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


C# TypeDefinition.IsGeneratedCode方法代码示例

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


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

示例1: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			//does rule apply?
			if (type.IsEnum || type.IsInterface || type.IsAbstract || type.IsDelegate () || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			if (!type.HasFields || (type.Fields.Count < MinimumFieldCount))
				return RuleResult.DoesNotApply;
			if (!type.HasMethods || (type.Methods.Count < MinimumMethodCount))
				return RuleResult.DoesNotApply;

			//yay! rule do apply!
			double coh = GetCohesivenessForType (type);
			if (coh >= SuccessLowerLimit)
				return RuleResult.Success;
			if (0 == coh)
				return RuleResult.DoesNotApply;

			//how's severity?
			Severity sev = GetCohesivenessSeverity(coh);

			string msg = String.Format (CultureInfo.CurrentCulture, "Type cohesiveness : {0}%", (int) (coh * 100));
			Runner.Report (type, sev, Confidence.Normal, msg);
			return RuleResult.Failure;
		}
开发者ID:col42dev,项目名称:mono-tools,代码行数:25,代码来源:AvoidLackOfCohesionOfMethodsRule.cs

示例2: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule only apply to (non generated) delegates
			if (!type.IsDelegate () || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			MethodDefinition invoke = type.GetMethod ("Invoke");
			// this happens for System.MulticastDelegate
			if (invoke == null)
				return RuleResult.DoesNotApply;

			if (!invoke.ReturnType.IsNamed ("System", "Void"))
				return RuleResult.Success;

			if (!invoke.HasParameters)
				return RuleResult.Success;

			IList<ParameterDefinition> pdc = invoke.Parameters;
			if (pdc.Count != 2)
				return RuleResult.Success;
			if (!pdc [0].ParameterType.IsNamed ("System", "Object"))
				return RuleResult.Success;
			if (!pdc [1].ParameterType.Inherits ("System", "EventArgs"))
				return RuleResult.Success;

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

示例3: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule applies only to types, interfaces and structures (value types)
			if (type.IsEnum || type.IsDelegate () || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			// rule onyly applies to type that implements IDisposable
			if (!type.Implements ("System.IDisposable"))
				return RuleResult.DoesNotApply;

			// no problem is a finalizer is found
			if (type.HasMethod (MethodSignatures.Finalize))
				return RuleResult.Success;

			// otherwise check for native types
			foreach (FieldDefinition field in type.Fields) {
				// we can't dispose static fields in IDisposable
				if (field.IsStatic)
					continue;
				if (!field.FieldType.GetElementType ().IsNative ())
					continue;
				Runner.Report (field, Severity.High, Confidence.High);
			}

			// special case: a struct cannot define a finalizer so it's a
			// bad candidate to hold references to unmanaged resources
			if (type.IsValueType && (Runner.CurrentRuleResult == RuleResult.Failure))
				Runner.Report (type, Severity.High, Confidence.High, Struct);

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

示例4: CheckType

        public RuleResult CheckType(TypeDefinition type)
        {
            // rule applies only to types and interfaces
            if (type.IsEnum || type.IsDelegate() || type.IsGeneratedCode() ||
                type.IsValueType || type.IsInterface)
                return RuleResult.DoesNotApply;

            // rule only applies to type that implements IDisposable
            if (!type.Implements("System", "IDisposable"))
                return RuleResult.DoesNotApply;

            // rule only applies to type that doesn't derive from class that implements IDisposable
            if (type.BaseType.Implements("System", "IDisposable"))
                return RuleResult.DoesNotApply;

            // rule only applies if type has a Dispose(bool) method
            if (!type.HasMethod(Dispose))
                return RuleResult.DoesNotApply;

            // no problem if a finalizer is found
            if (type.HasMethod(MethodSignatures.Finalize))
                return RuleResult.Success;

            Runner.Report(type, Severity.Medium, Confidence.High);
            return RuleResult.Failure;
        }
开发者ID:sillsdev,项目名称:FwGendarmeRules,代码行数:26,代码来源:EnsureDebugDisposeFinalizerRule.cs

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

示例6: CheckType

		public RuleResult CheckType (TypeDefinition type) 
		{
			//Skip the <Module> type declaration.
			if (type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;
			Runner.Report (type, Severity.High, Confidence.High);
			return RuleResult.Failure;
		}
开发者ID:TheRealDuckboy,项目名称:mono-soc-2008,代码行数:8,代码来源:FakeRules.cs

示例7: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// that will cover interfaces, delegates too
			if (!type.HasFields)
				return RuleResult.DoesNotApply;

			// rule doesn't apply to enums, interfaces, structs, delegates or generated code
			if (type.IsEnum || type.IsValueType || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			MethodDefinition explicitDisposeMethod = null;
			MethodDefinition implicitDisposeMethod = null;

			bool abstractWarning = false;

			if (type.Implements ("System", "IDisposable")) {
				implicitDisposeMethod = type.GetMethod (MethodSignatures.Dispose);
				explicitDisposeMethod = type.GetMethod (MethodSignatures.DisposeExplicit);

				if (IsAbstract (implicitDisposeMethod) || IsAbstract (explicitDisposeMethod)) {
					abstractWarning = true;
				} else {
					return RuleResult.Success;
				}
			}

			FieldCandidates.Clear ();

			foreach (FieldDefinition field in type.Fields) {
				// we can't dispose static fields in IDisposable
				if (field.IsStatic)
					continue;
				TypeDefinition fieldType = field.FieldType.GetElementType ().Resolve ();
				if (fieldType == null)
					continue;
				if (FieldTypeIsCandidate (fieldType))
					FieldCandidates.Add (field);
			}

			// if there are fields types that implements IDisposable
			if (type.HasMethods && (FieldCandidates.Count > 0)) {
				// check if we're assigning new object to them
				foreach (MethodDefinition method in type.Methods) {
					CheckMethod (method, abstractWarning);
				}
			}

			// Warn about possible confusion if the Dispose methods are abstract
			if (IsAbstract (implicitDisposeMethod))
				Runner.Report (implicitDisposeMethod, Severity.Medium, Confidence.High, AbstractDisposeMessage);

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

示例8: CheckType

		virtual public RuleResult CheckType (TypeDefinition type)
		{
			if (type.IsAbstract || type.IsGeneratedCode () || !type.Implements (InterfaceNamespace, InterfaceName))
				return RuleResult.DoesNotApply;

			signatures = GetMethods ();
			propertyNames = GetProperties ();

			methodsLeft = signatures.Length;
			propertiesLeft = propertyNames.Length;

			TypeDefinition baseType = type;
			while (methodsLeft > 0 || propertiesLeft > 0) {
				ProcessType (baseType);
				if (baseType.BaseType == null)
					break;
				TypeDefinition td = baseType.BaseType.Resolve ();
				if (td == null)
					break;
				baseType = td;

			}

			if (propertiesLeft > 0) {
				foreach (string propertyName in propertyNames) {
					if (propertyName == null)
						continue;
					Runner.Report (type, Severity.Medium, Confidence.High,
						"Type does not have strongly typed version of property " + propertyName);
				}
			}

			if (methodsLeft > 0) {
				foreach (MethodSignature signature in signatures) {
					if (signature == null)
						continue;
					Runner.Report (type, Severity.Medium, Confidence.High,
						"Type does not have strongly typed version of method " + signature.Name);
				}
			}

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

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

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

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

示例12: CheckType

        public RuleResult CheckType(TypeDefinition type)
        {
            // don't analyze cases where no methods (or body) are available
            if (type.IsEnum || type.IsInterface || !type.HasMethods)
                return RuleResult.DoesNotApply;

            // ignore code generated by compiler/tools, since they can generate some amount of duplicated code
            if (type.IsGeneratedCode ())
                return RuleResult.DoesNotApply;

            locator.Clear ();
            foreach (MethodDefinition current in type.Methods) {
                locator.CompareMethodAgainstTypeMethods (current, type);
                locator.CheckedMethods.AddIfNew (current.Name);
            }

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

示例13: CheckType

        public RuleResult CheckType(TypeDefinition type)
        {
            // rule applies only to ValueType, except enums and generated code
            if (!type.IsValueType || type.IsEnum || type.IsGeneratedCode ())
                return RuleResult.DoesNotApply;

            // note: no inheritance check required since we're dealing with structs

            bool equals = type.HasMethod (MethodSignatures.Equals);
            bool gethashcode = type.HasMethod (MethodSignatures.GetHashCode);
            bool operators = type.HasMethod (MethodSignatures.op_Equality) &&
                type.HasMethod (MethodSignatures.op_Inequality);

            // note: we want to avoid reporting 4 defects each (well most) of the time
            // the rule is triggered (it's too verbose to be useful)
            if (equals && gethashcode && operators)
                return RuleResult.Success;

            // drop severity one level if only operators are missing (since overloading them
            // is not available in every language)
            Severity severity = (equals || gethashcode) ? Severity.Medium : Severity.Low;
            string msg = String.Format (CultureInfo.InvariantCulture, MissingImplementationMessage,
                !equals && !gethashcode ? "Equals(object)' and 'GetHashCode()" : equals ? "GetHashCode()" : "Equals(object)",
                operators ? String.Empty : MissingOperatorsMessage);

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

示例14: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule does not apply to enums, delegates and to generated code
			if (type.IsEnum || type.IsDelegate () || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			// rule applies only if the type overrides Equals(object)
			if (!type.HasMethod (MethodSignatures.Equals))
				return RuleResult.DoesNotApply;

			// if so then the type should also implement Equals(type) since this avoid a cast 
			// operation (for reference types) and also boxing (for value types).

			// we suggest to implement IEquatable<T> if
			// * the assembly targets the 2.0 (or later) runtime
			// * and it does not already implement it
			if (type.Module.Runtime >= TargetRuntime.Net_2_0) {
				if (!type.Implements ("System", "IEquatable`1")) {
					Runner.Report (type, Severity.Medium, Confidence.Total, "Implement System.IEquatable<T>");
				}
				return Runner.CurrentRuleResult;
			}

			parameters [0] = type.GetFullName ();
			if (type.GetMethod (MethodAttributes.Public, "Equals", "System.Boolean", parameters) != null)
				return RuleResult.Success;

			// we consider this a step more severe for value types since it will need 
			// boxing/unboxing with Equals(object)
			Severity severity = type.IsValueType ? Severity.Medium : Severity.Low;
			string msg = String.Format (CultureInfo.InvariantCulture, "Implement 'bool Equals({0})'", type.Name);
			Runner.Report (type, severity, Confidence.High, msg);
			return RuleResult.Failure;
		}
开发者ID:col42dev,项目名称:mono-tools,代码行数:34,代码来源:ImplementEqualsTypeRule.cs

示例15: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			if (type.IsEnum || !type.HasFields || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			//collect *has* fields
			foreach (FieldDefinition fd in type.Fields) {
				if (!fd.FieldType.IsValueType || fd.IsSpecialName || fd.HasConstant || fd.IsInitOnly)
					continue;

				string prefix = null, suffix = null;
				if (IsHasField(fd, ref prefix, ref suffix)
					&& HasValueTypeField(type, string.Concat(prefix,suffix)) ) {
					//TODO: check if they are both used in the same method? does the complexity worth it?
					string s = (Runner.VerbosityLevel > 0)
						? String.Format ("Field '{0}' should probably be a nullable if '{1}' purpose is to inform if '{0}' has been set.", fd.Name, suffix)
						: string.Empty;
					Runner.Report (fd, Severity.Low, Confidence.Low, s);
				}
			}

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


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