I wish to set an attribute on a public property in .NET, however I do not have access to the explicit property itself, as this has been code generated in another file.
Since the generated class is a partial class, the following should work:
For example:
// Decorate the properties with attributes as required
public interface IMyInterface
{
[ValidateNonEmpty("Name is required")]
string Name { get; set; }
}
// This is the partial class I created, that implements the interface
public partial class MyGeneratedClass : IMyInterface
{
}
// This is the auto-generated class
public partial class MyGeneratedClass
{
public virtual string Name { get; set; }
}
I got this idea from geekswithblogs.