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


C# ITypeResolveContext类代码示例

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


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

示例1: IsReferenceType

		public bool? IsReferenceType(ITypeResolveContext context)
		{
			switch (flags.Data & (FlagReferenceTypeConstraint | FlagValueTypeConstraint)) {
				case FlagReferenceTypeConstraint:
					return true;
				case FlagValueTypeConstraint:
					return false;
			}
			// protect against cyclic dependencies between type parameters
			using (var busyLock = BusyManager.Enter(this)) {
				if (busyLock.Success) {
					foreach (ITypeReference constraintRef in this.Constraints) {
						IType constraint = constraintRef.Resolve(context);
						ITypeDefinition constraintDef = constraint.GetDefinition();
						// While interfaces are reference types, an interface constraint does not
						// force the type parameter to be a reference type; so we need to explicitly look for classes here.
						if (constraintDef != null && constraintDef.ClassType == ClassType.Class)
							return true;
						if (constraint is ITypeParameter) {
							bool? isReferenceType = constraint.IsReferenceType(context);
							if (isReferenceType.HasValue)
								return isReferenceType.Value;
						}
					}
				}
			}
			return null;
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:28,代码来源:DefaultTypeParameter.cs

示例2: Resolve

		public IType Resolve(ITypeResolveContext context)
		{
			string[] parts = typeName.Split('.');
			var assemblies = new [] { context.CurrentAssembly }.Concat(context.Compilation.Assemblies);
			for (int i = parts.Length - 1; i >= 0; i--) {
				string ns = string.Join(".", parts, 0, i);
				string name = parts[i];
				int topLevelTPC = (i == parts.Length - 1 ? typeParameterCount : 0);
				foreach (var asm in assemblies) {
					if (asm == null)
						continue;
					ITypeDefinition typeDef = asm.GetTypeDefinition(new TopLevelTypeName(ns, name, topLevelTPC));
					for (int j = i + 1; j < parts.Length && typeDef != null; j++) {
						int tpc = (j == parts.Length - 1 ? typeParameterCount : 0);
						typeDef = typeDef.NestedTypes.FirstOrDefault(n => n.Name == parts[j] && n.TypeParameterCount == tpc);
					}
					if (typeDef != null)
						return typeDef;
				}
			}
			int idx = typeName.LastIndexOf('.');
			if (idx < 0)
				return new UnknownType("", typeName, typeParameterCount);
			// give back a guessed namespace/type name
			return  new UnknownType(typeName.Substring(0, idx), typeName.Substring(idx + 1), typeParameterCount);
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:26,代码来源:GetPotentiallyNestedClassTypeReference.cs

示例3: TypeInference

		public TypeInference(ITypeResolveContext context, Conversions conversions = null)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			this.context = context;
			this.conversions = conversions ?? Conversions.Get(context);
		}
开发者ID:jiguixin,项目名称:ILSpy,代码行数:7,代码来源:TypeInference.cs

示例4: GetAllBaseTypes

 /// <summary>
 /// Gets all base types.
 /// </summary>
 /// <remarks>This is the reflexive and transitive closure of <see cref="IType.GetBaseTypes"/>.
 /// Note that this method does not return all supertypes - doing so is impossible due to contravariance
 /// (and undesirable for covariance as the list could become very large).
 /// </remarks>
 public static IEnumerable<IType> GetAllBaseTypes(this IType type, ITypeResolveContext context)
 {
     List<IType> output = new List<IType>();
     Stack<ITypeDefinition> activeTypeDefinitions = new Stack<ITypeDefinition>();
     CollectAllBaseTypes(type, context, activeTypeDefinitions, output);
     return output;
 }
开发者ID:richardschneider,项目名称:ILSpy,代码行数:14,代码来源:ExtensionMethods.cs

示例5: ResolveConstructor

		public IMethod ResolveConstructor(ITypeResolveContext context)
		{
			CSharpResolver r = new CSharpResolver(context);
			IType type = attributeType.Resolve(context);
			int totalArgumentCount = 0;
			if (positionalArguments != null)
				totalArgumentCount += positionalArguments.Count;
			if (namedCtorArguments != null)
				totalArgumentCount += namedCtorArguments.Count;
			ResolveResult[] arguments = new ResolveResult[totalArgumentCount];
			string[] argumentNames = new string[totalArgumentCount];
			int i = 0;
			if (positionalArguments != null) {
				while (i < positionalArguments.Count) {
					IConstantValue cv = positionalArguments[i];
					arguments[i] = cv.Resolve(context);
					i++;
				}
			}
			if (namedCtorArguments != null) {
				foreach (var pair in namedCtorArguments) {
					argumentNames[i] = pair.Key;
					arguments[i] = pair.Value.Resolve(context);
					i++;
				}
			}
			MemberResolveResult mrr = r.ResolveObjectCreation(type, arguments, argumentNames) as MemberResolveResult;
			return mrr != null ? mrr.Member as IMethod : null;
		}
开发者ID:jiguixin,项目名称:ILSpy,代码行数:29,代码来源:CSharpAttribute.cs

示例6: Resolve

			public IAssembly Resolve(ITypeResolveContext context)
			{
				IAssembly asm = context.CurrentAssembly;
				if (asm == null)
					throw new ArgumentException("A reference to the current assembly cannot be resolved in the compilation's global type resolve context.");
				return asm;
			}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:7,代码来源:DefaultAssemblyReference.cs

示例7: Resolve

 public IAssembly Resolve(ITypeResolveContext context)
 {
     var project = _solution.Projects.FirstOrDefault(p => p.ProjectId == _projectGuid);
     if (project != null)
         return project.ProjectContent.Resolve(context);
     return null;
 }
开发者ID:dyxu,项目名称:vimrc,代码行数:7,代码来源:ProjectReference.cs

示例8: CecilResolvedAttribute

		public CecilResolvedAttribute(ITypeResolveContext context, UnresolvedAttributeBlob unresolved)
		{
			this.context = context;
			this.blob = unresolved.blob;
			this.ctorParameterTypes = unresolved.ctorParameterTypes;
			this.attributeType = unresolved.attributeType.Resolve(context);
		}
开发者ID:0xd4d,项目名称:NRefactory,代码行数:7,代码来源:ResolvedAttributeBlob.cs

示例9: Resolve

 public IAssembly Resolve(ITypeResolveContext context)
 {
     var project = _solution.Projects.FirstOrDefault(p => string.Equals(p.Title, _projectTitle, StringComparison.OrdinalIgnoreCase));
     if (project != null) 
         return project.ProjectContent.Resolve(context);
     return null;
 }
开发者ID:dykim07,项目名称:vim-ide,代码行数:7,代码来源:ProjectReference.cs

示例10: GetValue

		public object GetValue(ITypeResolveContext context)
		{
			if (value is ITypeReference)
				return ((ITypeReference)value).Resolve(context);
			else
				return value;
		}
开发者ID:JustasB,项目名称:cudafy,代码行数:7,代码来源:SimpleConstantValue.cs

示例11: CachedResult

		/*
		sealed class CachedResult
		{
			public readonly CacheManager CacheManager;
			public readonly IType Result;
			
			public CachedResult(CacheManager cacheManager, IType result)
			{
				this.CacheManager = cacheManager;
				this.Result = result;
			}
		}
		 */
		
		public IType Resolve(ITypeResolveContext context)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			
			/*  TODO PERF: caching disabled until we measure how much of an advantage it is
			 * (and whether other approaches like caching only the last N resolve calls in a thread-static cache would work better)
			 * Maybe even make a distinction between the really common type references (e.g. primitiveTypeReferences) and
			 * normal GetClassTypeReferences?
			CacheManager cacheManager = context.CacheManager;
			if (cacheManager != null) {
				CachedResult result = this.v_cachedResult;
				if (result != null && result.CacheManager == cacheManager)
					return result.Result;
				IType newResult = DoResolve(context);
				this.v_cachedResult = new CachedResult(cacheManager, newResult);
				cacheManager.Disposed += delegate { v_cachedResult = null; }; // maybe optimize this to use interface call instead of delegate?
				return newResult;
			} else {
				return DoResolve(context);
			}
			
		}
		
		IType DoResolve(ITypeResolveContext context)
		{
			 */
			return context.GetClass(nameSpace, name, typeParameterCount, StringComparer.Ordinal) ?? SharedTypes.UnknownType;
		}
开发者ID:constructor-igor,项目名称:cudafy,代码行数:43,代码来源:GetClassTypeReference.cs

示例12: ResolveType

        IType ITypeReference.Resolve(ITypeResolveContext context)
        {
            // Strictly speaking, we might have to resolve the type in a nested compilation, similar
            // to what we're doing with ConstantExpression.
            // However, in almost all cases this will work correctly - if the resulting type is only available in the
            // nested compilation and not in this, we wouldn't be able to map it anyways.
            var ctx = context as CSharpTypeResolveContext;
            if (ctx == null) {
                ctx = new CSharpTypeResolveContext(context.CurrentAssembly ?? context.Compilation.MainAssembly, null, context.CurrentTypeDefinition, context.CurrentMember);
            }
            return ResolveType(new CSharpResolver(ctx));

            // A potential issue might be this scenario:

            // Assembly 1:
            //  class A { public class Nested {} }

            // Assembly 2: (references asm 1)
            //  class B : A {}

            // Assembly 3: (references asm 1 and 2)
            //  class C { public B.Nested Field; }

            // Assembly 4: (references asm 1 and 3, but not 2):
            //  uses C.Field;

            // Here we would not be able to resolve 'B.Nested' in the compilation of assembly 4, as type B is missing there.
        }
开发者ID:riviti,项目名称:NRefactory,代码行数:28,代码来源:TypeOrNamespaceReference.cs

示例13: Resolve

		public IMember Resolve(ITypeResolveContext context)
		{
			IType type = typeReference.Resolve(context);
			IEnumerable<IMember> members;
			if (entityType == EntityType.Method) {
				members = type.GetMethods(
					m => m.Name == name && m.EntityType == EntityType.Method && m.TypeParameters.Count == typeParameterCount,
					GetMemberOptions.IgnoreInheritedMembers);
			} else {
				members = type.GetMembers(
					m => m.Name == name && m.EntityType == entityType,
					GetMemberOptions.IgnoreInheritedMembers);
			}
			var resolvedParameterTypes = parameterTypes.Resolve(context);
			foreach (IMember member in members) {
				IParameterizedMember parameterizedMember = member as IParameterizedMember;
				if (parameterTypes.Count == 0) {
					if (parameterizedMember == null || parameterizedMember.Parameters.Count == 0)
						return member;
				} else if (parameterTypes.Count == parameterizedMember.Parameters.Count) {
					bool signatureMatches = true;
					for (int i = 0; i < parameterTypes.Count; i++) {
						IType type1 = ParameterListComparer.Instance.NormalizeMethodTypeParameters(resolvedParameterTypes[i]);
						IType type2 = ParameterListComparer.Instance.NormalizeMethodTypeParameters(parameterizedMember.Parameters[i].Type);
						if (!type1.Equals(type2)) {
							signatureMatches = false;
							break;
						}
					}
					if (signatureMatches)
						return member;
				}
			}
			return null;
		}
开发者ID:KAW0,项目名称:Alter-Native,代码行数:35,代码来源:DefaultMemberReference.cs

示例14: GetNamedArguments

		public IList<KeyValuePair<string, IConstantValue>> GetNamedArguments(ITypeResolveContext context)
		{
			if (namedArguments != null)
				return new ReadOnlyCollection<KeyValuePair<string, IConstantValue>>(namedArguments);
			else
				return EmptyList<KeyValuePair<string, IConstantValue>>.Instance;
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:7,代码来源:CSharpAttribute.cs

示例15: Resolve

		ISymbol ISymbolReference.Resolve(ITypeResolveContext context)
		{
			var type = Resolve(context);
			if (type is ITypeDefinition)
				return (ISymbol)type;
			return null;
		}
开发者ID:sphynx79,项目名称:dotfiles,代码行数:7,代码来源:NestedTypeReference.cs


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