Unseal StringSyntaxAttribute #9178
Replies: 2 comments 5 replies
-
If the IDE sees Maybe we need DerivedStringSyntaxAttributeAttribute: letting you apply |
Beta Was this translation helpful? Give feedback.
-
When working with attributes, the constructed attribute instance is very unimportant. It's a run-time only concept, which is impossible for many toolchains to utilize, including the compiler. That's why it's suggested against to have any logic in attributes, because they are totally inaccessible at compile time. To make your proposal possibly work, your attribute can only be defined as: public class FormatSyntaxAttribute : StringSyntaxAttribute
{
public FormatSyntaxAttribute(string syntax = StringSyntaxAttribute.CompositeFormat) : base(syntax) { }
} Then the compiler can see the default parameter provided by to the constructor. The constructor will never actually execute. Only the parameter provided to it can be utilized. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The StringSyntaxAttribute is very useful to add a syntax highlight to string parameters.
But because it requires to select the desired format it becomes very verbose.
For instance:
Allowing us to inherit from the StringSyntaxAttribute we could define our own attribute for the specific method or just to shorter the attribute name.
For instance:
I think that just unsealing the class would not cause a breaking change.
And the properties Syntax and Arguments used by the compiler would be inherited from the parent.
Simple type testing (is) can confirm the Attribute is of the correct type.
Please, consider.
Beta Was this translation helpful? Give feedback.
All reactions