Csla.Blazor.IPropertyInfo and [Required] attribute? #2855
Replies: 2 comments 7 replies
-
I took a peek into the That variable is stored here public virtual string FriendlyName
{
get
{
string result = Name;
if (!string.IsNullOrWhiteSpace(_friendlyName))
{
result = _friendlyName;
}
else if (_propertyInfo != null)
{
var display = _propertyInfo.GetCustomAttributes(typeof(DisplayAttribute), true).OfType<DisplayAttribute>().FirstOrDefault();
if (display != null)
{
// DataAnnotations attribute.
result = display.GetName();
}
else
{
// ComponentModel attribute.
var displayName = _propertyInfo.GetCustomAttributes(typeof(DisplayNameAttribute), true).OfType<DisplayNameAttribute>().FirstOrDefault();
if (displayName != null)
result = displayName.DisplayName;
}
}
return result;
}
} I'm thinking you could do the same in your own code and see how it works...you'd have to use reflection and inspect the property (via Name) that the PropertyInfo is pointing to for that attribute. |
Beta Was this translation helpful? Give feedback.
-
I don't understand the request? You can use the That doesn't stop the attribute from being used by the UIs that do honor the attributes - MVC, Razor Pages, and apparently now Blazor. |
Beta Was this translation helpful? Give feedback.
-
I'm experimenting with Ant Design Blazor. A nice feature of the
FormItem
component wrapper for edit controls is that it will look for a[Required]
attribute on the property and automatically prefix the label with a coloured asterisk, but this doesn't work when we use the pass-through property withCsla.Blazor.IPropertyInfo
. If we had something likebool HasAttribute<T>()
in the interface we could hook up theRequired
property like we do withdisabled="@(!Property.CanWrite)"
. Could this be possible?Beta Was this translation helpful? Give feedback.
All reactions