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


C# TypeReference.Resolve方法代码示例

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


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

示例1: Initialize

 internal static void Initialize(ModuleDefinition moduleDefinition)
 {
     ModuleDefinition = moduleDefinition;
     typeType = ModuleDefinition.Import(typeof(Type));
     taskType = ModuleDefinition.Import(typeof(Task));
     getTypeFromRuntimeHandleMethod = ModuleDefinition.Import(typeType.Resolve().Methods.Single(x => x.Name == "GetTypeFromHandle"));
     typeGetMethod = ModuleDefinition.Import(typeType.Resolve().Methods.Single(x => x.Name == "GetMethod" && x.Parameters.Count == 5));
     taskTType = ModuleDefinition.Import(typeof(Task<>));
     taskFromResult = ModuleDefinition.Import(taskType.Resolve().Methods.Single(x => x.Name == "FromResult"));
 }
开发者ID:kswoll,项目名称:sexy-proxy,代码行数:10,代码来源:CecilExtensions.cs

示例2: Process

        /// <summary>
        /// Transform open generic types to closed instantiation using context information.
        /// As an example, if B{T} inherits from A{T}, running it with B{C} as context and A{B.T} as type, ti will return A{C}.
        /// </summary>
        public static TypeReference Process(TypeReference context, TypeReference type)
        {
            if (type == null)
                return null;

            var genericInstanceTypeContext = context as GenericInstanceType;
            if (genericInstanceTypeContext == null)
                return type;

            if (genericInstanceTypeContext.ContainsGenericParameter())
                return type;

            // Build dictionary that will map generic type to their real implementation type
            var resolvedType = context.Resolve();
            var genericTypeMapping = new Dictionary<TypeReference, TypeReference>();
            for (int i = 0; i < resolvedType.GenericParameters.Count; ++i)
            {
                var genericParameter = context.GetElementType().Resolve().GenericParameters[i];
                genericTypeMapping.Add(genericParameter, genericInstanceTypeContext.GenericArguments[i]);
            }

            var visitor = new ResolveGenericsVisitor(genericTypeMapping);
            var result = visitor.VisitDynamic(type);

            // Make sure type is closed now
            if (result.ContainsGenericParameter())
                throw new InvalidOperationException("Unsupported generic resolution.");

            return result;
        }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:34,代码来源:ResolveGenericsVisitor.cs

示例3: IsAssignableFrom

        public static bool IsAssignableFrom(this TypeReference baseType, TypeReference type, Action<string> logger = null)
        {
            if (type.IsGenericParameter)
                return baseType.CompareTo(type);

            return baseType.Resolve().IsAssignableFrom(type.Resolve(), logger);
        }
开发者ID:kswoll,项目名称:sexy-proxy,代码行数:7,代码来源:CecilExtensions.cs

示例4: IsValueTypeBlittable

        /// <summary>
        /// Determines whether the specified value type is blittable.
        /// </summary>
        /// <param name="typeReference">The type reference.</param>
        /// <param name="marshalInfo">The marshal information.</param>
        /// <returns></returns>
        private static bool IsValueTypeBlittable(TypeReference typeReference, MarshalInfo marshalInfo)
        {
            bool isBlittable;
            if (blittableValueTypes.TryGetValue(typeReference, out isBlittable))
                return isBlittable;

            var typeDefinition = typeReference.Resolve();

            // Only value types are blittable
            if (typeDefinition.IsValueType)
            {
                isBlittable = true;

                if (!typeDefinition.IsEnum && !typeDefinition.IsExplicitLayout)
                {
                    // Check if every field is blittable
                    foreach (var field in typeDefinition.Fields)
                    {
                        if (field.IsStatic)
                            continue;

                        var fieldType = ResolveGenericsVisitor.Process(typeReference, field.FieldType);
                        if (!IsBlittable(fieldType, field.HasMarshalInfo ? field.MarshalInfo : null))
                        {
                            isBlittable = false;
                            break;
                        }
                    }
                }
            }

            blittableValueTypes[typeReference] = isBlittable;

            return isBlittable;
        }
开发者ID:RainsSoft,项目名称:SharpLang,代码行数:41,代码来源:Marshaller.cs

示例5: AddRole

 private void AddRole(TypeReference role)
 {
     var memberReader = new MemberReaderVisitor();
       role.Resolve().Accept(memberReader);
       var roleMembers = memberReader.Members.Select(member => MakeRoleMember(role, member));
       AddRoleMembers(role, roleMembers);
 }
开发者ID:cessationoftime,项目名称:nroles,代码行数:7,代码来源:ConflictDetector.cs

示例6: AspectWeaver

        public AspectWeaver(TypeReference aspectType)
        {
            _type = aspectType.Resolve();

            _onExecute = _type.Methods.FirstOrDefault(m => m.Name == "OnExecute");
            _onComplete = _type.Methods.FirstOrDefault(m => m.Name == "OnComplete");
            _onException = _type.Methods.FirstOrDefault(m => m.Name == "OnException");

            _requiresAspectInstance = (_onExecute != null && !_onExecute.IsStatic)
                || (_onComplete != null && !_onComplete.IsStatic)
                || (_onException != null && !_onException.IsStatic);

            if (_requiresAspectInstance)
            {
                _aspectCtor = _type.Methods.FirstOrDefault(m => m.IsConstructor && !m.HasParameters);

                if (_aspectCtor == null)
                {
                    throw new Exception(String.Format("Parameterless constructor required for {0}.", _type.Name));
                }
            }

            _requiresCorrelationVariable = _onExecute != null
                && _onExecute.IsStatic
                && !_onExecute.ReturnType.TypeMatches(typeof(void));

            if (_requiresCorrelationVariable)
            {
                _correlationType = _onExecute.ReturnType;
            }

            _aspectInstanceVariableName = String.Format("aspectInstance_{0}", _type.Name);
            _correlationVariableName = String.Format("aspectCorrelation_{0}", _type.Name);
            _exceptionVariableName = String.Format("aspectException_{0}", _type.Name);
        }
开发者ID:scmccart,项目名称:Reweave,代码行数:35,代码来源:AspectWeaver.cs

示例7: ResolveType

        private TypeDefinition ResolveType(TypeReference aRef)
        {
            var xDef = aRef as TypeDefinition;
            if (xDef != null)
            {
                return xDef;
            }
#if DEBUG
            var xArray = aRef as ArrayType;
            if (xArray != null)
            {
                throw new NotSupportedException("Reader.ResolveType doesnt support ArrayTypes");
            }
            var xPointer = aRef as PointerType;
            if (xPointer != null)
            {
                throw new NotSupportedException("Reader.ResolveType doesnt support PointerTypes");
            }
            //var xReference = aRef as ReferenceType;
            //if (xReference != null)
            //{
            //    throw new NotSupportedException("Reader.ResolveType doesnt support ReferenceTypes");
            //}
#endif
            return aRef.Resolve();
        }
开发者ID:Orvid,项目名称:Cosmos,代码行数:26,代码来源:Reader.MonoHelpers.cs

示例8: Get

 public static string Get(TypeReference type, Dictionary<FieldReference, string> fieldNames) {
     if (!type.IsValueType || type.IsNullable()) {
         return "null";
     }
     if (type.IsPrimitive) {
         var mdt = type.MetadataType;
         switch (mdt) {
         case MetadataType.Boolean: return "false";
         case MetadataType.IntPtr:
         case MetadataType.UIntPtr:
         case MetadataType.Int16:
         case MetadataType.Int32:
         case MetadataType.UInt16:
         case MetadataType.UInt32:
         case MetadataType.Byte:
         case MetadataType.SByte:
         case MetadataType.Single:
         case MetadataType.Double:
         case MetadataType.Char: return "0";
         case MetadataType.Int64:
         case MetadataType.UInt64: return "[0, 0]";
         default: throw new NotImplementedException("Cannot handle: " + mdt);
         }
     }
     if (type.Resolve().IsEnum) {
         return "0";
     }
     var fields = type.EnumResolvedFields().Where(x => !x.Resolve().IsStatic).ToArray();
     var defaultValue = "{" + string.Join(",",
         fields.Where(x => fieldNames.ContainsKey(x))
         .Select(x => fieldNames[x] + ":" + Get(x.FieldType, fieldNames))) + "}";
     return defaultValue;
 }
开发者ID:chrisdunelm,项目名称:DotNetWebToolkit,代码行数:33,代码来源:DefaultValuer.cs

示例9: Visit

        public override TypeReference Visit(TypeReference type)
        {
            var typeDefinition = type.Resolve();
            if (typeDefinition.IsValueType && !type.IsValueType)
                type.IsValueType = typeDefinition.IsValueType;

            return base.Visit(type);
        }
开发者ID:cg123,项目名称:xenko,代码行数:8,代码来源:FixupValueTypeVisitor.cs

示例10: IsPublic

		internal static bool IsPublic (TypeReference typeref)
		{
			if (typeref == null)
				throw new ArgumentNullException ("typeref");

			TypeDefinition td = typeref.Resolve ();
			return td.IsPublic;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:8,代码来源:Util.cs

示例11: AddBaseTypes

		internal static void AddBaseTypes(SharpTreeNodeCollection children, TypeReference type)
		{
			var def = type.Resolve();
			if (def.BaseType != null)
				children.Add(new BaseTypesEntryNode(ResolveWithTypes(def.BaseType, type), false));
			foreach (TypeReference i in def.Interfaces)
				children.Add(new BaseTypesEntryNode(ResolveWithTypes(i, type), true));
		}
开发者ID:arturek,项目名称:ILSpy,代码行数:8,代码来源:BaseTypesTreeNode.cs

示例12: IsEnumOrStruct

 /// <summary>
 /// Is the given type an enum or struct?
 /// </summary>
 private static bool IsEnumOrStruct(TypeReference type)
 {
     if (type.IsPrimitive)
         return false;
     if (!type.IsDefinitionOrReference())
         return false;
     var typeDef = type.Resolve();
     return (typeDef != null) && (typeDef.IsEnum || typeDef.IsValueType);
 }
开发者ID:rfcclub,项目名称:dot42,代码行数:12,代码来源:EnsureClassCtors.cs

示例13: BaseTypesEntryNode

		public BaseTypesEntryNode(TypeReference tr, bool isInterface)
		{
			if (tr == null)
				throw new ArgumentNullException("tr");
			this.tr = tr;
			this.def = tr.Resolve();
			this.isInterface = isInterface;
			this.LazyLoading = true;
		}
开发者ID:95ulisse,项目名称:ILEdit,代码行数:9,代码来源:BaseTypesEntryNode.cs

示例14: MemberResolver

 public MemberResolver(TypeReference target, ModuleDefinition targetModule = null)
 {
     if (target == null) throw new ArgumentNullException("target");
       Target = target;
       Module = targetModule ?? Target.Module;
       Source = Target.Resolve();
       TargetWithArguments = Target as GenericInstanceType;
       _map = new GenericParametersMap(Source, TargetWithArguments);
 }
开发者ID:cessationoftime,项目名称:nroles,代码行数:9,代码来源:MemberResolver.cs

示例15: InterceptMethod

 private void InterceptMethod(ILProcessor processor, TypeReference typeReference, Instruction instruction, string name)
 {
     var typeDefinition = typeReference.Resolve();
     var attributeConstructor = typeDefinition.Methods.First(x => x.Name == ".ctor");
     var attributeMethod = typeDefinition.Methods.First(x => x.Name == name);
     processor.InsertBefore(instruction, processor.Create(OpCodes.Newobj, attributeConstructor));
     processor.InsertBefore(instruction, processor.Create(OpCodes.Call, _getCurrentMethod));
     processor.InsertBefore(instruction, processor.Create(OpCodes.Call, attributeMethod));
 }
开发者ID:AlbertoMonteiro,项目名称:MethodInterceptorAopWithFody,代码行数:9,代码来源:ModuleWeaver.cs


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