Visual Studio .NET - Create Custom Attributes - Asked By aman on 28-Jul-11 02:44 AM

hi all and thanks for your previous help.......

public class clsCustomer
{

 public string strCustomerCode { get; set; }

 public string strCustomerName { get; set; }

}

i want to create a custom attribute on the above class so that the length of the fields does exceed greater than 10
soo how i can do this

please help
thanks and regards
Aman
Jitendra Faye replied to aman on 28-Jul-11 02:52 AM
Follow this code-


public class clsCustomer
{

  public string
_strCustomerCode

 public string strCustomerCode
 {
 
get
  { 
   return value;
  }
   
 
  set
   {
      //put validation here
    
     if(value.Length()<10)
        {
         _strCustomerCode=value;
        }  
      else
        {
         //your code (error)
        }
    }
 }

  public string _strCustomerName
  public
string strCustomerName
  { 
 
 get
 

   return value;
  }
   
 
  set
   {
      //put validation here
    
     if(value.Length()<10)
        {
         _strCustomerName=value;

        }  
      else
        {
         //your code (error)
        }
    }

}
Reena Jain replied to aman on 28-Jul-11 02:55 AM
Hi,

Well, If you want to check length of string you can check it before set in customer attribute like this
if(value.ToString().Length <=10)
{
CustomerCode= value;
}

Length is a property of string available in c#.net