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

C# TypeSystem.ParameterizedType类代码示例

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

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



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

示例1: ImportOpenGenericType

        public void ImportOpenGenericType()
        {
            // class C<T, U> { void M<X>() {} }

            var c = new DefaultUnresolvedTypeDefinition(string.Empty, "C");
            c.TypeParameters.Add(new DefaultUnresolvedTypeParameter(EntityType.TypeDefinition, 0, "T"));
            c.TypeParameters.Add(new DefaultUnresolvedTypeParameter(EntityType.TypeDefinition, 1, "U"));
            var m = new DefaultUnresolvedMethod(c, "M");
            m.TypeParameters.Add(new DefaultUnresolvedTypeParameter(EntityType.Method, 0, "X"));
            c.Members.Add(m);

            var resolvedC1 = TypeSystemHelper.CreateCompilationAndResolve(c);
            var resolvedM1 = resolvedC1.Methods.Single(method => method.Name == "M");

            var resolvedC2 = TypeSystemHelper.CreateCompilationAndResolve(c);
            var resolvedM2 = resolvedC2.Methods.Single(method => method.Name == "M");

            // the types, methods and type parameters differ in the two compilations:
            Assert.AreNotEqual(resolvedC1, resolvedC2);
            Assert.AreNotEqual(resolvedM1, resolvedM2);
            Assert.AreNotEqual(resolvedC1.TypeParameters[1], resolvedC2.TypeParameters[1]);
            Assert.AreNotEqual(resolvedM1.TypeParameters[0], resolvedM2.TypeParameters[0]);

            // C<U, X>
            var pt1 = new ParameterizedType(resolvedC1, new[] { resolvedC1.TypeParameters[1], resolvedM1.TypeParameters[0] });
            var pt2 = (ParameterizedType)resolvedC2.Compilation.Import(pt1);

            // importing resulted in C<U, X> in the new compilation:
            Assert.AreEqual(resolvedC2, pt2.GetDefinition());
            Assert.AreEqual(resolvedC2.TypeParameters[1], pt2.TypeArguments[0]);
            Assert.AreEqual(resolvedM2.TypeParameters[0], pt2.TypeArguments[1]);
        }
开发者ID:riviti,项目名称:NRefactory,代码行数:32,代码来源:TypeParameterTests.cs


示例2: ResolveKnownBaseType

		/// <summary>
		/// Finds IList&lt;T&gt; or IEnumerable&lt;T&gt; base type.
		/// </summary>
		/// <param name="fullNamePrefix">Type code to search for (IList&lt;T&gt; or IEnumerable&lt;T&gt;)</param></param>
		/// <param name="implementation">Found implementation.</param>
		/// <param name="itemType">The only generic argument of <paramref name="implementation"/></param>
		/// <returns>True if found, false otherwise.</returns>
		private static bool ResolveKnownBaseType(this IType type, KnownTypeCode knownTypeCode, out ParameterizedType implementation, out IType itemType)
		{
			if (type == null) throw new ArgumentNullException("type");
			implementation = null;
			itemType = null;
			ParameterizedType impl = 
				type.GetAllBaseTypes().OfType<ParameterizedType>().
				Where(t => t.IsKnownType(knownTypeCode) && t.TypeParameterCount == 1)
				.FirstOrDefault();
			if (impl != null) {
				implementation = impl;
				itemType = impl.GetTypeArgument(0);
				return true;
			}
			return false;
		}
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:23,代码来源:TypeResolver.cs


示例3: EnumerableToArrayInContravariantType

		public void EnumerableToArrayInContravariantType()
		{
			ITypeParameter tp = new DefaultTypeParameter(EntityType.Method, 0, "T");
			IType stringType = KnownTypeReference.String.Resolve(ctx);
			ITypeDefinition enumerableType = ctx.GetTypeDefinition(typeof(IEnumerable<>));
			ITypeDefinition comparerType = ctx.GetTypeDefinition(typeof(IComparer<>));
			
			var comparerOfIEnumerableOfString = new ParameterizedType(comparerType, new [] { new ParameterizedType(enumerableType, new [] { stringType} ) });
			var comparerOfTpArray = new ParameterizedType(comparerType, new [] { new ArrayType(tp) });
			
			bool success;
			Assert.AreEqual(
				new [] { stringType },
				ti.InferTypeArguments(new [] { tp },
				                      new [] { new ResolveResult(comparerOfIEnumerableOfString) },
				                      new [] { comparerOfTpArray },
				                      out success));
			Assert.IsTrue(success);
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:19,代码来源:TypeInferenceTests.cs


示例4: GetGenericNestedTypeOfBoundGenericClass

        public void GetGenericNestedTypeOfBoundGenericClass()
        {
            // class A<X> { class B<Y> { } }
            DefaultUnresolvedTypeDefinition a = new DefaultUnresolvedTypeDefinition(string.Empty, "A");
            a.TypeParameters.Add(new DefaultUnresolvedTypeParameter(SymbolKind.TypeDefinition, 0, "X"));

            DefaultUnresolvedTypeDefinition b = new DefaultUnresolvedTypeDefinition(a, "B");
            b.TypeParameters.Add(a.TypeParameters[0]);
            b.TypeParameters.Add(new DefaultUnresolvedTypeParameter(SymbolKind.TypeDefinition, 1, "Y"));

            a.NestedTypes.Add(b);

            var compilation = TypeSystemHelper.CreateCompilation(a, b);
            ITypeDefinition resolvedA = compilation.MainAssembly.GetTypeDefinition(a.FullTypeName);
            ITypeDefinition resolvedB = compilation.MainAssembly.GetTypeDefinition(b.FullTypeName);

            // A<> gets self-parameterized, B<> stays unbound
            Assert.AreEqual("A`1+B`1[[`0],[]]", resolvedA.GetNestedTypes().Single().ReflectionName);

            ParameterizedType pt = new ParameterizedType(resolvedA, new [] { compilation.FindType(KnownTypeCode.String) });
            Assert.AreEqual("A`1+B`1[[System.String],[]]", pt.GetNestedTypes().Single().ReflectionName);
        }
开发者ID:svermeulen,项目名称:NRefactory,代码行数:22,代码来源:GetMembersTests.cs


示例5: IsGenericInterfaceImplementedByArray

 static bool IsGenericInterfaceImplementedByArray(ParameterizedType rt)
 {
     if (rt == null || rt.TypeParameterCount != 1)
         return false;
     switch (rt.GetDefinition().FullName) {
         case "System.Collections.Generic.IEnumerable":
         case "System.Collections.Generic.ICollection":
         case "System.Collections.Generic.IList":
         case "System.Collections.Generic.IReadOnlyList":
             return true;
         default:
             return false;
     }
 }
开发者ID:svermeulen,项目名称:NRefactory,代码行数:14,代码来源:TypeInference.cs


示例6: ListOfNSSystem

 public void ListOfNSSystem()
 {
     var type = new ParameterizedType(compilation.FindType(typeof(List<>)).GetDefinition(), new[] { systemClass });
     Assert.AreEqual("List<NS.System>", TypeToString(type));
     Assert.AreEqual("List<System>", TypeToString(type, systemClass));
 }
开发者ID:holmak,项目名称:NRefactory,代码行数:6,代码来源:TypeSystemAstBuilderTests.cs


示例7: LookInCurrentUsingScope

 ResolveResult LookInCurrentUsingScope(string identifier, IList<IType> typeArguments, bool isInUsingDeclaration, bool parameterizeResultType)
 {
     int k = typeArguments.Count;
     // look in current namespace definitions
     ResolvedUsingScope currentUsingScope = this.CurrentUsingScope;
     for (ResolvedUsingScope u = currentUsingScope; u != null; u = u.Parent) {
         INamespace n = u.Namespace;
         // first look for a namespace
         if (k == 0 && n != null) {
             INamespace childNamespace = n.GetChildNamespace(identifier);
             if (childNamespace != null) {
                 if (u.HasAlias(identifier))
                     return new AmbiguousTypeResolveResult(new UnknownType(null, identifier));
                 return new NamespaceResolveResult(childNamespace);
             }
         }
         // then look for a type
         if (n != null) {
             ITypeDefinition def = n.GetTypeDefinition(identifier, k);
             if (def != null) {
                 IType result = def;
                 if (parameterizeResultType) {
                     result = new ParameterizedType(def, typeArguments);
                 }
                 if (u.HasAlias(identifier))
                     return new AmbiguousTypeResolveResult(result);
                 else
                     return new TypeResolveResult(result);
             }
         }
         // then look for aliases:
         if (k == 0) {
             if (u.ExternAliases.Contains(identifier)) {
                 return ResolveExternAlias(identifier);
             }
             if (!(isInUsingDeclaration && u == currentUsingScope)) {
                 foreach (var pair in u.UsingAliases) {
                     if (pair.Key == identifier) {
                         return pair.Value;
                     }
                 }
             }
         }
         // finally, look in the imported namespaces:
         if (!(isInUsingDeclaration && u == currentUsingScope)) {
             IType firstResult = null;
             foreach (var importedNamespace in u.Usings) {
                 ITypeDefinition def = importedNamespace.GetTypeDefinition(identifier, k);
                 if (def != null) {
                     if (firstResult == null) {
                         if (parameterizeResultType && k > 0)
                             firstResult = new ParameterizedType(def, typeArguments);
                         else
                             firstResult = def;
                     } else {
                         return new AmbiguousTypeResolveResult(firstResult);
                     }
                 }
             }
             if (firstResult != null)
                 return new TypeResolveResult(firstResult);
         }
         // if we didn't find anything: repeat lookup with parent namespace
     }
     return null;
 }
开发者ID:holmak,项目名称:NRefactory,代码行数:66,代码来源:CSharpResolver.cs


示例8: IEnumerableCovarianceWithDynamic

		public void IEnumerableCovarianceWithDynamic()
		{
			ITypeParameter tp = new DefaultTypeParameter(compilation, SymbolKind.Method, 0, "T");
			var ienumerableOfT = new ParameterizedType(compilation.FindType(typeof(IEnumerable<>)).GetDefinition(), new[] { tp });
			var ienumerableOfString = compilation.FindType(typeof(IEnumerable<string>));
			var ienumerableOfDynamic = compilation.FindType(typeof(IEnumerable<ReflectionHelper.Dynamic>));
			
			// static T M<T>(IEnumerable<T> x, IEnumerable<T> y) {}
			// M(IEnumerable<dynamic>, IEnumerable<string>); -> should infer T=dynamic, no ambiguity
			// See http://blogs.msdn.com/b/cburrows/archive/2010/04/01/errata-dynamic-conversions-and-overload-resolution.aspx
			// for details.
			
			bool success;
			Assert.AreEqual(
				new [] { SpecialType.Dynamic },
				ti.InferTypeArguments(
					new [] { tp },
					new [] { new ResolveResult(ienumerableOfDynamic), new ResolveResult(ienumerableOfString) },
					new [] { ienumerableOfT, ienumerableOfT },
					out success));
			Assert.IsTrue(success);
		}
开发者ID:0xb1dd1e,项目名称:NRefactory,代码行数:22,代码来源:TypeInferenceTests.cs


示例9: VisitParameterizedType

			public override IType VisitParameterizedType(ParameterizedType type)
			{
				IType newType = base.VisitParameterizedType(type);
				if (newType != type && ConstraintsValid) {
					// something was changed, so we need to validate the constraints
					ParameterizedType newParameterizedType = newType as ParameterizedType;
					if (newParameterizedType != null) {
						// C# 4.0 spec: §4.4.4 Satisfying constraints
						var typeParameters = newParameterizedType.GetDefinition().TypeParameters;
						for (int i = 0; i < typeParameters.Count; i++) {
							ITypeParameter tp = typeParameters[i];
							IType typeArg = newParameterizedType.GetTypeArgument(i);
							switch (typeArg.Kind) { // void, null, and pointers cannot be used as type arguments
								case TypeKind.Void:
								case TypeKind.Null:
								case TypeKind.Pointer:
									ConstraintsValid = false;
									break;
							}
							if (tp.HasReferenceTypeConstraint) {
								if (typeArg.IsReferenceType != true)
									ConstraintsValid = false;
							}
							if (tp.HasValueTypeConstraint) {
								if (!NullableType.IsNonNullableValueType(typeArg))
									ConstraintsValid = false;
							}
							if (tp.HasDefaultConstructorConstraint) {
								ITypeDefinition def = typeArg.GetDefinition();
								if (def != null && def.IsAbstract)
									ConstraintsValid = false;
								ConstraintsValid &= typeArg.GetConstructors(
									m => m.Parameters.Count == 0 && m.Accessibility == Accessibility.Public,
									GetMemberOptions.IgnoreInheritedMembers | GetMemberOptions.ReturnMemberDefinitions
								).Any();
							}
							foreach (IType constraintType in tp.DirectBaseTypes) {
								IType c = constraintType.AcceptVisitor(newParameterizedType.GetSubstitution());
								ConstraintsValid &= conversions.IsConstraintConvertible(typeArg, c);
							}
						}
					}
				}
				return newType;
			}
开发者ID:N3X15,项目名称:ILSpy,代码行数:45,代码来源:OverloadResolution.cs


示例10: LookInUsingScopeNamespace

		ResolveResult LookInUsingScopeNamespace(ResolvedUsingScope usingScope, INamespace n, string identifier, IList<IType> typeArguments, bool parameterizeResultType)
		{
			if (n == null)
				return null;
			// first look for a namespace
			int k = typeArguments.Count;
			if (k == 0) {
				INamespace childNamespace = n.GetChildNamespace(identifier);
				if (childNamespace != null) {
					if (usingScope != null && usingScope.HasAlias(identifier))
						return new AmbiguousTypeResolveResult(new UnknownType(null, identifier));
					return new NamespaceResolveResult(childNamespace);
				}
			}
			// then look for a type
			ITypeDefinition def = n.GetTypeDefinition(identifier, k);
			if (def != null) {
				IType result = def;
				if (parameterizeResultType && k > 0) {
					result = new ParameterizedType(def, typeArguments);
				}
				if (usingScope != null && usingScope.HasAlias(identifier))
					return new AmbiguousTypeResolveResult(result);
				else
					return new TypeResolveResult(result);
			}
			return null;
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:28,代码来源:CppResolver.cs


示例11: VisitParameterizedType

 public override IType VisitParameterizedType(ParameterizedType type)
 {
     IType newType = base.VisitParameterizedType(type);
     if (newType != type && ConstraintsValid) {
         // something was changed, so we need to validate the constraints
         ParameterizedType newParameterizedType = newType as ParameterizedType;
         if (newParameterizedType != null) {
             // C# 4.0 spec: §4.4.4 Satisfying constraints
             var typeParameters = newParameterizedType.GetDefinition().TypeParameters;
             for (int i = 0; i < typeParameters.Count; i++) {
                 ITypeParameter tp = typeParameters[i];
                 IType typeArg = newParameterizedType.TypeArguments[i];
                 if (tp.HasReferenceTypeConstraint) {
                     if (typeArg.IsReferenceType != true)
                         ConstraintsValid = false;
                 }
                 if (tp.HasValueTypeConstraint) {
                     if (typeArg.IsReferenceType != false)
                         ConstraintsValid = false;
                     if (NullableType.IsNullable(typeArg))
                         ConstraintsValid = false;
                 }
                 if (tp.HasDefaultConstructorConstraint) {
                     ITypeDefinition def = typeArg.GetDefinition();
                     if (def != null && def.IsAbstract)
                         ConstraintsValid = false;
                     ConstraintsValid &= typeArg.GetConstructors(
                         overloadResolution.context,
                         m => m.Parameters.Count == 0 && m.Accessibility == Accessibility.Public
                     ).Any();
                 }
                 foreach (IType constraintType in tp.Constraints) {
                     IType c = newParameterizedType.SubstituteInType(constraintType);
                     ConstraintsValid &= overloadResolution.IsConstraintConvertible(typeArg, c);
                 }
             }
         }
     }
     return newType;
 }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:40,代码来源:OverloadResolution.cs


示例12: NestedTypeInDerivedClass

		public void NestedTypeInDerivedClass()
		{
			var type1 = new ParameterizedType(nestedClass, new[] { derivedClass.TypeParameters[0], compilation.FindType(KnownTypeCode.String) });
			// short form "Nested<string>" cannot be used as it would refer to "Base<S>.Nested<string>"
			Assert.AreEqual("Base<T>.Nested<string>", TypeToString(type1, derivedClass));
			
			var type2 = new ParameterizedType(nestedClass, new[] { derivedClass.TypeParameters[1], compilation.FindType(KnownTypeCode.String) });
			Assert.AreEqual("Nested<string>", TypeToString(type2, derivedClass));
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:9,代码来源:TypeSystemAstBuilderTests.cs


示例13: SiblingClass

		public void SiblingClass()
		{
			var type = new ParameterizedType(siblingClass, new[] { baseClass.TypeParameters[0] });
			Assert.AreEqual("Sibling", TypeToString(type, nestedClass));
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:5,代码来源:TypeSystemAstBuilderTests.cs


示例14: NestedType

		public void NestedType()
		{
			var type = new ParameterizedType(nestedClass, new[] { compilation.FindType(KnownTypeCode.Char), compilation.FindType(KnownTypeCode.String) });
			Assert.AreEqual("Base<char>.Nested<string>", TypeToString(type));
			// The short form "Nested<string>" refers to "Base<T>.Nested<string>",
			// so we need to use the long form to specify that T=char.
			Assert.AreEqual("Base<char>.Nested<string>", TypeToString(type, baseClass));
			Assert.AreEqual("Base<char>.Nested<string>", TypeToString(type, nestedClass));
			Assert.AreEqual("Base<char>.Nested<string>", TypeToString(type, derivedClass));
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:10,代码来源:TypeSystemAstBuilderTests.cs


示例15: AliasedTypeWrongTypeArgument

		public void AliasedTypeWrongTypeArgument()
		{
			var type = new ParameterizedType(compilation.FindType(typeof(List<>)).GetDefinition(), new[] { compilation.FindType(KnownTypeCode.Int32) });
			Assert.AreEqual("List<int>", TypeToString(type, systemClass));
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:5,代码来源:TypeSystemAstBuilderTests.cs


示例16: IsIEnumerableCollectionOrList

		static bool IsIEnumerableCollectionOrList(ParameterizedType rt)
		{
			if (rt == null || rt.TypeParameterCount != 1)
				return false;
			switch (rt.GetDefinition().FullName) {
				case "System.Collections.Generic.IList":
				case "System.Collections.Generic.ICollection":
				case "System.Collections.Generic.IEnumerable":
					return true;
				default:
					return false;
			}
		}
开发者ID:nylen,项目名称:SharpDevelop,代码行数:13,代码来源:TypeInference.cs


示例17: FindTypesInBounds

        IList<IType> FindTypesInBounds(IList<IType> lowerBounds, IList<IType> upperBounds)
        {
            // If there's only a single type; return that single type.
            // If both inputs are empty, return the empty list.
            if (lowerBounds.Count == 0 && upperBounds.Count <= 1)
                return upperBounds;
            if (upperBounds.Count == 0 && lowerBounds.Count <= 1)
                return lowerBounds;
            if (nestingLevel > maxNestingLevel)
                return EmptyList<IType>.Instance;

            // Finds a type X so that "LB <: X <: UB"
            Log.WriteCollection("FindTypesInBound, LowerBounds=", lowerBounds);
            Log.WriteCollection("FindTypesInBound, UpperBounds=", upperBounds);

            // First try the Fixing algorithm from the C# spec (§7.5.2.11)
            List<IType> candidateTypes = lowerBounds.Union(upperBounds)
                .Where(c => lowerBounds.All(b => conversions.ImplicitConversion(b, c).IsValid))
                .Where(c => upperBounds.All(b => conversions.ImplicitConversion(c, b).IsValid))
                .ToList(); // evaluate the query only once

            Log.WriteCollection("FindTypesInBound, Candidates=", candidateTypes);

            // According to the C# specification, we need to pick the most specific
            // of the candidate types. (the type which has conversions to all others)
            // However, csc actually seems to choose the least specific.
            candidateTypes = candidateTypes.Where(
                c => candidateTypes.All(o => conversions.ImplicitConversion(o, c).IsValid)
            ).ToList();

            // If the specified algorithm produces a single candidate, we return
            // that candidate.
            // We also return the whole candidate list if we're not using the improved
            // algorithm.
            if (candidateTypes.Count == 1 || !(algorithm == TypeInferenceAlgorithm.Improved || algorithm == TypeInferenceAlgorithm.ImprovedReturnAllResults))
            {
                return candidateTypes;
            }
            candidateTypes.Clear();

            // Now try the improved algorithm
            Log.Indent();
            List<ITypeDefinition> candidateTypeDefinitions;
            if (lowerBounds.Count > 0) {
                // Find candidates by using the lower bounds:
                var hashSet = new HashSet<ITypeDefinition>(lowerBounds[0].GetAllBaseTypeDefinitions());
                for (int i = 1; i < lowerBounds.Count; i++) {
                    hashSet.IntersectWith(lowerBounds[i].GetAllBaseTypeDefinitions());
                }
                candidateTypeDefinitions = hashSet.ToList();
            } else {
                // Find candidates by looking at all classes in the project:
                candidateTypeDefinitions = compilation.GetAllTypeDefinitions().ToList();
            }

            // Now filter out candidates that violate the upper bounds:
            foreach (IType ub in upperBounds) {
                ITypeDefinition ubDef = ub.GetDefinition();
                if (ubDef != null) {
                    candidateTypeDefinitions.RemoveAll(c => !c.IsDerivedFrom(ubDef));
                }
            }

            foreach (ITypeDefinition candidateDef in candidateTypeDefinitions) {
                // determine the type parameters for the candidate:
                IType candidate;
                if (candidateDef.TypeParameterCount == 0) {
                    candidate = candidateDef;
                } else {
                    Log.WriteLine("Inferring arguments for candidate type definition: " + candidateDef);
                    bool success;
                    IType[] result = InferTypeArgumentsFromBounds(
                        candidateDef.TypeParameters,
                        new ParameterizedType(candidateDef, candidateDef.TypeParameters),
                        lowerBounds, upperBounds,
                        out success);
                    if (success) {
                        candidate = new ParameterizedType(candidateDef, result);
                    } else {
                        Log.WriteLine("Inference failed; ignoring candidate");
                        continue;
                    }
                }
                Log.WriteLine("Candidate type: " + candidate);

                if (upperBounds.Count == 0) {
                    // if there were only lower bounds, we aim for the most specific candidate:

                    // if this candidate isn't made redundant by an existing, more specific candidate:
                    if (!candidateTypes.Any(c => c.GetDefinition().IsDerivedFrom(candidateDef))) {
                        // remove all existing candidates made redundant by this candidate:
                        candidateTypes.RemoveAll(c => candidateDef.IsDerivedFrom(c.GetDefinition()));
                        // add new candidate
                        candidateTypes.Add(candidate);
                    }
                } else {
                    // if there were upper bounds, we aim for the least specific candidate:

                    // if this candidate isn't made redundant by an existing, less specific candidate:
                    if (!candidateTypes.Any(c => candidateDef.IsDerivedFrom(c.GetDefinition()))) {
//.........这里部分代码省略.........
开发者ID:svermeulen,项目名称:NRefactory,代码行数:101,代码来源:TypeInference.cs


示例18: VisitParameterizedType

		public virtual IType VisitParameterizedType(ParameterizedType type)
		{
			return type.VisitChildren(this);
		}
开发者ID:adisik,项目名称:simple-assembly-explorer,代码行数:4,代码来源:TypeVisitor.cs


示例19: LookInCurrentUsingScope

		ResolveResult LookInCurrentUsingScope(string identifier, IList<IType> typeArguments, bool isInUsingDeclaration, bool parameterizeResultType)
		{
			// look in current namespace definitions
			ResolvedUsingScope currentUsingScope = this.CurrentUsingScope;
			for (ResolvedUsingScope u = currentUsingScope; u != null; u = u.Parent) {
				var resultInNamespace = LookInUsingScopeNamespace(u, u.Namespace, identifier, typeArguments, parameterizeResultType);
				if (resultInNamespace != null)
					return resultInNamespace;
				// then look for aliases:
				if (typeArguments.Count == 0) {
					if (u.ExternAliases.Contains(identifier)) {
						return ResolveExternAlias(identifier);
					}
					if (!(isInUsingDeclaration && u == currentUsingScope)) {
						foreach (var pair in u.UsingAliases) {
							if (pair.Key == identifier) {
								return pair.Value;
							}
						}
					}
				}
				// finally, look in the imported namespaces:
				if (!(isInUsingDeclaration && u == currentUsingScope)) {
					IType firstResult = null;
					foreach (var importedNamespace in u.Usings) {
						ITypeDefinition def = importedNamespace.GetTypeDefinition(identifier, typeArguments.Count);
						if (def != null) {
							IType resultType;
							if (parameterizeResultType && typeArguments.Count > 0)
								resultType = new ParameterizedType(def, typeArguments);
							else
								resultType = def;
							
							if (firstResult == null || !TopLevelTypeDefinitionIsAccessible(firstResult.GetDefinition())) {
								firstResult = resultType;
							} else if (TopLevelTypeDefinitionIsAccessible(def)) {
								return new AmbiguousTypeResolveResult(firstResult);
							}
						}
					}
					if (firstResult != null)
						return new TypeResolveResult(firstResult);
				}
				// if we didn't find anything: repeat lookup with parent namespace
			}
			return null;
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:47,代码来源:CppResolver.cs


示例20: CreateTypeResolveResult

		ResolveResult CreateTypeResolveResult(IType returnedType, bool isAmbiguous, IList<IType> typeArguments)
		{
			if (typeArguments.Count > 0) {
				// parameterize the type if necessary
				ITypeDefinition returnedTypeDef = returnedType as ITypeDefinition;
				if (returnedTypeDef != null)
					returnedType = new ParameterizedType(returnedTypeDef, typeArguments);
			}
			if (isAmbiguous)
				return new AmbiguousTypeResolveResult(returnedType);
			else
				return new TypeResolveResult(returnedType);
		}
开发者ID:constructor-igor,项目名称:cudafy,代码行数:13,代码来源:MemberLookup.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Design.FakePackage类代码示例发布时间:2022-05-26
下一篇:
C# Semantics.ResolveResult类代码示例发布时间: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