Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expand CustomAttributes for paramarray parameters #686

Open
govert opened this issue Mar 27, 2024 · 1 comment
Open

Expand CustomAttributes for paramarray parameters #686

govert opened this issue Mar 27, 2024 · 1 comment
Assignees

Comments

@govert
Copy link
Member

govert commented Mar 27, 2024

This from a user - when we expand a paramarray parameter, the newly created parameters don't get the attributes we had on the original paramarry parameter. They're asking us to copy the custom attributes to all the new parameters. That seems reasonable and safe to me.

I’ve been working with the Excel DNA libraries for our internal projects. I ran into a small issue with the handling of vararg in the code base. In ParamsRegistration.cs, a vararg is unpacked up to a maximum 125 length for the function. When this is done, the ExcelParameterRegistration attribute is created and added for each new argument. Unfortunately, any other attributes are not transferred, so we lose our flags for handling of arguments in special ways.

The original code was something like:

reg.ParameterRegistrations.Add(
new ExcelParameterRegistration( /* create ExcelArgumentAttribute */));

for (int i = 0; i < restCount; ++i) {
reg.ParameterRegistration.Add( /* create ExcelArgumentAttribute */));
}

This, of course, drops our attributes which creates the problem. What I did, instead, in the code was create the parameter registration and then transfer the attributes that had been on the argument:

var newRegistration = new ExcelParameterRegistration(/* create ExcelArgumentAttribute */));
newRegistration.CustomAttributes.AddRange(lastParam.CustomAttributes);
reg.ParameterRegistration.Add(newRegistration);

The ParamArrayAttribute was already stripped from the last parameter (and others could be if a full transfer isn’t desired), but this passes along the developer’s attributes for later use when coercing the parameters.

@Sergey-Vlasov Does this look OK to you?
I think 'sharing' the attributes objects between different parameters while using the MethodBuilder should be OK, but it's worth thinking or checking that nothing goes wrong.

@Sergey-Vlasov
Copy link
Contributor

Implemented in #698

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants