當前位置: 首頁>>代碼示例>>C#>>正文


C# TypeDefinition.IsStatic方法代碼示例

本文整理匯總了C#中Mono.Cecil.TypeDefinition.IsStatic方法的典型用法代碼示例。如果您正苦於以下問題:C# TypeDefinition.IsStatic方法的具體用法?C# TypeDefinition.IsStatic怎麽用?C# TypeDefinition.IsStatic使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Mono.Cecil.TypeDefinition的用法示例。


在下文中一共展示了TypeDefinition.IsStatic方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: CanInstantiateType

		static bool CanInstantiateType (TypeDefinition type)
		{
			// type is static (>= 2.0)
			if (type.IsStatic ())
				return false;

			if (type.IsSealed && type.HasMethods) {
				foreach (MethodDefinition ctor in type.Methods) {
					if (ctor.IsConstructor && ctor.IsVisible ())
						return true;
				}
				return false;
			}
			return true;
		}
開發者ID:col42dev,項目名稱:mono-tools,代碼行數:15,代碼來源:CentralizePInvokesIntoNativeMethodsTypeRule.cs

示例2: DoesTypeStealthilyImplementInterface

		private static bool DoesTypeStealthilyImplementInterface (TypeDefinition type, TypeReference iface)
		{
			//ignore already uninteresting types below (self, enum, struct, static class)
			if (type == iface || type.IsEnum || type.IsValueType || type.IsStatic ())
				return false;

			//if type has less methods than the interface no need to check further
			if (!type.HasMethods)
				return false;
			IList<MethodDefinition> mdc = iface.GetMethods ().ToList ();
			if (type.Methods.Count < mdc.Count)
				return false;

			//type already publicly says it implements the interface
			if (type.Implements (iface.FullName))
				return false;

			foreach (MethodDefinition m in mdc) {
				//if any candidate fails we can return right away
				//since the interface will never be fully implemented
				MethodDefinition candidate = type.GetMethod (MethodAttributes.Public, m.Name);
				if (null == candidate || !candidate.IsPublic || candidate.IsStatic)
					return false;

				//ok interesting candidate! let's check if it matches the signature
				if (!AreSameElementTypes (m.ReturnType, candidate.ReturnType))
					return false;

				if (!CompareParameters (m, candidate))
					return false;
			}

			return true;
		}
開發者ID:nolanlum,項目名稱:mono-tools,代碼行數:34,代碼來源:ConsiderAddingInterfaceRule.cs

示例3: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule applies only if the type isn't: an enum, an interface, a struct, a delegate or compiler generated
			if (type.IsEnum || type.IsInterface || type.IsValueType || type.IsDelegate () || type.IsGeneratedCode ())
				return RuleResult.DoesNotApply;

			// it also does not apply if the type is static (2.0+ only)
			if (type.IsStatic ())
				return RuleResult.DoesNotApply;

			if (!IsAllStatic (type))
				return RuleResult.Success;

			// rule applies!

			foreach (MethodDefinition ctor in type.Methods) {
				if (ctor.IsConstructor && !ctor.IsStatic && ctor.IsVisible ()) {
					Runner.Report (ctor, Severity.Low, Confidence.High);
				}
			}

			return Runner.CurrentRuleResult;
		}
開發者ID:col42dev,項目名稱:mono-tools,代碼行數:23,代碼來源:AvoidConstructorsInStaticTypesRule.cs

示例4: DoesTypeStealthilyImplementInterface

		private static bool DoesTypeStealthilyImplementInterface (TypeDefinition type, TypeDefinition iface)
		{
			//ignore already uninteresting types below (self, enum, struct, static class)
			if (type == iface || type.IsEnum || type.IsValueType || type.IsStatic ())
				return false;

			//if type has less methods than the interface no need to check further
			if (!type.HasMethods)
				return false;
			IList<MethodDefinition> mdc = iface.Methods;
			if (type.Methods.Count < mdc.Count)
				return false;

			//type already publicly says it implements the interface
			if (type.Implements (iface.Namespace, iface.Name))
				return false;

			foreach (MethodDefinition m in mdc) {
				// FIXME: ignore methods with generic constraints
				if (HasConstraints (m))
					return false;

				//if any candidate fails we can return right away
				//since the interface will never be fully implemented
				MethodDefinition candidate = type.GetMethod (MethodAttributes.Public, m.Name);
				if (null == candidate || !candidate.IsPublic || candidate.IsStatic)
					return false;

				//ok interesting candidate! let's check if it matches the signature
				if (!m.CompareSignature (candidate))
					return false;
				// FIXME: ignore methods with generic constraints
				if (HasConstraints (candidate))
					return false;
			}

			if (iface.HasInterfaces) {
				foreach (TypeReference tr in iface.Interfaces) {
					TypeDefinition td = tr.Resolve ();
					if (td == null)
						continue;
					if (!DoesTypeStealthilyImplementInterface (type, td))
						return false;
				}
			}
			return true;
		}
開發者ID:alfredodev,項目名稱:mono-tools,代碼行數:47,代碼來源:ConsiderAddingInterfaceRule.cs

示例5: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule applies only if the type isn't: an enum, an interface, a struct, a delegate or compiler generated
			if (type.IsEnum || type.IsInterface || type.IsValueType || !type.HasFields && GetMethodCount (type) == 0
				|| type.IsDelegate () || type.IsGeneratedCode () 
				|| type.BaseType != null && type.BaseType.FullName != "System.Object")
				return RuleResult.DoesNotApply;
			
			// success if the type is already static
			if (type.IsStatic ())
				return RuleResult.Success;
			
			if (IsAllStatic (type)) {
				// no technical reason not to use a static type exists
				Runner.Report (type, Severity.Medium, Confidence.High);
			}
			return Runner.CurrentRuleResult;
		}
開發者ID:boothead,項目名稱:mono-tools,代碼行數:18,代碼來源:ConsiderUsingStaticTypeRule.cs

示例6: CheckType

		public RuleResult CheckType (TypeDefinition type)
		{
			// rule applies only if the type isn't: an enum, an interface, a struct, a delegate or compiler generated
			if (type.IsEnum || type.IsInterface || type.IsValueType || type.IsDelegate () || type.IsGeneratedCode () 
				|| type.BaseType != null && !type.BaseType.IsNamed ("System", "Object"))
				return RuleResult.DoesNotApply;
			
			// success if the type is already static or, before 2.0, is it's sealed
			if ((type.Module.Runtime >= TargetRuntime.Net_2_0) ? type.IsStatic () : type.IsSealed)
				return RuleResult.Success;
			
			if (IsAllStatic (type)) {
				// no technical reason not to use a static type exists
				Runner.Report (type, Severity.Medium, Confidence.High);
			}
			return Runner.CurrentRuleResult;
		}
開發者ID:col42dev,項目名稱:mono-tools,代碼行數:17,代碼來源:ConsiderUsingStaticTypeRule.cs


注:本文中的Mono.Cecil.TypeDefinition.IsStatic方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。