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


C# TypeNode.GetTemplateInstance方法代码示例

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


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

示例1: VisitTypeReference


//.........这里部分代码省略.........
          if (type.Template != null)
          {
            Debug.Assert(TypeNode.IsCompleteTemplate(type.Template));
            // map consolidated arguments
            bool mustSpecializeFurther = false;
            TypeNodeList targs = type.ConsolidatedTemplateArguments;
            int numArgs = targs == null ? 0 : targs.Count;
            if (targs != null)
            {
              targs = targs.Clone();
              for (int i = 0; i < numArgs; i++)
              {
                TypeNode targ = targs[i];
                targs[i] = this.VisitTypeReference(targ);
                if (targ != targs[i]) { mustSpecializeFurther = true; }
              }
            }
            if (targs == null || !mustSpecializeFurther) return type;
            TypeNode t = type.Template.GetGenericTemplateInstance(this.TargetModule, targs);
            return t;
          }
          return type;
#if OLD
          TypeNode declaringType = this.VisitTypeReference(type.DeclaringType);
          if (declaringType != null){
            Identifier tname = type.Name;
            if (type.Template != null && type.IsGeneric) tname = type.Template.Name;
            TypeNode nt = declaringType.GetNestedType(tname);
            if (nt != null){
              TypeNodeList arguments = type.TemplateArguments;
              type = nt;
              if (TargetPlatform.UseGenerics) {
                if (arguments != null && arguments.Count > 0 && nt.ConsolidatedTemplateParameters != null && nt.ConsolidatedTemplateParameters.Count > 0)
                  type = nt.GetTemplateInstance(this.TargetModule, this.CurrentType, declaringType, arguments);
              }
            }
          }
          if (type.Template != null && (type.ConsolidatedTemplateParameters == null || type.ConsolidatedTemplateParameters.Count == 0)){
            if (!type.IsNotFullySpecialized && !type.IsNormalized) return type;
            //Type is a template instance, but some of its arguments were themselves parameters.
            //See if any of these parameters are to be specialized by this specializer.
            bool mustSpecializeFurther = false;
            TypeNodeList targs = type.TemplateArguments;
            int numArgs = targs == null ? 0 : targs.Count;
            if (targs != null) {
              targs = targs.Clone();
              for (int i = 0; i < numArgs; i++) {
                TypeNode targ = targs[i];
                ITypeParameter tparg = targ as ITypeParameter;
                if (tparg != null) {
                  for (int j = 0, np = pars == null ? 0 : pars.Count, m = args == null ? 0 : args.Count; j < np && j < m; j++) {
                    //^ assert pars != null && args != null;
                    if (TargetPlatform.UseGenerics) {
                      ITypeParameter par = pars[j] as ITypeParameter;
                      if (par == null) continue;
                      if (tparg == par || (tparg.ParameterListIndex == par.ParameterListIndex && tparg.DeclaringMember == par.DeclaringMember)) {
                        targ = this.args[j]; break;
                      }
                    }
                    else {
                      if (targ == pars[j]) { targ = this.args[j]; break; }
                    }
                  }
                } else {
                  if (targ != type)
                    targ = this.VisitTypeReference(targ);
开发者ID:asvishnyakov,项目名称:CodeContracts,代码行数:67,代码来源:Specializer.cs

示例2: GetDummyInstance

 public virtual TypeNode GetDummyInstance(TypeNode t){
   if (t == null){Debug.Assert(false); return null;}
   if (this.currentTypeInstance != null){
     TypeNode nt = this.GetTypeView(this.currentTypeInstance).GetNestedType(t.Name);
     if (nt == null){Debug.Assert(false); return null;}
     if (nt.TemplateParameters == null || nt.TemplateParameters.Count == 0) return nt;
     t = nt;
   }
   return t.GetTemplateInstance(this.currentModule, null, t.DeclaringType, t.TemplateParameters);
 }
开发者ID:dbremner,项目名称:specsharp,代码行数:10,代码来源:Resolver.cs

示例3: PTypeRef

	void PTypeRef(out TypeNode tn) {
		Module assem = null;
		string ns, tname, nestedname;
		ArrayList/*<string>*/ typeNames;
		TypeNodeList templateArgs = null;
		
		if (la.kind == 28) {
			Assembly(out assem);
		}
		QualName(out ns, out tname);
		NestedTypeName(out typeNames, out nestedname);
		if (la.kind == 31) {
			Get();
			TypeNode arg; 
			PType(out arg);
			templateArgs = new TypeNodeList(); templateArgs.Add(arg); 
			while (la.kind == 23) {
				Get();
				PType(out arg);
				templateArgs.Add(arg); 
			}
			Expect(32);
		}
		if ( assem == null ){
		 assem = currentAssembly;
		}
		#if !WHIDBEY
		if (templateArgs != null){
		 /* then need to create the pseudo-generic name */
		 string pseudoGenericName = tname;
		 /*pseudoGenericName += SystemTypes.GenericTypeNamesMangleChar;*/
		 /*pseudoGenericName += templateArgs.Count.ToString();*/
		 pseudoGenericName += "<";
		 for (int i = 0, n = templateArgs.Count; i < n; i++){
		   if (i > 0)
		     pseudoGenericName += ",";
		   pseudoGenericName += templateArgs[i].FullName;
		 }
		 pseudoGenericName += ">";
		 tname = pseudoGenericName;
		}
		#endif
		tn = assem.GetType(Identifier.For(ns),Identifier.For(tname));
		if (tn == null) {
		 this.errors.SemErr(t.filename, t.line, t.col,
		               String.Format("could not resolve namespace {0}, type {1}", ns, tname));
		 throw new Exception("cannot continue"); //Errors.Exception("cannot continue");
		}
		// now do nested types
		for (int i=0; i<typeNames.Count; i++){
		 tn = tn.GetNestedType(Identifier.For((string)typeNames[i]));
		}
		if (tn == null) {
		 this.errors.SemErr(t.filename, t.line, t.col,
		               String.Format("could not resolve namespace {0} type {1} nesting {2}", ns, tname, nestedname));
		 throw new Exception("cannot continue"); //Errors.Exception("cannot continue");
		}
		#if WHIDBEY
		/* Pre-Whidbey, templateArgs are used to construct a pseudo-generic name */
		if (templateArgs != null)
		{
		 tn = tn.GetTemplateInstance(assem, null, null, templateArgs);
		}
		#endif
		
	}
开发者ID:dbremner,项目名称:specsharp,代码行数:66,代码来源:DeserializerParser.cs

示例4: GetDummyInstance

 public virtual TypeNode GetDummyInstance(TypeNode t){
   if (t == null || t.ConsolidatedTemplateParameters == null || t.ConsolidatedTemplateParameters.Count == 0) return t;
   if (t.DeclaringType != null){
     TypeNode dt = this.GetDummyInstance(t.DeclaringType);
     if (dt != null){
       t = this.GetTypeView(dt).GetNestedType(t.Name);
       if (t == null || t.TemplateParameters == null || t.TemplateParameters.Count == 0) return t;
     }
   }
   t = t.GetTemplateInstance(this.currentType, t.TemplateParameters);
   this.AddTemplateInstanceToList(t);
   return t;
 }
开发者ID:tapicer,项目名称:resource-contracts-.net,代码行数:13,代码来源:Looker.cs

示例5: ThisExpression

        public This ThisExpression(TypeNode type)
        {
            var result = new This();
            result.Type =
                type.IsGeneric && type.TemplateParameters != null ?
                    type.GetTemplateInstance(type, type.TemplateParameters.ToArray()) :
                    type;

            return result;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:10,代码来源:Rewriter.cs

示例6: FirstOrderTypeOfExpression

 public Expression FirstOrderTypeOfExpression(TypeNode hkType)
 {
     var classTypeParameters = default(Seq<TypeNode>);
     ExplodeTypeAbstraction(hkType, out classTypeParameters);
     if (classTypeParameters == null || classTypeParameters.Count == 0)
         return TypeOfExpression(hkType);
     else
     {
         var types = new TypeNode[classTypeParameters.Count];
         classTypeParameters.CopyTo(types, 0);
         var type = hkType.GetTemplateInstance(hkType, types);
         return TypeOfExpression(type);
     }
 }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:14,代码来源:Rewriter.cs


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