C#C
C#3y ago
SWEETPONY

✅ What should I do with the attributes?

public class Arguments                                  
{                                                       
    [Component(InputType.DepartmentsTreeSelect)]        
    [ComponentOptions()]                                
    [JsonProperty(PropertyName = "departments_ids")]    
    public HashSet<string>? DepartmentsIDs { get; set; }
}                                                       

can you give advice on how to do it better? I just can't think of...
here I have a field over which custom attributes are defined
with the Component attribute, there are no problems, we just pass a string that indicates which component to draw

but with ComponentOptions, everything is more complicated, because the options are a separate class and I would like the user to fill it in, but since we cannot pass it to the attribute class, then I do not know what to do

And this is possible class for ComponentOptions but I can't use it in attribute
public class ExtendedProperties
{
    /// <summary>
    /// UI component type
    /// </summary>
    [JsonProperty(PropertyName = "inputType")]
    public InputType InputType { get; set; }
    
    /// <summary>
    /// defines order
    /// </summary>
    [JsonProperty(PropertyName = "order")]
    public int Order { get; set; }
    
    /// <summary>
    /// defines multiple selection for UI component
    /// </summary>
    [JsonProperty(PropertyName = "multiple")]
    public bool Multiple { get; set; }
    
    /// <summary>
    /// defines options
    /// </summary>
    [JsonProperty(PropertyName = "options")]
    public Options? Options { get; set; }
    
    /// <summary>
    /// defines component properties
    /// </summary>
    [JsonProperty(PropertyName = "componentProps")]
    public ComponentProperties? ComponentProperties { get; set; }
}
Was this page helpful?