CSharp examples for System:Type
Contains Attribute
using System.Reflection; using System.Text; using System.Linq; using System.Collections.Generic; using System;//from w ww . ja v a 2 s . c o m public class Main{ /// <summary> /// ????????????Attribute /// </summary> /// <typeparam name="T"></typeparam> /// <param name="type"></param> /// <param name="FieldName"></param> /// <returns></returns> public static T ContainsAttribute<T>(Type type) where T : Attribute { object[] arr = type.GetCustomAttributes(typeof(T), true); if (arr.Length == 0) return null; return (T)arr[0]; } }