I am trying to seperate DataAnnotations from our POCOs within a Silverlight project. One way to do this outside of SL is to use buddy classes e.g:
[MetadataTypeAttribute(typeof(MyPOCO.POCOMetaData))]
public partial class MyPOCO
{
internal sealed class POCOMetaData
{
[Required(ErrorMessage="Requires name.")]
public string Name { get; set; }
[Required(ErrorMessage = "Requires age.")]
public string Age { get; set; }
}
}
However as of Silverlight 4, the MetadataType attribute does not exist within System.ComponentModel.DataAnnotations namespace. Has anyone found an alternative way to seperate DataAnnotation attributes from POCOs? I am looking into this as I was planning on using T4 templates to generate our basic POCO classes.
This scenario looks somehow strange, why wouldn’t you want to decorate your POCOs themselves?
1 – If there is a matching server, consider using WCF RIA Services and declare your POCOs at the server side, the RIA engine will then generate for you all the proxies at the client side, including all its annotations, and many other goodies.
2 – If there is no matching server and you want to manipulate the data on client side, then I would go for WPF and have a wider range of desktop development capabilities.
3 – Unfortunately,
TypeDescriptoris also not implemented in Silverlight, so you can’t even add the attributes dynamically at runtime (in case you would want go that dirty-handed).So I’m affraid your chances are: