I want to get the interface properties if they exist from the container object of the property. I can get the container class, I think, but the interface of doing "as ISportParameters
" returns null, but the interface is certainly on the object.
public class CustomModelMetadataProvider : DataAnnotationsModelMetadataProvider
{
protected override ModelMetadata CreateMetadata(IEnumerable<Attribute> attributes, Type containerType, Func<object> modelAccessor, Type modelType, string propertyName)
{
var modelMetadata = base.CreateMetadata(attributes, containerType, modelAccessor, modelType, propertyName);
if (attributes.OfType<DisplayAttribute>().ToList().Count > 0)
{
// Want ISportParameters properties
var model = modelAccessor.Target.GetType().GetField("container").GetValue(modelAccessor.Target);
}
return modelMetadata;
}
}
Aucun commentaire:
Enregistrer un commentaire