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


C# TypeDefinition.IsTypeComVisible方法代码示例

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


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

示例1: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (!type.IsTypeComVisible ())
				return RuleResult.DoesNotApply;

			ClassInterfaceType? attributeValue = GetClassInterfaceAttributeValue (type);

			bool fromAssembly = false;

			// attribute not found on class, try assembly instead
			if (attributeValue == null) {
				attributeValue = GetClassInterfaceAttributeValue (type.Module.Assembly);
				fromAssembly = true;
			}

			// not found on assembly as well, set default value
			if (attributeValue == null)
				attributeValue = ClassInterfaceType.AutoDispatch;

			if (attributeValue == ClassInterfaceType.AutoDual) {
				if (fromAssembly)
					Runner.Report (type, Severity.High, Confidence.High, "Attribute was set on assembly level");
				else
					Runner.Report (type, Severity.High, Confidence.High);
				return RuleResult.Failure;
			} else
				return RuleResult.Success;
		}
开发者ID:boothead,项目名称:mono-tools,代码行数:28,代码来源:DoNotUseAutoDualClassInterfaceTypeRule.cs

示例2: CheckType

        public RuleResult CheckType(TypeDefinition type)
        {
            // Check only for reference types with attributes.
            if (!type.IsClass || type.IsValueType || !type.HasCustomAttributes)
                return RuleResult.DoesNotApply;

            // Ensure class is explicitly ComVisible.
            if (!type.IsTypeComVisible ())
                return RuleResult.DoesNotApply;

            // Report success if a default public constructor is found or no parameterized constructor is found.
            bool hasParameterizedCtor = false;
            bool hasDefaultCtor = false;
            foreach (var ctor in type.Methods) {
                if (!ctor.IsConstructor)
                    continue;

                if (ctor.IsPublic && ctor.HasParameters) {
                    hasParameterizedCtor = true;
                    continue;
                }
                if (ctor.IsPublic)
                    hasDefaultCtor = true;
            }
            if (!hasParameterizedCtor || hasDefaultCtor)
                return RuleResult.Success;

            Runner.Report (type, Severity.Medium, Confidence.Total);

            return Runner.CurrentRuleResult;
        }
开发者ID:FreeBSD-DotNet,项目名称:mono-tools,代码行数:31,代码来源:ComVisibleTypesShouldBeCreatableRule.cs

示例3: 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;

			if (!type.IsTypeComVisible ())
				return RuleResult.DoesNotApply;

			// 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:FreeBSD-DotNet,项目名称:mono-tools,代码行数:17,代码来源:AvoidNonPublicFieldsInComVisibleValueTypesRule.cs

示例4: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (type.BaseType == null)
				return RuleResult.DoesNotApply;

			// Checks whether specific type is COM visible or not
			// considering nested types, assemblies attributes and default values
			if (!type.IsTypeComVisible ())
				return RuleResult.DoesNotApply;

			TypeDefinition baseType = type.BaseType.Resolve ();
			if ((baseType != null) && !baseType.IsTypeComVisible ()) {
				Runner.Report (type, Severity.High, Confidence.Total,
					String.Format ("Type is derived from invisible from COM type {0}",
						baseType.FullName));
			}
			return Runner.CurrentRuleResult;
		}
开发者ID:boothead,项目名称:mono-tools,代码行数:18,代码来源:ComVisibleShouldInheritFromComVisibleRule.cs

示例5: CheckType

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

            if (!type.IsTypeComVisible ())
                return RuleResult.DoesNotApply;

            if (type.IsAutoLayout)
                Runner.Report (type, Severity.High, Confidence.High);

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

示例6: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (type.HasGenericParameters || !type.IsVisible () || !type.IsTypeComVisible ())
				return RuleResult.DoesNotApply;

			bool foundRegister = false; // type level variables
			bool foundUnregister = false;

			foreach (MethodDefinition method in type.Methods) {
				if (!method.HasCustomAttributes)
					continue;

				bool foundRegisterUnregisterMethod = false; // method level variable
				foreach (CustomAttribute attribute in method.CustomAttributes) {
					var name = attribute.AttributeType.FullName;
					if (!foundRegister && name == comRegister) {
						foundRegister = true;
						foundRegisterUnregisterMethod = true;
					}
					if (!foundUnregister && name == comUnregister) {
						foundUnregister = true;
						foundRegisterUnregisterMethod = true;
					}
				}
				if (foundRegisterUnregisterMethod && method.IsVisible ()) {
					Runner.Report (method, Severity.High, Confidence.High,
						"Method is marked with the ComRegisterFunctionAttribute or with the ComUnregisterFunctionAttribute and is externally visible");
				}
			}

			if (foundRegister ^ foundUnregister) { // only one of them is true
				if (foundRegister)
					Runner.Report (type, Severity.High, Confidence.High,
						"Type contains has a method with ComRegisterFunctionAttribute but it doesn't contain a method with ComUnregisterFunctionAttribute");
				if (foundUnregister)
					Runner.Report (type, Severity.High, Confidence.High,
						"Type contains has a method with ComUnregisterFunctionAttribute but it doesn't contain a method with ComRegisterFunctionAttribute");
			}

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

示例7: 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)
                return RuleResult.DoesNotApply;

            if (!type.IsTypeComVisible ())
                return RuleResult.DoesNotApply;

            methods.Clear ();
            foreach (MethodDefinition method in type.Methods) {
                var name = method.Name;
                if (methods.Contains (name) && (method.IsComVisible () ?? true))
                    Runner.Report (method, Severity.Critical, Confidence.Total);
                else
                    methods.Add (name);
            }

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


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