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


C# TypeDefinition.IsComVisible方法代码示例

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


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

示例1: CheckType

		public RuleResult CheckType(TypeDefinition type)
		{
			// This rule only applies to public interfaces with methods and explicit ComVisible.
			if (!type.IsInterface || !type.IsPublic || !type.HasMethods || !type.HasCustomAttributes)
				return RuleResult.DoesNotApply;

			// If no explicit ComVisible is found, we still need to check.
			// If we're explicitly invisible, we can assume success.
			bool wasExplicit;
			if (!type.IsComVisible (out wasExplicit) && wasExplicit)
				return RuleResult.Success;

			methods.Clear ();
			foreach (MethodDefinition method in type.Methods) {
				if (methods.Contains (method.Name) && !(!method.IsComVisible(out wasExplicit) && wasExplicit))
					Runner.Report (method, Severity.Critical, Confidence.Total);
				else
					methods.Add (method.Name);
			}

			return Runner.CurrentRuleResult;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:22,代码来源:AvoidOverloadsInComVisibleInterfacesRule.cs

示例2: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// Only check for value types and types with fields.
			// But also for types with attributes, since FXCop only issues a warning if ComVisible is explicitly defined.
			if (!type.IsValueType || !type.HasCustomAttributes || !type.HasFields)
				return RuleResult.DoesNotApply;

			// Ensure the defining assembly is not null, then perform the same check for attributes on the assembly.
			AssemblyDefinition assembly = type.GetAssembly ();
			if (assembly != null && !assembly.HasCustomAttributes)
				return RuleResult.DoesNotApply;

			// Iterate through attributes on the type and assembly to ensure that ComVisible is false on the assembly,
			// and true on the type.
			bool exp;
			if (assembly != null) {
				if (assembly.IsComVisible (out exp) && exp)
					return RuleResult.Success;
			}
			if (!type.IsComVisible (out exp) && exp)
				return RuleResult.Success;

			// If we find any, low severity as the code works, but it's bad practice.
			foreach (FieldDefinition field in type.Fields)
				if (!field.IsPublic)
					Runner.Report (field, Severity.Low, Confidence.Total);

			return Runner.CurrentRuleResult;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:29,代码来源:AvoidNonPublicFieldsInComVisibleValueTypesRule.cs

示例3: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (!type.IsValueType || !type.HasCustomAttributes || 
				(!type.IsPublic && !type.IsNestedPublic) || type.HasGenericParameters)
				return RuleResult.DoesNotApply;

			AssemblyDefinition assembly = type.Module.Assembly;
			bool expl;
			// return if assembly is ComVisible 
			// or not visible but was not marked explicitly
			if (assembly.IsComVisible (out expl) || !expl)
				return RuleResult.DoesNotApply;

			// type should be explicitly marked as ComVisible, return otherwise
			if (!(type.IsComVisible (out expl) && expl))
				return RuleResult.DoesNotApply;
				
			if (type.IsAutoLayout) 
				Runner.Report (type, Severity.High, Confidence.High);

			return Runner.CurrentRuleResult;	
		}
开发者ID:madgnome,项目名称:mono-tools,代码行数:22,代码来源:AutoLayoutTypesShouldNotBeComVisibleRule.cs


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