Attribute control class 2

Source: Internet
Author: User
Code

  [Attributeusage (attributetargets. Property, inherited  =     False  )]
[Comvisible ( True )]
Public Class Propertykeyattribute: attribute
{
Public Propertykeyattribute ( Int Length)
{
This . Length = Length;
This . Nonebuild = True ;
}
Public Propertykeyattribute ()
{
This . Nonebuild = True ;
}

Public Int Length { Get ; Set ;}
Public System. Data. sqldbtype { Get ; Set ;}
Public String Name { Get ; Set ;}
Public Int Index { Get ; Set ;}
Public Bool Nonebuild { Get ; Set ;}



Public Static Int Getlength < T > ( String Name)
{
Propertykeyattribute ATTR = Getpropertykeyattribute < T > (Name );
If (ATTR ! = Null )
Return ATTR. length;
Return 20 ;
}
Public Static System. Data. sqldbtype getsqldbtype < T > ( String Name)
{
Propertykeyattribute ATTR = Getpropertykeyattribute < T > (Name );
If (ATTR ! = Null )
Return ATTR. sqldbtype;
Return System. Data. sqldbtype. varchar;
}
Public Static Bool Getnonebuild < T > ( String Name)
{
Propertykeyattribute ATTR = Getpropertykeyattribute < T > (Name );
If (ATTR ! = Null )
Return ATTR. nonebuild;
Return False ;
}

Public Static Int Getlength ( Object Model, String Name)
{
Propertykeyattribute ATTR = Getpropertykeyattribute (model, name );
If (ATTR ! = Null )
Return ATTR. length;
Return 20 ;
}
Public Static System. Data. sqldbtype getsqldbtype ( Object Model, String Name)
{
Propertykeyattribute ATTR = Getpropertykeyattribute (model, name );
If (ATTR ! = Null )
Return ATTR. sqldbtype;
Return System. Data. sqldbtype. varchar;
}
Public Static Bool Getnonebuild ( Object Model, String Name)
{
Propertykeyattribute ATTR = Getpropertykeyattribute (model, name );
If (ATTR ! = Null )
Return ATTR. nonebuild;
Return False ;
}

# Region Propertykeyattribute
Private Static Propertykeyattribute getpropertykeyattribute < T > ( String Name)
{
T Model = (T) activator. createinstance ( Typeof (T ));
Type type = Typeof (Propertykeyattribute );

Propertyinfo pi = Model. GetType (). getproperty (name );
Object [] Attributes = Pi. getcustomattributes ( False );
Foreach ( Object O In Attributes)
{
If (O Is Propertykeyattribute)
{
// Forcibly convert the obtained attribute to the personattribute
Propertykeyattribute Pa = (Propertykeyattribute) O;
Return Pa;
}
}
Return Null ;
}
Private Static Propertykeyattribute getpropertykeyattribute ( Object Model, String Name)
{
Try
{
Type type = Typeof (Propertykeyattribute );
Propertyinfo pi = Model. GetType (). getproperty (name );
Object [] Attributes = Pi. getcustomattributes ( False );
Foreach ( Object O In Attributes)
{
If (O Is Propertykeyattribute)
{
// Forcibly convert the obtained attribute to the personattribute
Propertykeyattribute Pa = (Propertykeyattribute) O;
Return Pa;
}
}
}
Catch
{

}
Return Null ;
}
# Endregion


}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.