• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# CSharp.TypeParameter类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中Mono.CSharp.TypeParameter的典型用法代码示例。如果您正苦于以下问题:C# TypeParameter类的具体用法?C# TypeParameter怎么用?C# TypeParameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



TypeParameter类属于Mono.CSharp命名空间,在下文中一共展示了TypeParameter类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: HoistedStoreyClass

		public HoistedStoreyClass (TypeContainer 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 (this, null, src, dst);
				for (int i = 0; i < type_params.Length; ++i) {
					src[i].InflateConstraints (inflator, dst[i]);
				}

				mutator = new TypeParameterMutator (tparams, type_params);
			}
		}
开发者ID:nzaugg,项目名称:mono,代码行数:25,代码来源:anonymous.cs


示例2: 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];
				for (int i = 0; i < type_params.Length; ++i) {
					type_params[i] = tparams[i].CreateHoistedCopy (this, spec);
				}
			}
		}
开发者ID:pgoron,项目名称:monodevelop,代码行数:10,代码来源:anonymous.cs


示例3: MakeMemberName

		protected static MemberName MakeMemberName (MemberBase host, string name, int unique_id, TypeParameter[] tparams, Location loc)
		{
			string host_name = host == null ? null : host.Name;
			string tname = MakeName (host_name, "c", name, unique_id);
			TypeArguments args = null;
			if (tparams != null) {
				args = new TypeArguments ();
				foreach (TypeParameter tparam in tparams)
					args.Add (new TypeParameterName (tparam.Name, null, loc));
			}

			return new MemberName (tname, args, loc);
		}
开发者ID:nzaugg,项目名称:mono,代码行数:13,代码来源:anonymous.cs


示例4: GenericMethod

		public GenericMethod (NamespaceEntry ns, DeclSpace parent, MemberName name, TypeParameter[] tparams,
					  FullNamedExpression return_type, ParametersCompiled parameters)
			: this (ns, parent, name, return_type, parameters)
		{
			this.type_params = tparams;
		}
开发者ID:ikvm,项目名称:mono,代码行数:6,代码来源:generic.cs


示例5: case_355

void case_355()
#line 2902 "cs-parser.jay"
{
		var lt = (Tokenizer.LocatedToken)yyVals[0+yyTop];
		yyVal = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)yyVals[-2+yyTop], (Variance) yyVals[-1+yyTop]);
  	  }
开发者ID:xamarin-release-manager,项目名称:monodevelop,代码行数:6,代码来源:cs-parser.cs


示例6: SimpleName

		public SimpleName (string name, TypeParameter[] type_params, Location l)
			: base (name, l)
		{
			targs = new TypeArguments ();
			foreach (TypeParameter type_param in type_params)
				targs.Add (new TypeParameterExpr (type_param, l));
		}
开发者ID:lewurm,项目名称:benchmarker,代码行数:7,代码来源:ecore.cs


示例7: FindTypeParameter

		public static TypeParameter FindTypeParameter (TypeParameter[] all, string name)
		{
			throw new NotImplementedException ();
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:4,代码来源:generic-mcs.cs


示例8: ConvertToType

			static AstType ConvertToType(TypeParameter spec)
			{
				AstType result;
				result = new SimpleType { IdentifierToken = Identifier.Create(spec.Name, Convert(spec.Location)) };
				return result;
			}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:6,代码来源:CSharpParser.cs


示例9: SetParameterInfo

		public virtual void SetParameterInfo (List<Constraints> constraints_list)
		{
#if FULL_AST
			if (constraints_list != null) {
				this.PlainConstraints = constraints_list;
				constraints_list = this.Constraints = new List<Constraints> (constraints_list);
			}
#else
			this.Constraints = constraints_list;
#endif
			if (!is_generic) {
				if (constraints_list != null) {
					Report.Error (
						80, Location, "Constraints are not allowed " +
						"on non-generic declarations");
				}

				return;
			}

			TypeParameterName[] names = MemberName.TypeArguments.GetDeclarations ();
			type_params = new TypeParameter [names.Length];

			//
			// Register all the names
			//
			for (int i = 0; i < type_params.Length; i++) {
				TypeParameterName name = names [i];

				Constraints constraints = null;
				if (constraints_list != null) {
					int total = constraints_list.Count;
					for (int ii = 0; ii < total; ++ii) {
						Constraints constraints_at = (Constraints)constraints_list[ii];
						// TODO: it is used by iterators only
						if (constraints_at == null) {
							constraints_list.RemoveAt (ii);
							--total;
							continue;
						}
						if (constraints_at.TypeParameter.Value == name.Name) {
							constraints = constraints_at;
							constraints_list.RemoveAt(ii);
							break;
						}
					}
				}

				Variance variance = name.Variance;
				if (name.Variance != Variance.None && !(this is Delegate || this is Interface)) {
					Report.Error (1960, name.Location, "Variant type parameters can only be used with interfaces and delegates");
					variance = Variance.None;
				}

				type_params [i] = new TypeParameter (
					Parent, i, new MemberName (name.Name, Location), constraints, name.OptAttributes, variance);

				AddToContainer (type_params [i], name.Name);
			}

			if (constraints_list != null && constraints_list.Count > 0) {
				foreach (Constraints constraint in constraints_list) {
					Report.Error(699, constraint.Location, "`{0}': A constraint references nonexistent type parameter `{1}'", 
						GetSignatureForError (), constraint.TypeParameter.Value);
				}
			}
		}
开发者ID:constructor-igor,项目名称:cudafy,代码行数:67,代码来源:decl.cs


示例10: case_366

void case_366()
#line 3016 "cs-parser.jay"
{
		var lt = (LocatedToken)yyVals[0+yyTop];
		var variance = (Variance) yyVals[-1+yyTop];
		yyVal = new TypeParameter (new MemberName (lt.Value, lt.Location), (Attributes)yyVals[-2+yyTop], variance);
		if (variance != Variance.None)
			lbag.AddLocation (yyVal, savedLocation);
  	  }
开发者ID:segaman,项目名称:NRefactory,代码行数:9,代码来源:cs-parser.cs


示例11: DoCreateMethodHost

		//
		// Creates a host for the anonymous method
		//
		AnonymousMethodMethod DoCreateMethodHost (EmitContext ec)
		{
			//
			// Anonymous method body can be converted to
			//
			// 1, an instance method in current scope when only `this' is hoisted
			// 2, a static method in current scope when neither `this' nor any variable is hoisted
			// 3, an instance method in compiler generated storey when any hoisted variable exists
			//

			Modifiers modifiers;
			if (Block.HasCapturedVariable || Block.HasCapturedThis) {
				storey = FindBestMethodStorey ();
				modifiers = storey != null ? Modifiers.INTERNAL : Modifiers.PRIVATE;
			} else {
				if (ec.CurrentAnonymousMethod != null)
					storey = ec.CurrentAnonymousMethod.Storey;

				modifiers = Modifiers.STATIC | Modifiers.PRIVATE;
			}

			TypeContainer parent = storey != null ? storey : ec.CurrentTypeDefinition.Parent.PartialContainer;

			MemberCore mc = ec.MemberContext as MemberCore;
			string name = CompilerGeneratedClass.MakeName (parent != storey ? block_name : null,
				"m", null, unique_id++);

			MemberName member_name;
			GenericMethod generic_method;
			if (storey == null && mc.MemberName.TypeArguments != null) {
				member_name = new MemberName (name, mc.MemberName.TypeArguments.Clone (), Location);

				var hoisted_tparams = ec.CurrentTypeParameters;
				var type_params = new TypeParameter[hoisted_tparams.Length];
				for (int i = 0; i < type_params.Length; ++i) {
					type_params[i] = hoisted_tparams[i].CreateHoistedCopy (parent, null);
				}

				generic_method = new GenericMethod (parent.NamespaceEntry, parent, member_name, type_params,
					new TypeExpression (ReturnType, Location), parameters);
			} else {
				member_name = new MemberName (name, Location);
				generic_method = null;
			}

			string real_name = String.Format (
				"{0}~{1}{2}", mc.GetSignatureForError (), GetSignatureForError (),
				parameters.GetSignatureForError ());

			return new AnonymousMethodMethod (parent,
				this, storey, generic_method, new TypeExpression (ReturnType, Location), modifiers,
				real_name, member_name, parameters);
		}
开发者ID:nzaugg,项目名称:mono,代码行数:56,代码来源:anonymous.cs


示例12: Resolve

		//
		// Resolve the constraints types with only possible early checks, return
		// value `false' is reserved for recursive failure
		//
		public bool Resolve (IMemberContext context, TypeParameter tp)
		{
			if (resolved)
				return true;

			if (resolving)
				return false;

			resolving = true;
			var spec = tp.Type;
			List<TypeParameterSpec> tparam_types = null;
			bool iface_found = false;

			spec.BaseType = TypeManager.object_type;

			for (int i = 0; i < constraints.Count; ++i) {
				var constraint = constraints[i];

				if (constraint is SpecialContraintExpr) {
					spec.SpecialConstraint |= ((SpecialContraintExpr) constraint).Constraint;
					if (spec.HasSpecialStruct)
						spec.BaseType = TypeManager.value_type;

					// Set to null as it does not have a type
					constraints[i] = null;
					continue;
				}

				var type_expr = constraints[i] = constraint.ResolveAsTypeTerminal (context, false);
				if (type_expr == null)
					continue;

				var gexpr = type_expr as GenericTypeExpr;
				if (gexpr != null && gexpr.HasDynamicArguments ()) {
					context.Compiler.Report.Error (1968, constraint.Location,
						"A constraint cannot be the dynamic type `{0}'", gexpr.GetSignatureForError ());
					continue;
				}

				var type = type_expr.Type;

				if (!context.CurrentMemberDefinition.IsAccessibleAs (type)) {
					context.Compiler.Report.SymbolRelatedToPreviousError (type);
					context.Compiler.Report.Error (703, loc,
						"Inconsistent accessibility: constraint type `{0}' is less accessible than `{1}'",
						type.GetSignatureForError (), context.GetSignatureForError ());
				}

				if (type.IsInterface) {
					if (!spec.AddInterface (type)) {
						context.Compiler.Report.Error (405, constraint.Location,
							"Duplicate constraint `{0}' for type parameter `{1}'", type.GetSignatureForError (), tparam.Value);
					}

					iface_found = true;
					continue;
				}


				var constraint_tp = type as TypeParameterSpec;
				if (constraint_tp != null) {
					if (tparam_types == null) {
						tparam_types = new List<TypeParameterSpec> (2);
					} else if (tparam_types.Contains (constraint_tp)) {
						context.Compiler.Report.Error (405, constraint.Location,
							"Duplicate constraint `{0}' for type parameter `{1}'", type.GetSignatureForError (), tparam.Value);
						continue;
					}

					//
					// Checks whether each generic method parameter constraint type
					// is valid with respect to T
					//
					if (tp.IsMethodTypeParameter) {
						TypeManager.CheckTypeVariance (type, Variance.Contravariant, context);
					}

					var tp_def = constraint_tp.MemberDefinition as TypeParameter;
					if (tp_def != null && !tp_def.ResolveConstraints (context)) {
						context.Compiler.Report.Error (454, constraint.Location,
							"Circular constraint dependency involving `{0}' and `{1}'",
							constraint_tp.GetSignatureForError (), tp.GetSignatureForError ());
						continue;
					}

					//
					// Checks whether there are no conflicts between type parameter constraints
					//
					// class Foo<T, U>
					//      where T : A
					//      where U : B, T
					//
					// A and B are not convertible and only 1 class constraint is allowed
					//
					if (constraint_tp.HasTypeConstraint) {
						if (spec.HasTypeConstraint || spec.HasSpecialStruct) {
//.........这里部分代码省略.........
开发者ID:ikvm,项目名称:mono,代码行数:101,代码来源:generic.cs


示例13: TypeParameterExpr

		public TypeParameterExpr (TypeParameter type_parameter, Location loc)
		{
			this.type = type_parameter.Type;
			this.eclass = ExprClass.TypeParameter;
			this.loc = loc;
		}
开发者ID:ikvm,项目名称:mono,代码行数:6,代码来源:generic.cs


示例14: TypeParameterMutator

		public TypeParameterMutator (TypeParameter[] mvar, TypeParameter[] var)
		{
			if (mvar.Length != var.Length)
				throw new ArgumentException ();

			this.mvar = mvar;
			this.var = var;
		}
开发者ID:ikvm,项目名称:mono,代码行数:8,代码来源:generic.cs


示例15: Resolve

		/// <summary>
		///   Resolve the constraints - but only resolve things into Expression's, not
		///   into actual types.
		/// </summary>
		public bool Resolve (MemberCore ec, TypeParameter tp, Report Report)
		{
			if (resolved)
				return true;

			if (ec == null)
				return false;

			iface_constraints = new ArrayList (2);	// TODO: Too expensive allocation
			type_param_constraints = new ArrayList ();

			foreach (object obj in constraints) {
				if (HasConstructorConstraint) {
					Report.Error (401, loc,
						      "The new() constraint must be the last constraint specified");
					return false;
				}

				if (obj is SpecialConstraint) {
					SpecialConstraint sc = (SpecialConstraint) obj;

					if (sc == SpecialConstraint.Constructor) {
						if (!HasValueTypeConstraint) {
							attrs |= GenericParameterAttributes.DefaultConstructorConstraint;
							continue;
						}

						Report.Error (451, loc, "The `new()' constraint " +
							"cannot be used with the `struct' constraint");
						return false;
					}

					if ((num_constraints > 0) || HasReferenceTypeConstraint || HasValueTypeConstraint) {
						Report.Error (449, loc, "The `class' or `struct' " +
							      "constraint must be the first constraint specified");
						return false;
					}

					if (sc == SpecialConstraint.ReferenceType)
						attrs |= GenericParameterAttributes.ReferenceTypeConstraint;
					else
						attrs |= GenericParameterAttributes.NotNullableValueTypeConstraint;
					continue;
				}

				int errors = Report.Errors;
				FullNamedExpression fn = ((Expression) obj).ResolveAsTypeStep (ec, false);

				if (fn == null) {
					if (errors != Report.Errors)
						return false;

					NamespaceEntry.Error_NamespaceNotFound (loc, ((Expression)obj).GetSignatureForError (), Report);
					return false;
				}

				TypeExpr expr;
				GenericTypeExpr cexpr = fn as GenericTypeExpr;
				if (cexpr != null) {
					expr = cexpr.ResolveAsBaseTerminal (ec, false);
				} else
					expr = ((Expression) obj).ResolveAsTypeTerminal (ec, false);

				if ((expr == null) || (expr.Type == null))
					return false;

				if (!ec.IsAccessibleAs (fn.Type)) {
					Report.SymbolRelatedToPreviousError (fn.Type);
					Report.Error (703, loc,
						"Inconsistent accessibility: constraint type `{0}' is less accessible than `{1}'",
						fn.GetSignatureForError (), ec.GetSignatureForError ());
					return false;
				}

				if (TypeManager.IsGenericParameter (expr.Type))
					type_param_constraints.Add (expr);
				else if (expr.IsInterface)
					iface_constraints.Add (expr);
				else if (class_constraint != null || iface_constraints.Count != 0) {
					Report.Error (406, loc,
						"The class type constraint `{0}' must be listed before any other constraints. Consider moving type constraint to the beginning of the constraint list",
						expr.GetSignatureForError ());
					return false;
				} else if (HasReferenceTypeConstraint || HasValueTypeConstraint) {
					Report.Error (450, loc, "`{0}': cannot specify both " +
						      "a constraint class and the `class' " +
						      "or `struct' constraint", expr.GetSignatureForError ());
					return false;
				} else
					class_constraint = expr;


				//
				// Checks whether each generic method parameter constraint type
				// is valid with respect to T
				//
//.........这里部分代码省略.........
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:101,代码来源:generic.cs


示例16: SetParameterInfo

		public virtual void SetParameterInfo (ArrayList constraints_list)
		{
			if (!is_generic) {
				if (constraints_list != null) {
					Report.Error (
						80, Location, "Constraints are not allowed " +
						"on non-generic declarations");
				}

				return;
			}

			TypeParameterName[] names = MemberName.TypeArguments.GetDeclarations ();
			type_params = new TypeParameter [names.Length];

			//
			// Register all the names
			//
			for (int i = 0; i < type_params.Length; i++) {
				TypeParameterName name = names [i];

				Constraints constraints = null;
				if (constraints_list != null) {
					int total = constraints_list.Count;
					for (int ii = 0; ii < total; ++ii) {
						Constraints constraints_at = (Constraints)constraints_list[ii];
						// TODO: it is used by iterators only
						if (constraints_at == null) {
							constraints_list.RemoveAt (ii);
							--total;
							continue;
						}
						if (constraints_at.TypeParameter == name.Name) {
							constraints = constraints_at;
							constraints_list.RemoveAt(ii);
							break;
						}
					}
				}

				type_params [i] = new TypeParameter (
					Parent, this, name.Name, constraints, name.OptAttributes,
					Location);

				AddToContainer (type_params [i], name.Name);
			}

			if (constraints_list != null && constraints_list.Count > 0) {
				foreach (Constraints constraint in constraints_list) {
					Report.Error(699, constraint.Location, "`{0}': A constraint references nonexistent type parameter `{1}'", 
						GetSignatureForError (), constraint.TypeParameter);
				}
			}
		}
开发者ID:lewurm,项目名称:benchmarker,代码行数:54,代码来源:decl.cs


示例17: AddPartialConstraints

        //
        // This is called for each part of a partial generic type definition.
        //
        // If partial type parameters constraints are not null and we don't
        // already have constraints they become our constraints. If we already
        // have constraints, we must check that they're the same.
        //
        public bool AddPartialConstraints(TypeContainer part, TypeParameter tp)
        {
            if (builder == null)
                throw new InvalidOperationException ();

            var new_constraints = tp.constraints;
            if (new_constraints == null)
                return true;

            // TODO: could create spec only
            //tp.Define (null, -1, part.Definition);
            tp.spec.DeclaringType = part.Definition;
            if (!tp.ResolveConstraints (part))
                return false;

            if (constraints != null)
                return spec.HasSameConstraintsDefinition (tp.Type);

            constraints = new_constraints;
            return true;
        }
开发者ID:speier,项目名称:shake,代码行数:28,代码来源:generic.cs


示例18: TypeParameterExpr

		public TypeParameterExpr (TypeParameter type_parameter, Location loc)
		{
			throw new NotImplementedException ();
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:4,代码来源:generic-mcs.cs


示例19: AnonymousMethodStorey

		public AnonymousMethodStorey (Block block, TypeContainer parent, MemberBase host, TypeParameter[] tparams, string name)
			: base (parent, MakeMemberName (host, name, unique_id, tparams, block.StartLocation),
				tparams, Modifiers.SEALED)
		{
			OriginalSourceBlock = block;
			ID = unique_id++;
		}
开发者ID:nzaugg,项目名称:mono,代码行数:7,代码来源:anonymous.cs


示例20: AddPartialConstraints

		//
		// This is called for each part of a partial generic type definition.
		//
		// If partial type parameters constraints are not null and we don't
		// already have constraints they become our constraints. If we already
		// have constraints, we must check that they're the same.
		//
		public bool AddPartialConstraints (TypeContainer part, TypeParameter tp)
		{
			if (builder == null)
				throw new InvalidOperationException ();

			var new_constraints = tp.constraints;
			if (new_constraints == null)
				return true;

			// TODO: could create spec only
			//tp.Define (null, -1, part.Definition);
			tp.spec.DeclaringType = part.Definition;
			if (!tp.ResolveConstraints (part))
				return false;

			if (constraints != null)
				return spec.HasSameConstraintsDefinition (tp.Type);

			// Copy constraint from resolved part to partial container
			spec.SpecialConstraint = tp.spec.SpecialConstraint;
			spec.InterfacesDefined = tp.spec.InterfacesDefined;
			spec.TypeArguments = tp.spec.TypeArguments;
			spec.BaseType = tp.spec.BaseType;
			
			return true;
		}
开发者ID:ikvm,项目名称:mono,代码行数:33,代码来源:generic.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# CSharp.TypeParameterInflator类代码示例发布时间:2022-05-26
下一篇:
C# CSharp.TypeOf类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap