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

C# ITypeResolveContext类代码示例

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

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



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


示例16: ResolveConstructor

		public IMethod ResolveConstructor(ITypeResolveContext context)
		{
			IType[] parameterTypes = null;
			if (constructorParameterTypes != null && constructorParameterTypes.Length > 0) {
				parameterTypes = new IType[constructorParameterTypes.Length];
				for (int i = 0; i < parameterTypes.Length; i++) {
					parameterTypes[i] = constructorParameterTypes[i].Resolve(context);
				}
			}
			IMethod bestMatch = null;
			foreach (IMethod ctor in attributeType.Resolve(context).GetConstructors(context)) {
				if (ctor.IsStatic)
					continue;
				if (parameterTypes == null) {
					if (ctor.Parameters.Count == 0)
						return ctor;
				} else if (ctor.Parameters.Count == parameterTypes.Length) {
					bestMatch = ctor;
					bool ok = true;
					for (int i = 0; i < parameterTypes.Length; i++) {
						if (ctor.Parameters[i].Type != parameterTypes[i]) {
							ok = false;
							break;
						}
					}
					if (ok)
						return ctor;
				}
			}
			return bestMatch;
		}
开发者ID:constructor-igor,项目名称:cudafy,代码行数:31,代码来源:DefaultAttribute.cs


示例17: TypeSystemAstBuilder

		/// <summary>
		/// Creates a new TypeSystemAstBuilder.
		/// </summary>
		/// <param name="context">
		/// Context used for resolving types.
		/// </param>
		public TypeSystemAstBuilder(ITypeResolveContext context)
		{
			if (context == null)
				throw new ArgumentNullException("context");
			this.context = context;
			InitProperties();
		}
开发者ID:jiguixin,项目名称:ILSpy,代码行数:13,代码来源:TypeSystemAstBuilder.cs


示例18: GetPositionalArguments

		public IList<IConstantValue> GetPositionalArguments(ITypeResolveContext context)
		{
			if (namedCtorArguments == null || namedCtorArguments.Count == 0) {
				// no namedCtorArguments: just return the positionalArguments
				if (positionalArguments != null)
					return new ReadOnlyCollection<IConstantValue>(positionalArguments);
				else
					return EmptyList<IConstantValue>.Instance;
			}
			// we do have namedCtorArguments, which need to be re-ordered and appended to the positional arguments
			List<IConstantValue> result = new List<IConstantValue>(this.positionalArguments);
			IMethod method = ResolveConstructor(context);
			if (method != null) {
				for (int i = result.Count; i < method.Parameters.Count; i++) {
					IParameter p = method.Parameters[i];
					bool found = false;
					foreach (var pair in namedCtorArguments) {
						if (pair.Key == p.Name) {
							result.Add(pair.Value);
							found = true;
						}
					}
					if (!found) {
						// add the parameter's default value:
						result.Add(p.DefaultValue ?? new SimpleConstantValue(p.Type, CSharpResolver.GetDefaultValue(p.Type.Resolve(context))));
					}
				}
			}
			return result.AsReadOnly();
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:30,代码来源:CSharpAttribute.cs


示例19: GetNonInterfaceBaseTypes

		/// <summary>
		/// Gets the non-interface base types.
		/// </summary>
		/// <remarks>
		/// When <paramref name="type"/> is an interface, this method will also return base interfaces.
		/// 
		/// The output is ordered so that base types occur in before derived types.
		/// </remarks>
		public static IEnumerable<IType> GetNonInterfaceBaseTypes(this IType type, ITypeResolveContext context)
		{
			BaseTypeCollector collector = new BaseTypeCollector(context);
			collector.SkipImplementedInterfaces = true;
			collector.CollectBaseTypes(type);
			return collector;
		}
开发者ID:jiguixin,项目名称:ILSpy,代码行数:15,代码来源:ExtensionMethods.cs


示例20: Combine

		/// <summary>
		/// Creates a <see cref="CompositeTypeResolveContext"/> that combines the given resolve contexts.
		/// If one of the input parameters is null, the other input parameter is returned directly.
		/// If both input parameters are null, the function returns null.
		/// </summary>
		public static ITypeResolveContext Combine(ITypeResolveContext a, ITypeResolveContext b)
		{
			if (a == null)
				return b;
			if (b == null)
				return a;
			return new CompositeTypeResolveContext(new [] { a, b });
		}
开发者ID:yayanyang,项目名称:monodevelop,代码行数:13,代码来源:CompositeTypeResolveContext.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# ITypeResolver类代码示例发布时间:2022-05-24
下一篇:
C# ITypeReference类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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