VKamakodu

C#: How to make a property Required and not null ?

Discussion created by VKamakodu on May 12, 2010
Latest reply on Jun 11, 2010 by VKamakodu

I would like to make a C# Property required and not nullable through an attribute. Is there a way to do this?  I want to force the consumer of my class to get a compiler error if a particular attribute is not set. I can handle it through code by checking the value but how about doing through attributes?

 

For example: I would like to see something like this.

[Required]
public string FirstName { get; set; }

Outcomes