0

I am trying to pass some named arguments to my Attribute constructor but whatever I do they just get ignored.

protected class FormulaOperator : AbstractMethodAttribute
{

    public bool AutoConvertSingleParamToArray = true;
    public bool UseStrictParamOrder = true;
    public bool FlattenResults = false;

}
protected class ParameterListOperator : FormulaOperator
{

}
[ParameterListOperator(",", FlattenResults = true)]
protected object[] CollectParams(object[] collection)
{
    return collection;
}

As you see FlattenResults a simple public bool, but the default value is always preserved even when I specifically pass a different value to constructor. I've tried to convert FlattenResults to property and removing the default value entirely.No luck! It should be true but is always false. Am I missing something?

SUNIL DHAPPADHULE
  • 2,755
  • 17
  • 32
  • 2
    Can you post a [mcve]? Meaning something that would produce an incorrect result, so you would need to post the attribute, code that applies it to something, as well as the reflection code that retrieves it? A simple test I made doesn't reproduce the problem so I will assume there is a bug elsewhere as well, or that the code in the question doesn't fully represent the code with the problem. Creating an [mcve] will show us, and possibly you, what the real problem is. – Lasse V. Karlsen May 03 '19 at 09:45
  • 3
    Cannot reproduce. `attr.FlattenResults` [shows](https://stackoverflow.com/a/2493191/11683) `true`. – GSerg May 03 '19 at 09:47
  • Always returns true for me too. Can you post a complete program demonstrating the incorrect behaviour? – Sean Reid May 03 '19 at 10:09
  • To answer your question, yes, you are missing something, but since the missing part is in code you've not posted, so are we. We still need to see a full working example of your problem, otherwise all we can say is that you're doing something wrong because it works for us. – Lasse V. Karlsen May 03 '19 at 11:44
  • I think the word `constructor` is creating a little bit of confusion and uncertainty. `FlattenResults` is public property which is set when the attribute is used. There is no constructor with any boolean argument, so it's not getting passed to a constructor. Also, we're missing `AbstractMethodAttribute`, although it doesn't look likely to change anything. – Scott Hannen May 03 '19 at 14:10
  • 1
    ...and a `protected` class can only be nested within another class, but we can't see the class it's nested within. These might not be relevant, but it creates some uncertainty. The behavior you describe could be related to something we can't see. – Scott Hannen May 03 '19 at 14:16

0 Answers0