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


C# TypeDefinition.IsAttribute方法代码示例

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


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

示例1: Create

 /// <summary>
 /// Create a type builder for the given type.
 /// </summary>
 internal static IClassBuilder[] Create(ReachableContext context, AssemblyCompiler compiler, TypeDefinition typeDef)
 {
     if (typeDef.FullName == "<Module>")
         return new IClassBuilder[] { new SkipClassBuilder() };
     if (typeDef.IsDelegate())
         return new IClassBuilder[] {new DelegateClassBuilder(context, compiler, typeDef) };
     if (typeDef.IsAttribute()) 
         return new IClassBuilder[]  {new AttributeClassBuilder(context, compiler, typeDef) };
     if (typeDef.IsAnnotation())
         return new IClassBuilder[] {new AnnotationClassBuilder(context, compiler, typeDef) };
     if (typeDef.HasDexImportAttribute())
         return new IClassBuilder[] {new DexImportClassBuilder(context, compiler, typeDef) };
     if (typeDef.HasJavaImportAttribute())
         return new IClassBuilder[] {CreateJavaImportBuilder(context, compiler, typeDef)};
     if (typeDef.IsEnum)
     {
         if (typeDef.UsedInNullableT)
         {
             var nullableBaseClassBuilder = new NullableEnumBaseClassBuilder(context, compiler, typeDef);
             IClassBuilder builder = new EnumClassBuilder(context, compiler, typeDef, nullableBaseClassBuilder);
             return new[] { builder, nullableBaseClassBuilder };
         }
         return new IClassBuilder[] { new EnumClassBuilder(context, compiler, typeDef, null) };
     }
     else
     {
         IClassBuilder builder = new StandardClassBuilder(context, compiler, typeDef);
         if (typeDef.UsedInNullableT)
             return new[] { builder, new NullableBaseClassBuilder(context, compiler, typeDef) };
         return new[] { builder };
     }
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:35,代码来源:ClassBuilder.cs

示例2: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule applies only to attributes
			if (!type.IsAttribute ())
				return RuleResult.DoesNotApply;

			if (type.HasAttribute ("System", "AttributeUsageAttribute")) // it's ok
				return RuleResult.Success;

			Runner.Report (type, Severity.High, Confidence.Total);
			return RuleResult.Failure;
		}
开发者ID:FreeBSD-DotNet,项目名称:mono-tools,代码行数:12,代码来源:MissingAttributeUsageOnCustomAttributeRule.cs

示例3: CheckType

        public RuleResult CheckType(TypeDefinition type)
        {
            // rule applies only to attributes
            if (!type.IsAttribute ())
                return RuleResult.DoesNotApply;

            if (type.IsAbstract) // it's ok
                return RuleResult.Success;

            if (type.IsSealed) // it's ok
                return RuleResult.Success;

            Runner.Report (type, Severity.Medium, Confidence.High);
            return RuleResult.Failure;
        }
开发者ID:alfredodev,项目名称:mono-tools,代码行数:15,代码来源:AvoidUnsealedConcreteAttributesRule.cs

示例4: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule applies only to attributes
			if (!type.IsAttribute ())
				return RuleResult.DoesNotApply;

			// look through getters
			allProperties.Clear ();
			foreach (PropertyDefinition property in type.Properties) {
				if (property.GetMethod != null) {
					allProperties.Add (property.Name);
				}
			}

			// look through parameters
			foreach (MethodDefinition constructor in type.GetConstructors ()) {
				foreach (ParameterDefinition param in constructor.Parameters) {
					 // pascal case it
					string correspondingPropertyName = Char.ToUpper (param.Name [0]).ToString () + param.Name.Substring (1);
					if (!allProperties.Contains (correspondingPropertyName)) {
						string s = String.Format ("Add '{0}' property to the attribute class.", correspondingPropertyName);
						Runner.Report (param, Severity.Medium, Confidence.High, s);
						allProperties.Add (correspondingPropertyName); // to avoid double catching same property (e.g. from different constructors)
					}
				}
			}
			return Runner.CurrentRuleResult;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:28,代码来源:AttributeArgumentsShouldHaveAccessorsRule.cs

示例5: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule applies only to attributes
			if (!type.IsAttribute ())
				return RuleResult.DoesNotApply;

			// look through getters
			allProperties.Clear ();

			TypeDefinition t = type;
			// Walk up the inheritance tree so that inherited properties are counted
			do
			{
				foreach (PropertyDefinition property in t.Properties) {
					if (property.GetMethod != null) {
						allProperties.Add (property.Name);
					}
				}
				t = t.BaseType != null ? t.BaseType.Resolve () : null;
			} while (t != null  && !t.IsNamed ("System", "Attribute"));

			// look through parameters
			foreach (MethodDefinition constructor in type.Methods) {
				if (!constructor.IsConstructor)
					continue;

				foreach (ParameterDefinition param in constructor.Parameters) {
					 // pascal case it
					string correspondingPropertyName = Char.ToUpper (param.Name [0], CultureInfo.InvariantCulture).ToString (CultureInfo.InvariantCulture) +
						param.Name.Substring (1);
					if (!allProperties.Contains (correspondingPropertyName)) {
						string s = String.Format (CultureInfo.InvariantCulture, 
							"Add '{0}' property to the attribute class.", correspondingPropertyName);
						Runner.Report (param, Severity.Medium, Confidence.High, s);
						allProperties.Add (correspondingPropertyName); // to avoid double catching same property (e.g. from different constructors)
					}
				}
			}
			return Runner.CurrentRuleResult;
		}
开发者ID:FreeBSD-DotNet,项目名称:mono-tools,代码行数:40,代码来源:AttributeArgumentsShouldHaveAccessorsRule.cs


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