You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the current implementation properties of variant options are translated to fields (see below example). I think it would be favorable to use .NET-Properties instead because:
Not using public fields is a best practice and properties are what should be used instead. Apparently some reasons for this (e.g. lazy evaluation or input checks) don't apply here: We have read-only data that's already there when the object is created. But I think the point still stays valid.
It's more likely that reflection-based code will require properties instead of fields. The concrete example that I see here would be Microsofts PropertyGrid, which is used for example in the Visualizer for Nitra.
The Performance overhead of using properties is neglectable.
Implementing this as the default behaviour would be a backward compatibility break if someone is using reflection on variants. Therefore I'm not quiet sure if it is reasonable to do that. A macro could be used instead to make the switch from fields to properties on a per variant basis.
namespace Test
{
publicvariant Test
{
| Foo { Integer : int; }
| Bar { Float : float; }
}
}
Removing the boilerplate code this roughly translates to
namespace Test
{
publicabstractclass Test
{
publicclass Foo : Test.Test
{
public Integer : int;
publicthis(integer : int)
{
this.Integer = integer;
}
}
publicclass Bar : Test.Test
{
public Float : float;
publicthis(float : float)
{
this.Float = float;
}
}
}
}
The text was updated successfully, but these errors were encountered:
ssrmm
changed the title
Suggestion: Variants should produce Properties instead of Attributes
Suggestion: Variants should produce Properties instead of Fields
Nov 29, 2016
In the current implementation properties of variant options are translated to fields (see below example). I think it would be favorable to use .NET-Properties instead because:
Implementing this as the default behaviour would be a backward compatibility break if someone is using reflection on variants. Therefore I'm not quiet sure if it is reasonable to do that. A macro could be used instead to make the switch from fields to properties on a per variant basis.
Removing the boilerplate code this roughly translates to
The text was updated successfully, but these errors were encountered: