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


C# TypeDefinition.IsVisible方法代码示例

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


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

示例1: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule doesn't apply on enums, interfaces, delegates or to compiler/tools-generated code
			// e.g. CSC compiles anonymous methods as an inner type that expose public fields
			if (type.IsEnum || type.IsInterface || !type.HasFields || type.IsDelegate () || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;
			
			// rule doesn't apply to type non (externally) visible
			if (!type.IsVisible ())
				return RuleResult.DoesNotApply;

			foreach (FieldDefinition fd in type.Fields) {
				if (!fd.IsVisible () || fd.IsSpecialName || fd.HasConstant || fd.IsInitOnly)
					continue;

				string name = fd.Name;
				if (fd.FieldType.IsArray) {
					string s = String.Format (CultureInfo.InvariantCulture, 
						"Consider changing the field '{0}' to a private or internal field and add a 'Set{1}{2}' method.",
						name, Char.ToUpper (name [0], CultureInfo.InvariantCulture).ToString (CultureInfo.InvariantCulture), name.Substring (1));
					Runner.Report (fd, Severity.Medium, Confidence.Total, s);
				} else {
					string s = String.Format (CultureInfo.InvariantCulture, 
						"Field '{0}' should be private or internal and its value accessed through a property.", name);
					Runner.Report (fd, Severity.Medium, Confidence.Total, s);
				}
			}
			return Runner.CurrentRuleResult;
		}
开发者ID:FreeBSD-DotNet,项目名称:mono-tools,代码行数:29,代码来源:AvoidPublicInstanceFieldsRule.cs

示例2: CheckType

        public RuleResult CheckType(TypeDefinition type)
        {
            // rule apply only to types protected by either a Demand or a LinkDemand (i.e. SecurityDeclaration)
            // that have fields and are visible outside the assembly
            if (!type.HasSecurityDeclarations || !type.HasFields || !type.IsVisible ())
                return RuleResult.DoesNotApply;

            bool demand = false;
            foreach (SecurityDeclaration declsec in type.SecurityDeclarations) {
                switch (declsec.Action) {
                case Mono.Cecil.SecurityAction.Demand:
                case Mono.Cecil.SecurityAction.LinkDemand:
                    demand = true;
                    break;
                }
            }

            if (!demand)
                return RuleResult.DoesNotApply;

            // *** ok, the rule applies! ***

            // type shouldn't have any visible fields
            foreach (FieldDefinition field in type.Fields) {
                if (field.IsVisible ()) {
                    Runner.Report (field, Severity.Critical, Confidence.Total);
                }
            }
            return Runner.CurrentRuleResult;
        }
开发者ID:alfredodev,项目名称:mono-tools,代码行数:30,代码来源:DoNotExposeFieldsInSecuredTypeRule.cs

示例3: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// if the type is not visible or has no fields then the rule does not apply
			if (!type.HasFields || type.IsEnum || !type.IsVisible ())
				return RuleResult.DoesNotApply;

			foreach (FieldDefinition field in type.Fields) {
				// look for 'const' fields
				if (!field.IsLiteral)
					continue;

				// that are visible outside the current assembly
				if (!field.IsVisible ())
					continue;

				// we let null constant for all reference types (since they can't be changed to anything else)
				// except for strings (which can be modified later)
				string type_name = field.FieldType.FullName;
				if (!field.FieldType.IsValueType && (type_name != "System.String"))
					continue;

				string msg = string.Format ("'{0}' of type {1}.", field.Name, type_name);
				Runner.Report (field, Severity.High, Confidence.High, msg);

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

示例4: CheckType

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

			if (type.GenericParameters.Count > 2)
				Runner.Report (type, Severity.Medium, Confidence.Total);

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

示例5: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule doesn't apply to nested types, since the declaring type will already be reported
			if (type.IsNested)
				return RuleResult.DoesNotApply;
			
			// rule applies to only to types visible outside the assembly
			if (!type.IsVisible ())
				return RuleResult.DoesNotApply;

			// rule applies!

			// check if the type resides inside a namespace
			if (!String.IsNullOrEmpty (type.Namespace))
				return RuleResult.Success;

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

示例6: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (type.IsAbstract || type.IsSealed || type.IsVisible () || type.IsGeneratedCode ())
				return RuleResult.Success;

			ModuleDefinition module = type.Module;
			string type_name = type.FullName;
			foreach (TypeDefinition type_definition in module.GetAllTypes ()) {
				// skip ourself
				if (type_definition.FullName == type_name)
					continue;
				if (type_definition.Inherits (type_name))
					return RuleResult.Success;
			}

			Confidence c = module.Assembly.HasAttribute ("System.Runtime.CompilerServices.InternalsVisibleToAttribute") ?
				Confidence.High : Confidence.Total;
			Runner.Report (type, Severity.Medium, c);
			return RuleResult.Failure;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:20,代码来源:AvoidUnsealedUninheritedInternalClassesRule.cs

示例7: CheckType

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

			if (type.HasFields) {
				foreach (var field in type.Fields) {
					if (field.IsStatic && field.IsVisible ())
						Runner.Report (field, Severity.Medium, Confidence.Total);
				}
			}
			if (type.HasMethods) {
				foreach (var method in type.Methods) {
					if (method.IsStatic && method.IsVisible ())
						Runner.Report (method, Severity.Medium, Confidence.Total);
				}
			}

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

示例8: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule applies only to classes that defines events
			if (type.IsEnum || type.IsInterface || type.IsValueType || !type.HasEvents)
				return RuleResult.DoesNotApply;

			// type can be non-visible (private or internal) but still reachable
			// with an interface or with an attribute (internals)
			bool type_visible = type.IsVisible ();

			foreach (EventDefinition evnt in type.Events) {
				// we assume that Add|Remove have the same visibility
				if (evnt.AddMethod.IsVisible ())
					continue;

				// report if Add|Remove is synchronized
				if (evnt.AddMethod.IsSynchronized) {
					Confidence confidence = type_visible ? Confidence.Normal : Confidence.Low;
					Runner.Report (evnt, Severity.Medium, confidence);
				}
			}
			return Runner.CurrentRuleResult;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:23,代码来源:ConsiderCustomAccessorsForNonVisibleEventsRule.cs

示例9: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule does not apply to enums, interfaces and generated code
			if (type.IsEnum || type.IsInterface || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;
			
			// rule applies only to visible types
			if (!type.IsVisible ())
				return RuleResult.DoesNotApply;

			// rule only applies if the type implements IEnumerable
			if (!type.Implements ("System.Collections", "IEnumerable"))
				return RuleResult.DoesNotApply;
		
			// rule does not apply to the types implementing IDictionary
			if (type.Implements ("System.Collections", "IDictionary"))
				return RuleResult.DoesNotApply;

			// the type should implement IEnumerable<T> too
			if (!type.Implements ("System.Collections.Generic", "IEnumerable`1"))
				Runner.Report (type, Severity.Medium, Confidence.High);

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

示例10: CheckTypeVisibility

		private void CheckTypeVisibility (TypeDefinition type)
		{
			// *NativeMethods types should never be visible outside the assembly
			if (type.IsVisible ()) {
				string msg = String.Format (CultureInfo.InvariantCulture, 
					"'{0}' should not be visible outside the assembly.", type.GetFullName ());
				Runner.Report (type, Severity.High, Confidence.Total, msg);
			}

			if (CanInstantiateType (type)) {
				string msg = String.Format (CultureInfo.InvariantCulture, 
					"'{0}' should not be static or sealed with no visible constructor.", type.GetFullName ());
				Runner.Report (type, Severity.High, Confidence.Total, msg);
			}
		}
开发者ID:col42dev,项目名称:mono-tools,代码行数:15,代码来源:CentralizePInvokesIntoNativeMethodsTypeRule.cs

示例11: CheckType

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

			// rule apply only to type that inherits from the base exceptions
			switch (type.BaseType.FullName) {
			case "System.Exception":
			case "System.SystemException":
			case "System.ApplicationException":
				break;
			default:
				return RuleResult.DoesNotApply;
			}

			if (type.IsAbstract || type.IsVisible ())
				return RuleResult.Success;

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

示例12: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			//type does not apply if not an interface or is an empty interface
			if (!type.IsInterface || !type.HasMethods)
				return RuleResult.DoesNotApply;

			//TODO: take into account [InternalsVisibleTo] on iface's assembly
			AssemblyDefinition current_assembly = type.Module.Assembly;
			if (type.IsVisible ()) {
				// We should not, by default, promote the implementation of interfaces in assemblies that
				// do not, already, refer to the current one because:
				// (a) we could be suggesting circular references (solvable, or not, by refactoring)
				// (b) it has a very HIGH performance cost, with verry LITTLE value (in # of defects)
				string current_assembly_name = current_assembly.Name.Name;
				foreach (AssemblyDefinition assembly in Runner.Assemblies) {
					// by default only process assemblies (from the set) that refers to the current one
					// or the current one itself
					if (!ReferencesOnly || (current_assembly_name == assembly.Name.Name) ||
						assembly.References (current_assembly_name)) {
						CheckAssemblyTypes (assembly, type);
					}
				}
			} else {
				// if the interface is not visible then we only check this assembly
				CheckAssemblyTypes (current_assembly, type);
			}

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

示例13: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule apply to internal (non-visible) types
			// note: IsAbstract also excludes static types (2.0)
			if (type.IsVisible () || type.IsAbstract || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			// people use this pattern to have a static class in C# 1.
			if (type.IsSealed && HasSinglePrivateConstructor (type))
				return RuleResult.DoesNotApply;

			// used for documentation purpose by monodoc
			if (type.Name == "NamespaceDoc")
				return RuleResult.DoesNotApply;

			// rule applies

			// if the type holds the Main entry point then it is considered useful
			AssemblyDefinition assembly = type.Module.Assembly;
			MethodDefinition entry_point = assembly.EntryPoint;
			if ((entry_point != null) && (entry_point.DeclaringType == type))
				return RuleResult.Success;

			// create a cache of all type instantiation inside this
			CacheInstantiationFromAssembly (assembly);

			HashSet<TypeReference> typeset = null;
			if (cache.ContainsKey (assembly))
				typeset = cache [assembly];

			// if we can't find the non-public type being used in the assembly then the rule fails
			if (typeset == null || !typeset.Contains (type)) {
				// base confidence on whether the internals are visible or not
				Confidence c = assembly.HasAttribute ("System.Runtime.CompilerServices.InternalsVisibleToAttribute") ? 
					Confidence.Low : Confidence.Normal;
				Runner.Report (type, Severity.High, c);
				return RuleResult.Failure;
			}

			return RuleResult.Success;
		}
开发者ID:nolanlum,项目名称:mono-tools,代码行数:41,代码来源:AvoidUninstantiatedInternalClassesRule.cs

示例14: GetBaseImplementor

		private static TypeDefinition GetBaseImplementor (TypeDefinition type, IEnumerable<MethodSignature> signatures)
		{
			TypeDefinition implementor = type;

			while (null != type && type.IsVisible ()) {
				//search for matching interface
				TypeDefinition ifaceDef = GetInterfaceImplementor (type, signatures);
				if (null != ifaceDef)
					implementor = ifaceDef;
				else if (DoesAllSignaturesMatchType (type, signatures))
					implementor = type;

				type = type.BaseType != null ? type.BaseType.Resolve () : null;
			}

			return implementor;
		}
开发者ID:boothead,项目名称:mono-tools,代码行数:17,代码来源:AvoidUnnecessarySpecializationRule.cs

示例15: 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


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