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


C# CSharp.TypeParameterSpec類代碼示例

本文整理匯總了C#中Mono.CSharp.TypeParameterSpec的典型用法代碼示例。如果您正苦於以下問題:C# TypeParameterSpec類的具體用法?C# TypeParameterSpec怎麽用?C# TypeParameterSpec使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


TypeParameterSpec類屬於Mono.CSharp命名空間,在下文中一共展示了TypeParameterSpec類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: ImplicitTypeParameterConversion

		public static Expression ImplicitTypeParameterConversion (Expression expr, TypeParameterSpec expr_type, TypeSpec target_type)
		{
			//
			// From T to a type parameter U, provided T depends on U
			//
			if (target_type.IsGenericParameter) {
				if (expr_type.TypeArguments != null && expr_type.HasDependencyOn (target_type)) {
					if (expr == null)
						return EmptyExpression.Null;

					if (expr_type.IsReferenceType && !((TypeParameterSpec) target_type).IsReferenceType)
						return new BoxedCast (expr, target_type);

					return new ClassCast (expr, target_type);
				}

				return null;
			}

			//
			// LAMESPEC: From T to dynamic type because it's like T to object
			//
			if (target_type.BuiltinType == BuiltinTypeSpec.Type.Dynamic) {
				if (expr == null)
					return EmptyExpression.Null;

				if (expr_type.IsReferenceType)
					return new ClassCast (expr, target_type);

				return new BoxedCast (expr, target_type);
			}

			//
			// From T to its effective base class C
			// From T to any base class of C (it cannot contain dynamic or be of dynamic type)
			// From T to any interface implemented by C
			//
			var base_type = expr_type.GetEffectiveBase ();
			if (base_type == target_type || TypeSpec.IsBaseClass (base_type, target_type, false) || base_type.ImplementsInterface (target_type, true)) {
				if (expr == null)
					return EmptyExpression.Null;

				if (expr_type.IsReferenceType)
					return new ClassCast (expr, target_type);

				return new BoxedCast (expr, target_type);
			}

			if (target_type.IsInterface && expr_type.IsConvertibleToInterface (target_type)) {
				if (expr == null)
					return EmptyExpression.Null;

				if (expr_type.IsReferenceType)
					return new ClassCast (expr, target_type);

				return new BoxedCast (expr, target_type);
			}

			return null;
		}
開發者ID:nberardi,項目名稱:mono,代碼行數:60,代碼來源:convert.cs

示例2: TypeParameterInflator

        public TypeParameterInflator(TypeSpec type, TypeParameterSpec[] tparams, TypeSpec[] targs)
        {
            if (tparams.Length != targs.Length)
                throw new ArgumentException ("Invalid arguments");

            this.tparams = tparams;
            this.targs = targs;
            this.type = type;
        }
開發者ID:speier,項目名稱:shake,代碼行數:9,代碼來源:generic.cs

示例3: HoistedStoreyClass

		public HoistedStoreyClass (DeclSpace parent, MemberName name, TypeParameter[] tparams, Modifiers mod)
			: base (parent, name, mod | Modifiers.PRIVATE)
		{
			if (tparams != null) {
				type_params = new TypeParameter[tparams.Length];
				var src = new TypeParameterSpec[tparams.Length];
				var dst = new TypeParameterSpec[tparams.Length];

				for (int i = 0; i < type_params.Length; ++i) {
					type_params[i] = tparams[i].CreateHoistedCopy (this, spec);

					src[i] = tparams[i].Type;
					dst[i] = type_params[i].Type;
				}

				// A copy is not enough, inflate any type parameter constraints
				// using a new type parameters
				var inflator = new TypeParameterInflator (null, src, dst);
				for (int i = 0; i < type_params.Length; ++i) {
					src[i].InflateConstraints (inflator, dst[i]);
				}
			}
		}
開發者ID:Tak,項目名稱:monodevelop-novell,代碼行數:23,代碼來源:anonymous.cs

示例4: ImportedGenericMethodDefinition

		public ImportedGenericMethodDefinition (MethodInfo provider, AParametersCollection parameters, TypeParameterSpec[] tparams)
			: base (provider, parameters)
		{
			this.tparams = tparams;
		}
開發者ID:telurmasin,項目名稱:mono,代碼行數:5,代碼來源:import.cs

示例5: ExplicitTypeParameterConversionToT

		static Expression ExplicitTypeParameterConversionToT (Expression source, TypeSpec source_type, TypeParameterSpec target_type)
		{
			//
			// From the effective base class C of T to T and from any base class of C to T
			//
			var effective = target_type.GetEffectiveBase ();
			if (TypeSpecComparer.IsEqual (effective, source_type) || TypeSpec.IsBaseClass (effective, source_type, false))
				return source == null ? EmptyExpression.Null : new ClassCast (source, target_type);

			return null;
		}
開發者ID:frje,項目名稱:SharpLang,代碼行數:11,代碼來源:convert.cs

示例6: TypeParameter

		public TypeParameter (TypeParameterSpec spec, DeclSpace parent, TypeSpec parentSpec, MemberName name, Attributes attrs)
			: base (parent, name, attrs)
		{
			this.spec = new TypeParameterSpec (parentSpec, spec.DeclaredPosition, spec.MemberDefinition, spec.SpecialConstraint, spec.Variance, null) {
				BaseType = spec.BaseType,
				InterfacesDefined = spec.InterfacesDefined,
				TypeArguments = spec.TypeArguments
			};
		}
開發者ID:afaerber,項目名稱:mono,代碼行數:9,代碼來源:generic.cs

示例7: CreateTypeParameter

		TypeParameterSpec CreateTypeParameter (MetaType type, TypeSpec declaringType)
		{
			Variance variance;
			switch (type.GenericParameterAttributes & GenericParameterAttributes.VarianceMask) {
			case GenericParameterAttributes.Covariant:
				variance = Variance.Covariant;
				break;
			case GenericParameterAttributes.Contravariant:
				variance = Variance.Contravariant;
				break;
			default:
				variance = Variance.None;
				break;
			}

			SpecialConstraint special = SpecialConstraint.None;
			var import_special = type.GenericParameterAttributes & GenericParameterAttributes.SpecialConstraintMask;

			if ((import_special & GenericParameterAttributes.NotNullableValueTypeConstraint) != 0) {
				special |= SpecialConstraint.Struct;
			} else if ((import_special & GenericParameterAttributes.DefaultConstructorConstraint) != 0) {
				special = SpecialConstraint.Constructor;
			}

			if ((import_special & GenericParameterAttributes.ReferenceTypeConstraint) != 0) {
				special |= SpecialConstraint.Class;
			}

			TypeParameterSpec spec;
			var def = new ImportedTypeParameterDefinition (type, this);
			if (type.DeclaringMethod != null) {
				spec = new TypeParameterSpec (type.GenericParameterPosition, def, special, variance, type);
			} else {
				spec = new TypeParameterSpec (declaringType, type.GenericParameterPosition, def, special, variance, type);
			}

			return spec;
		}
開發者ID:Gobiner,項目名稱:ILSpy,代碼行數:38,代碼來源:import.cs

示例8: ImportedGenericMethodDefinition

		public ImportedGenericMethodDefinition (MethodInfo provider, TypeSpec type, AParametersCollection parameters, TypeParameterSpec[] tparams, MetadataImporter importer)
			: base (provider, type, parameters, importer)
		{
			this.tparams = tparams;
		}
開發者ID:Gobiner,項目名稱:ILSpy,代碼行數:5,代碼來源:import.cs

示例9: HasSameConstraintsDefinition

		//
		// Constraints have to match by definition but not position, used by
		// partial classes or methods
		//
		public bool HasSameConstraintsDefinition (TypeParameterSpec other)
		{
			if (spec != other.spec)
				return false;

			if (BaseType != other.BaseType)
				return false;

			if (!TypeSpecComparer.Override.IsSame (InterfacesDefined, other.InterfacesDefined))
				return false;

			if (!TypeSpecComparer.Override.IsSame (targs, other.targs))
				return false;

			return true;
		}
開發者ID:ikvm,項目名稱:mono,代碼行數:20,代碼來源:generic.cs

示例10: TypeParameter

		public TypeParameter (DeclSpace parent, int index, MemberName name, Constraints constraints, Attributes attrs, Variance variance)
			: base (parent, name, attrs)
		{
			this.constraints = constraints;
//			this.variance = variance;
			this.spec = new TypeParameterSpec (null, index, this, SpecialConstraint.None, variance, null);
		}
開發者ID:ikvm,項目名稱:mono,代碼行數:7,代碼來源:generic.cs

示例11: CheckConversion

		static void CheckConversion (IMemberContext mc, MemberSpec context, TypeSpec atype, TypeParameterSpec tparam, TypeSpec ttype, Location loc)
		{
			var expr = new EmptyExpression (atype);
			if (!Convert.ImplicitStandardConversionExists (expr, ttype)) {
				mc.Compiler.Report.SymbolRelatedToPreviousError (tparam);
				if (TypeManager.IsValueType (atype)) {
					mc.Compiler.Report.Error (315, loc, "The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. There is no boxing conversion from `{0}' to `{3}'",
						atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError (), ttype.GetSignatureForError ());
				} else if (atype.IsGenericParameter) {
					mc.Compiler.Report.Error (314, loc, "The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. There is no boxing or type parameter conversion from `{0}' to `{3}'",
						atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError (), ttype.GetSignatureForError ());
				} else {
					mc.Compiler.Report.Error (311, loc, "The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. There is no implicit reference conversion from `{0}' to `{3}'",
						atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError (), ttype.GetSignatureForError ());
				}
			}
		}
開發者ID:ikvm,項目名稱:mono,代碼行數:17,代碼來源:generic.cs

示例12: CheckConstraint

		static bool CheckConstraint (IMemberContext mc, MemberSpec context, TypeSpec atype, TypeParameterSpec tparam, Location loc)
		{
			//
			// First, check the `class' and `struct' constraints.
			//
			if (tparam.HasSpecialClass && !TypeManager.IsReferenceType (atype)) {
				mc.Compiler.Report.Error (452, loc,
					"The type `{0}' must be a reference type in order to use it as type parameter `{1}' in the generic type or method `{2}'",
					TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ());
				return false;
			}

			if (tparam.HasSpecialStruct && (!TypeManager.IsValueType (atype) || TypeManager.IsNullableType (atype))) {
				mc.Compiler.Report.Error (453, loc,
					"The type `{0}' must be a non-nullable value type in order to use it as type parameter `{1}' in the generic type or method `{2}'",
					TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ());
				return false;
			}

			//
			// The class constraint comes next.
			//
			if (tparam.HasTypeConstraint) {
				CheckConversion (mc, context, atype, tparam, tparam.BaseType, loc);
			}

			//
			// Now, check the interfaces and type parameters constraints
			//
			if (tparam.Interfaces != null) {
				if (TypeManager.IsNullableType (atype)) {
					mc.Compiler.Report.Error (313, loc,
						"The type `{0}' cannot be used as type parameter `{1}' in the generic type or method `{2}'. The nullable type `{0}' never satisfies interface constraint",
						atype.GetSignatureForError (), tparam.GetSignatureForError (), context.GetSignatureForError ());
				} else {
					foreach (TypeSpec iface in tparam.Interfaces) {
						CheckConversion (mc, context, atype, tparam, iface, loc);
					}
				}
			}

			//
			// Finally, check the constructor constraint.
			//
			if (!tparam.HasSpecialConstructor)
				return true;

			if (!HasDefaultConstructor (atype)) {
				mc.Compiler.Report.SymbolRelatedToPreviousError (atype);
				mc.Compiler.Report.Error (310, loc,
					"The type `{0}' must have a public parameterless constructor in order to use it as parameter `{1}' in the generic type or method `{2}'",
					TypeManager.CSharpName (atype), tparam.GetSignatureForError (), context.GetSignatureForError ());
				return false;
			}

			return true;
		}
開發者ID:ikvm,項目名稱:mono,代碼行數:57,代碼來源:generic.cs

示例13: CheckAll

		/// <summary>
		///   Check the constraints; we're called from ResolveAsTypeTerminal()
		///   after fully resolving the constructed type.
		/// </summary>
		public static bool CheckAll (IMemberContext mc, MemberSpec context, TypeSpec[] targs, TypeParameterSpec[] tparams, Location loc)
		{
			for (int i = 0; i < tparams.Length; i++) {
				if (!CheckConstraint (mc, context, targs [i], tparams [i], loc))
					return false;
			}

			return true;
		}
開發者ID:ikvm,項目名稱:mono,代碼行數:13,代碼來源:generic.cs

示例14: Mutate

		public TypeParameterSpec Mutate (TypeParameterSpec tp)
		{
			for (int i = 0; i < mvar.Length; ++i) {
				if (mvar[i].Type == tp)
					return var[i].Type;
			}

			return tp;
		}
開發者ID:ikvm,項目名稱:mono,代碼行數:9,代碼來源:generic.cs

示例15: Inflate

		public TypeSpec Inflate (TypeParameterSpec tp)
		{
			for (int i = 0; i < tparams.Length; ++i)
				if (tparams [i] == tp)
					return targs[i];

			// This can happen when inflating nested types
			// without type arguments specified
			return tp;
		}
開發者ID:ikvm,項目名稱:mono,代碼行數:10,代碼來源:generic.cs


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