model configuration classes - Envivo-Software/Envivo.Fresnel GitHub Wiki
Model Configuration Classes
As an alternative to decorating classes and members with Atttributes, you may configure your model using Model Configuration Classes. If you prefer to keep your model classes devoid of clutter (or you are using non-Fresnel model classes), consider this technique.
Create a single class that inherits from Envivo.Fresnel.ModelAttributes.Config.ModelConfigBase. Then use the ConfigureClass<T> method to apply your custom configurations:
using Envivo.Fresnel.ModelAttributes.Config;
public class ModelConfig : ModelConfigBase //👈
{
public override void Configure()
{
ConfigureClass<ObjectWithCustomNames>(new DisplayNameAttribute("Custom Names"))
.Property(o => o.A_Boolean, new DisplayNameAttribute("Yes or No"))
.Property(o => o.A_String, new DisplayNameAttribute("Text"))
.Property(o => o.An_Int, new DisplayNameAttribute("Whole number"))
.Property(o => o.A_Double, new DisplayNameAttribute("Fractional number"))
.Property(o => o.A_DateTime, new DisplayNameAttribute("Date/Time"))
.Method(o => o.A_Method, new DisplayNameAttribute("Open dialog"))
.MethodParameter(o => o.A_Method, "property1", new DisplayNameAttribute("First property"))
.MethodParameter(o => o.A_Method, "property2", new DisplayNameAttribute("Second property"))
;
The ConfigureClass<T> method lets you configure as many properties and methods as necessary.
To apply multiple attribute configurations to a member, simply add them to the list:
ConfigureClass<ObjectWithCustomNames>(new DisplayNameAttribute("Custom Names"))
.Property(o => o.A_Boolean, new DisplayNameAttribute("Yes or No"),
new DefaultValueAttribute(true),
new RequiredAttribute())
...
;
A note about Parameter configurations
At this time, parameter names must be specified as strings.
This may cause issues if you perform a symbolic rename within the code, and then forget to change your configuration class. In these cases it may be safer to use Model Configuration Attributes.
💡 Note:
If a class or member is configured with both a attribute decoration and a configuration class, the decorated Attribute takes precedence.