コード例 #1
0
        public TypeReference ImportType(Type type, ImportGenericContext context, ImportGenericKind import_kind)
        {
            if (IsTypeSpecification(type) || ImportOpenGenericType(type, import_kind))
            {
                return(this.ImportTypeSpecification(type, context));
            }
            TypeReference provider = new TypeReference(string.Empty, type.Name, this.module, this.ImportScope(type.Assembly), type.IsValueType)
            {
                etype = ImportElementType(type)
            };

            if (IsNestedType(type))
            {
                provider.DeclaringType = this.ImportType(type.DeclaringType, context, import_kind);
            }
            else
            {
                provider.Namespace = type.Namespace ?? string.Empty;
            }
            if (type.IsGenericType)
            {
                ImportGenericParameters(provider, type.GetGenericArguments());
            }
            return(provider);
        }
コード例 #2
0
        TypeReference ImportType(Type type, ImportGenericContext context, ImportGenericKind import_kind)
        {
            if (IsTypeSpecification(type) || ImportOpenGenericType(type, import_kind))
            {
                return(ImportTypeSpecification(type, context));
            }

            var reference = new TypeReference(
                string.Empty,
                type.Name,
                module,
                ImportScope(type.Assembly),
                type.IsValueType);

            reference.etype = ImportElementType(type);

            if (IsNestedType(type))
            {
                reference.DeclaringType = ImportType(type.DeclaringType, context, import_kind);
            }
            else
            {
                reference.Namespace = type.Namespace ?? string.Empty;
            }

            if (type.IsGenericType)
            {
                ImportGenericParameters(reference, type.GetGenericArguments());
            }

            return(reference);
        }
コード例 #3
0
 private static bool ImportOpenGenericMethod(MethodBase method, ImportGenericKind import_kind)
 {
     if (method.IsGenericMethod && method.IsGenericMethodDefinition)
     {
         return(import_kind == ImportGenericKind.Open);
     }
     return(false);
 }
コード例 #4
0
 private static bool ImportOpenGenericType(Type type, ImportGenericKind import_kind)
 {
     if (type.IsGenericType() && type.IsGenericTypeDefinition())
     {
         return(import_kind == ImportGenericKind.Open);
     }
     return(false);
 }
コード例 #5
0
 private TypeReference ImportType(Type type, ImportGenericContext context, ImportGenericKind import_kind)
 {
     if (!IsTypeSpecification(type) && !ImportOpenGenericType(type, import_kind))
     {
         TypeReference typeReference = new TypeReference(string.Empty, type.Name, module, ImportScope(type), type.IsValueType());
         typeReference.etype = ImportElementType(type);
         if (IsNestedType(type))
         {
             typeReference.DeclaringType = ImportType(type.DeclaringType, context, import_kind);
         }
         else
         {
             typeReference.Namespace = (type.Namespace ?? string.Empty);
         }
         if (type.IsGenericType())
         {
             ImportGenericParameters(typeReference, type.GetGenericArguments());
         }
         return(typeReference);
     }
     return(ImportTypeSpecification(type, context));
 }
コード例 #6
0
        public TypeReference ImportType(Type type, ImportGenericContext context, ImportGenericKind import_kind)
        {
            if (IsTypeSpecification(type) || ImportOpenGenericType(type, import_kind))
            {
                return(ImportTypeSpecification(type, context));
            }

            var reference = new TypeReference(
                string.Empty,
                type.Name,
                module,
                ImportScope(type.Assembly),
                type.IsValueType);

            ElementType elementType = ImportElementType(type);

            if (elementType != ElementType.None)
            {
                // TODO: Use some IL generated setter instead of SetValue (which is slow)
                etypeField.SetValue(reference, (byte)elementType);
            }

            if (IsNestedType(type))
            {
                reference.DeclaringType = ImportType(type.DeclaringType, context, import_kind);
            }
            else
            {
                reference.Namespace = type.Namespace ?? string.Empty;
            }

            if (type.IsGenericType)
            {
                ImportGenericParameters(reference, type.GetGenericArguments());
            }

            return(reference);
        }
コード例 #7
0
        public TypeReference ImportType(Type type, ImportGenericContext context, ImportGenericKind import_kind)
        {
            if (IsTypeSpecification(type) || ImportOpenGenericType(type, import_kind))
            {
                return(ImportTypeSpecification(type, context));
            }

            var reference = new TypeReference(
                string.Empty,
                type.Name,
                module,
                ImportScope(type.Assembly),
                type.IsValueType);

            ElementType elementType = ImportElementType(type);

            if (elementType != ElementType.None)
            {
                typeof(TypeReference).GetField("etype", SR.BindingFlags.NonPublic | SR.BindingFlags.Instance).SetValue(reference, elementType);
            }

            if (IsNestedType(type))
            {
                reference.DeclaringType = ImportType(type.DeclaringType, context, import_kind);
            }
            else
            {
                reference.Namespace = type.Namespace ?? string.Empty;
            }

            if (type.IsGenericType)
            {
                ImportGenericParameters(reference, type.GetGenericArguments());
            }

            return(reference);
        }
コード例 #8
0
ファイル: Import.cs プロジェクト: jeroldhaas/ContinuousTests
		public TypeReference ImportType (Type type, IGenericContext context, ImportGenericKind import_kind)
		{
			if (IsTypeSpecification (type) || ImportOpenGenericType (type, import_kind))
				return ImportTypeSpecification (type, context);

			var reference = new TypeReference (
				string.Empty,
				type.Name,
				module,
				ImportScope (type.Assembly),
				type.IsValueType);

			reference.etype = ImportElementType (type);

			if (IsNestedType (type))
				reference.DeclaringType = ImportType (type.DeclaringType, context, import_kind);
			else
				reference.Namespace = type.Namespace;

			if (type.IsGenericType)
				ImportGenericParameters (reference, type.GetGenericArguments ());

			return reference;
		}
コード例 #9
0
        MethodReference ImportMethod(SR.MethodBase method, ImportGenericContext context, ImportGenericKind import_kind)
        {
            if (IsMethodSpecification(method) || ImportOpenGenericMethod(method, import_kind))
            {
                return(ImportMethodSpecification(method, context));
            }

            var declaring_type = ImportType(method.DeclaringType, context);

            if (IsGenericInstance(method.DeclaringType))
            {
                method = method.Module.ResolveMethod(method.MetadataToken);
            }

            var reference = new MethodReference {
                Name          = method.Name,
                HasThis       = HasCallingConvention(method, SR.CallingConventions.HasThis),
                ExplicitThis  = HasCallingConvention(method, SR.CallingConventions.ExplicitThis),
                DeclaringType = ImportType(method.DeclaringType, context, ImportGenericKind.Definition),
            };

            if (HasCallingConvention(method, SR.CallingConventions.VarArgs))
            {
                reference.CallingConvention &= MethodCallingConvention.VarArg;
            }

            if (method.IsGenericMethod)
            {
                ImportGenericParameters(reference, method.GetGenericArguments());
            }

            context.Push(reference);
            try {
                var method_info = method as SR.MethodInfo;
                reference.ReturnType = method_info != null
                                        ? ImportType(method_info.ReturnType, context)
                                        : ImportType(typeof(void), default(ImportGenericContext));

                var parameters           = method.GetParameters();
                var reference_parameters = reference.Parameters;

                for (int i = 0; i < parameters.Length; i++)
                {
                    reference_parameters.Add(
                        new ParameterDefinition(ImportType(parameters [i].ParameterType, context)));
                }

                reference.DeclaringType = declaring_type;

                return(reference);
            } finally {
                context.Pop();
            }
        }
コード例 #10
0
 static bool ImportOpenGenericMethod(SR.MethodBase method, ImportGenericKind import_kind)
 {
     return(method.IsGenericMethod && method.IsGenericMethodDefinition && import_kind == ImportGenericKind.Open);
 }
コード例 #11
0
 static bool ImportOpenGenericType(Type type, ImportGenericKind import_kind)
 {
     return(type.IsGenericType && type.IsGenericTypeDefinition && import_kind == ImportGenericKind.Open);
 }
コード例 #12
0
ファイル: Import.cs プロジェクト: jeroldhaas/ContinuousTests
		public MethodReference ImportMethod (SR.MethodBase method, IGenericContext context, ImportGenericKind import_kind)
		{
			if (IsMethodSpecification (method) || ImportOpenGenericMethod (method, import_kind))
				return ImportMethodSpecification (method, context);

			var declaring_type = ImportType (method.DeclaringType, context);

			if (IsGenericInstance (method.DeclaringType))
				method = method.Module.ResolveMethod (method.MetadataToken);

			var reference = new MethodReference {
				Name = method.Name,
				HasThis = HasCallingConvention (method, SR.CallingConventions.HasThis),
				ExplicitThis = HasCallingConvention (method, SR.CallingConventions.ExplicitThis),
				DeclaringType = ImportType (method.DeclaringType, context, ImportGenericKind.Definition),
			};

			if (HasCallingConvention (method, SR.CallingConventions.VarArgs))
				reference.CallingConvention &= MethodCallingConvention.VarArg;

			if (method.IsGenericMethod)
				ImportGenericParameters (reference, method.GetGenericArguments ());

			var method_info = method as SR.MethodInfo;
			reference.ReturnType = method_info != null
				? ImportType (method_info.ReturnType, context ?? reference)
				: ImportType (typeof (void), null);

			var parameters = method.GetParameters ();
			var reference_parameters = reference.Parameters;

			for (int i = 0; i < parameters.Length; i++)
				reference_parameters.Add (
					new ParameterDefinition (ImportType (parameters [i].ParameterType, context ?? reference)));

			reference.DeclaringType = declaring_type;

			return reference;
		}
コード例 #13
0
        public MethodReference ImportMethod(MethodBase method, ImportGenericContext context, ImportGenericKind import_kind)
        {
            MethodReference reference4;

            if (IsMethodSpecification(method) || ImportOpenGenericMethod(method, import_kind))
            {
                return(this.ImportMethodSpecification(method, context));
            }
            TypeReference reference = this.ImportType(method.DeclaringType, context);

            if (IsGenericInstance(method.DeclaringType))
            {
                method = method.Module.ResolveMethod(method.MetadataToken);
            }
            MethodReference provider = new MethodReference {
                Name          = method.Name,
                HasThis       = HasCallingConvention(method, CallingConventions.HasThis),
                ExplicitThis  = HasCallingConvention(method, CallingConventions.ExplicitThis),
                DeclaringType = this.ImportType(method.DeclaringType, context, ImportGenericKind.Definition)
            };

            if (HasCallingConvention(method, CallingConventions.VarArgs))
            {
                provider.CallingConvention = (MethodCallingConvention)((byte)(provider.CallingConvention & MethodCallingConvention.VarArg));
            }
            if (method.IsGenericMethod)
            {
                ImportGenericParameters(provider, method.GetGenericArguments());
            }
            context.Push(provider);
            try
            {
                TypeReference reference1;
                MethodInfo    info = method as MethodInfo;
                if (info != null)
                {
                    reference1 = this.ImportType(info.ReturnType, context);
                }
                else
                {
                    ImportGenericContext context2 = new ImportGenericContext();
                    reference1 = this.ImportType(typeof(void), context2);
                }
                provider.ReturnType = reference1;
                ParameterInfo[] parameters = method.GetParameters();
                Collection <ParameterDefinition> collection = provider.Parameters;
                int index = 0;
                while (true)
                {
                    if (index >= parameters.Length)
                    {
                        provider.DeclaringType = reference;
                        reference4             = provider;
                        break;
                    }
                    collection.Add(new ParameterDefinition(this.ImportType(parameters[index].ParameterType, context)));
                    index++;
                }
            }
            finally
            {
                context.Pop();
            }
            return(reference4);
        }
コード例 #14
0
 private MethodReference ImportMethod(MethodBase method, ImportGenericContext context, ImportGenericKind import_kind)
 {
     if (!IsMethodSpecification(method) && !ImportOpenGenericMethod(method, import_kind))
     {
         TypeReference declaringType = ImportType(method.DeclaringType, context);
         if (IsGenericInstance(method.DeclaringType))
         {
             method = ResolveMethodDefinition(method);
         }
         MethodReference methodReference = new MethodReference
         {
             Name          = method.Name,
             HasThis       = HasCallingConvention(method, CallingConventions.HasThis),
             ExplicitThis  = HasCallingConvention(method, CallingConventions.ExplicitThis),
             DeclaringType = ImportType(method.DeclaringType, context, ImportGenericKind.Definition)
         };
         if (HasCallingConvention(method, CallingConventions.VarArgs))
         {
             methodReference.CallingConvention &= MethodCallingConvention.VarArg;
         }
         if (method.IsGenericMethod)
         {
             ImportGenericParameters(methodReference, method.GetGenericArguments());
         }
         context.Push(methodReference);
         try
         {
             MethodInfo methodInfo = method as MethodInfo;
             methodReference.ReturnType = ((methodInfo != (MethodInfo)null) ? ImportType(methodInfo.ReturnType, context) : ImportType(typeof(void), default(ImportGenericContext)));
             ParameterInfo[] parameters = method.GetParameters();
             Collection <ParameterDefinition> parameters2 = methodReference.Parameters;
             for (int i = 0; i < parameters.Length; i++)
             {
                 parameters2.Add(new ParameterDefinition(ImportType(parameters[i].ParameterType, context)));
             }
             methodReference.DeclaringType = declaringType;
             return(methodReference);
         }
         finally
         {
             context.Pop();
         }
     }
     return(ImportMethodSpecification(method, context));
 }
コード例 #15
0
        public MethodReference ImportMethod(MethodBase method, ImportGenericContext context, ImportGenericKind import_kind)
        {
            MethodReference methodReference;

            if (MetadataImporter.IsMethodSpecification(method) || MetadataImporter.ImportOpenGenericMethod(method, import_kind))
            {
                return(this.ImportMethodSpecification(method, context));
            }
            TypeReference typeReference = this.ImportType(method.DeclaringType, context);

            if (MetadataImporter.IsGenericInstance(method.DeclaringType))
            {
                method = method.Module.ResolveMethod(method.MetadataToken);
            }
            MethodReference methodReference1 = new MethodReference()
            {
                Name          = method.Name,
                HasThis       = MetadataImporter.HasCallingConvention(method, CallingConventions.HasThis),
                ExplicitThis  = MetadataImporter.HasCallingConvention(method, CallingConventions.ExplicitThis),
                DeclaringType = this.ImportType(method.DeclaringType, context, ImportGenericKind.Definition)
            };

            if (MetadataImporter.HasCallingConvention(method, CallingConventions.VarArgs))
            {
                MethodReference callingConvention = methodReference1;
                callingConvention.CallingConvention = callingConvention.CallingConvention & MethodCallingConvention.VarArg;
            }
            if (method.IsGenericMethod)
            {
                MetadataImporter.ImportGenericParameters(methodReference1, method.GetGenericArguments());
            }
            context.Push(methodReference1);
            try
            {
                MethodInfo methodInfo = method as MethodInfo;
                methodReference1.ReturnType = (methodInfo != null ? this.ImportType(methodInfo.ReturnType, context) : this.ImportType(typeof(void), new ImportGenericContext()));
                ParameterInfo[] parameters = method.GetParameters();
                Collection <ParameterDefinition> parameterDefinitions = methodReference1.Parameters;
                for (int i = 0; i < (int)parameters.Length; i++)
                {
                    parameterDefinitions.Add(new ParameterDefinition(this.ImportType(parameters[i].ParameterType, context)));
                }
                methodReference1.DeclaringType = typeReference;
                methodReference = methodReference1;
            }
            finally
            {
                context.Pop();
            }
            return(methodReference);
        }
コード例 #16
0
ファイル: Import.cs プロジェクト: jeroldhaas/ContinuousTests
		static bool ImportOpenGenericType (Type type, ImportGenericKind import_kind)
		{
			return type.IsGenericType && type.IsGenericTypeDefinition && import_kind == ImportGenericKind.Open;
		}
コード例 #17
0
ファイル: Import.cs プロジェクト: jeroldhaas/ContinuousTests
		static bool ImportOpenGenericMethod (SR.MethodBase method, ImportGenericKind import_kind)
		{
			return method.IsGenericMethod && method.IsGenericMethodDefinition && import_kind == ImportGenericKind.Open;
		}
コード例 #18
0
 private static bool ImportOpenGenericMethod(MethodBase method, ImportGenericKind import_kind) =>
 (method.IsGenericMethod && (method.IsGenericMethodDefinition && (import_kind == ImportGenericKind.Open)));
コード例 #19
0
 private static bool ImportOpenGenericType(Type type, ImportGenericKind import_kind) =>
 (type.IsGenericType && (type.IsGenericTypeDefinition && (import_kind == ImportGenericKind.Open)));
コード例 #20
0
ファイル: Import.cs プロジェクト: terurou/cecil
 static bool ImportOpenGenericType(Type type, ImportGenericKind import_kind)
 {
     #if !NETFX_CORE
     return type.IsGenericType && type.IsGenericTypeDefinition && import_kind == ImportGenericKind.Open;
     #else
     var typeInfo = type.GetTypeInfo();
     return typeInfo.IsGenericType && typeInfo.IsGenericTypeDefinition && import_kind == ImportGenericKind.Open;
     #endif
 }