I seem to be missing something on using MetadataPropertyType when i need to add an ErrorMessage Property and its value to an exported Range Attribute.
nativeTypes.ExportAttribute<System.ComponentModel.DataAnnotations.RangeAttribute>(x =>
{
var metadata = nativeTypes.GetGenerator().ToMetadataAttribute(x);
metadata.Name = x.GetType().FullName;
if (metadata.Args == null)
metadata.Args = new List<MetadataPropertyType>();
var attr = (System.ComponentModel.DataAnnotations.RangeAttribute)x;
if (!string.IsNullOrEmpty(attr.ErrorMessage))
{
metadata.Args.Add(new MetadataPropertyType { Name = nameof(System.ComponentModel.DataAnnotations.RangeAttribute.ErrorMessage), Value = attr.ErrorMessage, TypeNamespace = "System", Type = nameof(String)});
}
return metadata;
});
The ErrorMessage property is not emitted.
It seems that if there are no ConstructorArgs the Args emit properly, as in the case of DisplayAttribute.