当前位置: 首页>>代码示例>>C#>>正文


C# Type.GetCustomAttributes方法代码示例

本文整理汇总了C#中Type.GetCustomAttributes方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetCustomAttributes方法的具体用法?C# Type.GetCustomAttributes怎么用?C# Type.GetCustomAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Type的用法示例。


在下文中一共展示了Type.GetCustomAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: RegisterExtensionType

		static void RegisterExtensionType (Type type)
		{
			ExtensionInfo ext = new ExtensionInfo();
			ext.Type = type;
			
			object[] ats = type.GetCustomAttributes (typeof(XmlFormatExtensionPrefixAttribute), true);
			
			foreach (XmlFormatExtensionPrefixAttribute at in ats)
				ext.NamespaceDeclarations.Add (new XmlQualifiedName (at.Prefix, at.Namespace));
			
			ats = type.GetCustomAttributes (typeof(XmlFormatExtensionAttribute), true);
			if (ats.Length > 0)
			{
				XmlFormatExtensionAttribute at = (XmlFormatExtensionAttribute)ats[0];
				ext.ElementName = at.ElementName;
				if (at.Namespace != null) ext.Namespace = at.Namespace;
			}

			XmlRootAttribute root = new XmlRootAttribute ();
			root.ElementName = ext.ElementName;
			if (ext.Namespace != null) root.Namespace = ext.Namespace;

			XmlReflectionImporter ri = new XmlReflectionImporter ();
			XmlTypeMapping map = ri.ImportTypeMapping (type, root);
			
			if (ext.ElementName == null) throw new InvalidOperationException ("XmlFormatExtensionAttribute must be applied to type " + type);
			extensionsByName.Add (ext.Namespace + " " + ext.ElementName, ext);
			extensionsByType.Add (type, ext);
			
			maps.Add (map);
			extensions.Add (ext);
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:32,代码来源:ExtensionManager.cs

示例2: Initialize

        protected void Initialize(Type controllerType)
        {
            ControllerType = controllerType;

            // If controller type has a RouteAttribute, then standard routes can't reach it.             
            _hasRouteAttributeOnController = controllerType.GetCustomAttributes(typeof(IDirectRouteFactory), inherit: false).Any()
                || controllerType.GetCustomAttributes(typeof(IRouteInfoProvider), inherit: false).Any();

            PopulateLookupTables();
        }
开发者ID:tlycken,项目名称:aspnetwebstack,代码行数:10,代码来源:ActionMethodSelectorBase.cs

示例3: AddModuleDocumentation

    /// <summary>
    /// Adds the documentation for the current 
    /// module type to the referenced stringbuild.
    /// </summary>
    /// <returns></returns>
    public static bool AddModuleDocumentation(ref StringBuilder working, Type moduleType)
    {
        if(moduleType == null)
            return false;

        object[] attrs = moduleType
            .GetCustomAttributes(typeof(KPartModuleConfigurationDocumentationAttribute), true);

        if(attrs.Length == 0)
            return false;

        KPartModuleConfigurationDocumentationAttribute attribute =
                attrs[0] as KPartModuleConfigurationDocumentationAttribute;

        if(attribute == null)
            return false;

        attrs = moduleType.GetCustomAttributes(typeof(KRequiresModuleAttribute), true);

        string moduleStringName = string.Concat(moduleType.UnderlyingSystemType.Name, ".cs");

        working.Append("//");
        working.Append('=', moduleStringName.Length);
        working.AppendLine();

        working.Append("//");
        working.AppendLine(moduleStringName);

        working.Append("//");
        working.Append('=', moduleStringName.Length);

        working.AppendLine(attribute.ModuleDocumentation);
        working.AppendLine("//");

        working.AppendLine("//Requires Modules:");
        if(attrs.Length > 0)
        {
            foreach(KRequiresModuleAttribute current in attrs)
            {
                working.Append("// > ");
                working.AppendLine(
                    FormatAssemblyString(current.RequiredType));
            }
        }
        else
        {
            working.Append("//=> None");
        }

        working.Append("//");
        working.AppendLine();

        return true;
    }
开发者ID:KineMorto,项目名称:KineTechAnimationLibrary,代码行数:59,代码来源:KConfigDocumentationGenerator.cs

示例4: GetAttributeValue

 private static bool GetAttributeValue(Type objType, Type attrType, string property, bool inherit, ref object outVal)
 {
     object[] attrs = objType.GetCustomAttributes(attrType, inherit);
     if (attrs.Length > 0)
         return GetPropertyValue(attrs[0], property, ref outVal);
     return false;
 }
开发者ID:BclEx,项目名称:BclEx-Extend,代码行数:7,代码来源:XmlSerializationHelper.cs

示例5: EnumTypeConfiguration

        /// <summary>
        /// Initializes a new instance of the <see cref="EnumTypeConfiguration"/> class.
        /// </summary>
        public EnumTypeConfiguration(ODataModelBuilder builder, Type clrType)
        {
            if (builder == null)
            {
                throw Error.ArgumentNull("builder");
            }
            if (clrType == null)
            {
                throw Error.ArgumentNull("clrType");
            }

            if (!clrType.IsEnum)
            {
                throw Error.Argument("clrType", SRResources.TypeCannotBeEnum, clrType.FullName);
            }

            ClrType = clrType;
            IsFlags = clrType.GetCustomAttributes(typeof(FlagsAttribute), false).Any();
            UnderlyingType = Enum.GetUnderlyingType(clrType);
            ModelBuilder = builder;
            _name = clrType.EdmName();
            _namespace = clrType.Namespace ?? DefaultNamespace;
            ExplicitMembers = new Dictionary<Enum, EnumMemberConfiguration>();
            RemovedMembers = new List<Enum>();
        }
开发者ID:ZhaoYngTest01,项目名称:WebApi,代码行数:28,代码来源:EnumTypeConfiguration.cs

示例6: TryFindConfigurationType

        public virtual Type TryFindConfigurationType(Type contextType, IEnumerable<Type> typesToSearch = null)
        {
            DebugCheck.NotNull(contextType);

            var typeFromAttribute = contextType.GetCustomAttributes(inherit: true)
                                               .OfType<DbConfigurationTypeAttribute>()
                                               .Select(a => a.ConfigurationType)
                                               .FirstOrDefault();

            if (typeFromAttribute != null)
            {
                if (!typeof(DbConfiguration).IsAssignableFrom(typeFromAttribute))
                {
                    throw new InvalidOperationException(
                        Strings.CreateInstance_BadDbConfigurationType(typeFromAttribute.ToString(), typeof(DbConfiguration).ToString()));
                }
                return typeFromAttribute;
            }

            var configurations = (typesToSearch ?? contextType.Assembly.GetAccessibleTypes())
                .Where(
                    t => typeof(DbConfiguration).IsAssignableFrom(t)
                         && t != typeof(DbConfiguration)
                         && !t.IsAbstract
                         && !t.IsGenericType)
                .ToList();

            if (configurations.Count > 1)
            {
                throw new InvalidOperationException(
                    Strings.MultipleConfigsInAssembly(configurations.First().Assembly, typeof(DbConfiguration).Name));
            }

            return configurations.FirstOrDefault();
        }
开发者ID:jwanagel,项目名称:jjwtest,代码行数:35,代码来源:DbConfigurationFinder.cs

示例7: GetInitializer

	public override object GetInitializer(Type webServiceType) 
	{
		if (webServiceType.GetCustomAttributes (typeof (EncryptAttribute), false).Length > 0)
			return CreateAlgorithm ();
		else
			return null;
	}
开发者ID:louislatreille,项目名称:xsp,代码行数:7,代码来源:EncryptExtension.cs

示例8: GetInitializer

	public override object GetInitializer(Type webServiceType) 
	{
		if (webServiceType.GetCustomAttributes (typeof (DumpAttribute), false).Length > 0)
			return true;
		else
			return false;
	}
开发者ID:louislatreille,项目名称:xsp,代码行数:7,代码来源:DumpExtension.cs

示例9: GetFor

 public static UTActionInfoAttribute GetFor(Type type)
 {
     var info = type.GetCustomAttributes(typeof(UTActionInfoAttribute), false);
     if (info.Length == 0) {
         return new UTActionInfoAttribute();
     }
     return info[0] as UTActionInfoAttribute;
 }
开发者ID:realshyfox,项目名称:PlayMakerCustomActions_U3,代码行数:8,代码来源:UTActionInfoAttribute.cs

示例10: GetFor

 /// <summary>
 /// Gets the UTDefaultAction attached to the given type.
 /// </summary>
 /// <returns>
 /// The UTDefaultAction or null, if there is no UTDefaultAction on the type.
 /// </returns>
 public static UTDefaultAction GetFor(Type type)
 {
     var annotations = type.GetCustomAttributes(typeof(UTDefaultAction), false);
     if (annotations.Length == 1) {
         return (UTDefaultAction) annotations[0];
     }
     return null;
 }
开发者ID:realshyfox,项目名称:PlayMakerCustomActions_U3,代码行数:14,代码来源:UTDefaultAction.cs

示例11: GetFor

 public static UTPropertyRendererAttribute GetFor(Type type)
 {
     var attrs = type.GetCustomAttributes (typeof(UTPropertyRendererAttribute), false);
     if (attrs.Length == 1) {
         return (UTPropertyRendererAttribute)attrs [0];
     }
     return null;
 }
开发者ID:realshyfox,项目名称:PlayMakerCustomActions_U3,代码行数:8,代码来源:UTPropertyRendererAttribute.cs

示例12: GetDebugViewType

 private static Type GetDebugViewType(Type type)
 {
     var att =
         (DebuggerTypeProxyAttribute)
             type.GetCustomAttributes().Single(at => at.TypeId.Equals(typeof(DebuggerTypeProxyAttribute)));
     var proxyName = att.ProxyTypeName;
     proxyName = proxyName.Substring(0, proxyName.IndexOf(','));
     return type.GetTypeInfo().Assembly.GetType(proxyName);
 }
开发者ID:AtsushiKan,项目名称:corefx,代码行数:9,代码来源:BindingRestrictionsProxyTests.cs

示例13: GetFor

 /// <summary>
 /// Gets the UTInspectorGroups attribute attached to the given type. If no such attribute is attached to the given
 /// type, a default UTInspectorGroups object will be returned.
 /// </summary>
 /// <returns>
 /// The UTInspectorGroups attribute.
 /// </returns>
 /// <param name='type'>
 /// The type to read the attribute from.
 /// </param>
 public static UTInspectorGroups GetFor(Type type)
 {
     var groups = type.GetCustomAttributes(typeof(UTInspectorGroups), true);
     if (groups.Length > 0) {
         var hint = (UTInspectorGroups) groups[0];
         return hint;
     }
     return Default;
 }
开发者ID:realshyfox,项目名称:PlayMakerCustomActions_U3,代码行数:19,代码来源:UTInspectorGroups.cs

示例14: IsTypeThemeable

		public static bool IsTypeThemeable (Type type)
		{
			Object [] attributes = type.GetCustomAttributes (typeof (ThemeableAttribute), false);
			if (attributes.Length != 0) {
				foreach (Attribute attrib in attributes)
					if (attrib is ThemeableAttribute)
						return true;
			}
			return false;
		}
开发者ID:nlhepler,项目名称:mono,代码行数:10,代码来源:ThemeableAttribute.cs

示例15: DataContractImplementor

        internal DataContractImplementor(EntityType ospaceEntityType)
        {
            _baseClrType = ospaceEntityType.ClrType;

            var attributes = (DataContractAttribute[])_baseClrType.GetCustomAttributes(typeof(DataContractAttribute), false);
            if (attributes.Length > 0)
            {
                _dataContract = attributes[0];
            }
        }
开发者ID:christiandpena,项目名称:entityframework,代码行数:10,代码来源:DataContractImplementor.cs


注:本文中的Type.GetCustomAttributes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。