C # uses reflection to determine whether an object contains an implementation of an attribute

Source: Internet
Author: User

This example shows that C # uses reflection to determine whether an object contains an attribute, and for C # program designers, it has a certain learning value.

The specific implementation code is as follows:

<SUMMARY>///uses reflection to determine whether an object contains an attribute//</summary>///<param name= "instance" >object</param>// /<param name= "PropertyName" > Properties to be judged </param>///<returns> contains </returns>public static bool Containproperty (This object instance, string propertyname) {  if (instance! = null &&!string. IsNullOrEmpty (PropertyName))  {PropertyInfo _findedpropertyinfo = instance. GetType (). GetProperty (PropertyName); Return (_findedpropertyinfo! = null);  }  return false;}

Here's how to use the code:

bool cc = _person. Containproperty ("CC"); bool AA = _person. Containproperty ("Age");

I hope that the examples described in this article can help you!

In addition to the Declaration, Running GuestArticles are original, reproduced please link to the form of the address of this article
C # uses reflection to determine whether an object contains an implementation of an attribute

This address: http://www.paobuke.com/develop/c-develop/pbk23647.html






Related Content C # WinForm Implementation of pop-up window results in the lower right corner C # calculates the similarity of 2 strings C # implements the method of converting HTML to plain text C # Method of implementing TCP connection information statistics
C # manual Double buffering Technology Usage Example Analysis C # BASE64 encryption and decryption Class C # processing JSON string Instance parsing C # setting form maximized and does not obscure the taskbar method

C # uses reflection to determine whether an object contains an implementation of an attribute

Related Article

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.