TypeReference ImportTypeSpecification(Type type, ImportGenericContext context, ISRImportMapper mapper) { if (type.IsByRef) return new ByReferenceType(ImportType(type.GetElementType(), context, mapper)); if (type.IsPointer) return new PointerType(ImportType(type.GetElementType(), context, mapper)); if (type.IsArray) return new ArrayType(ImportType(type.GetElementType(), context, mapper), type.GetArrayRank()); if (type.IsGenericType) return ImportGenericInstance(type, context, mapper); if (type.IsGenericParameter) return ImportGenericParameter(type, context, mapper); throw new NotSupportedException (type.FullName); }
internal TypeReference ImportType(Type type, ImportGenericContext context, ISRImportMapper mapper) { return ImportType(type, context, ImportGenericKind.Open, mapper); }
internal TypeReference ImportType(Type type, ImportGenericContext context, ImportGenericKind import_kind, ISRImportMapper mapper) { if (IsTypeSpecification(type) || ImportOpenGenericType(type, import_kind)) return ImportTypeSpecification(type, context, mapper); var reference = new TypeReference ( string.Empty, type.Name, module, ImportScope(mapper.MapAssembly(type.Assembly)), type.IsValueType); reference.etype = ImportElementType(type); if (IsNestedType (type)) reference.DeclaringType = ImportType(type.DeclaringType, context, import_kind, mapper); else reference.Namespace = type.Namespace ?? string.Empty; if (type.IsGenericType) ImportGenericParameters(reference, type.GetGenericArguments()); return reference; }
internal MethodReference ImportMethod(SR.MethodBase method, ImportGenericContext context, ImportGenericKind import_kind, ISRImportMapper mapper) { if (IsMethodSpecification(method) || ImportOpenGenericMethod(method, import_kind)) return ImportMethodSpecification(method, context, mapper); var declaring_type = ImportType(method.DeclaringType, context, mapper); 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, mapper), }; 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, mapper) : ImportType(typeof(void), default(ImportGenericContext), mapper); 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, mapper))); reference.DeclaringType = declaring_type; return reference; } finally { context.Pop (); } }
MethodReference ImportMethodSpecification(SR.MethodBase method, ImportGenericContext context, ISRImportMapper mapper) { var method_info = method as SR.MethodInfo; if (method_info == null) throw new InvalidOperationException (); var element_method = ImportMethod(method_info.GetGenericMethodDefinition(), context, ImportGenericKind.Definition, mapper); var instance = new GenericInstanceMethod (element_method); var arguments = method.GetGenericArguments (); var instance_arguments = instance.GenericArguments; context.Push (element_method); try { for (int i = 0; i < arguments.Length; i++) instance_arguments.Add(ImportType(arguments[i], context, mapper)); return instance; } finally { context.Pop (); } }
TypeReference ImportGenericParameter(Type type, ImportGenericContext context, ISRImportMapper mapper) { if (context.IsEmpty) throw new InvalidOperationException (); if (type.DeclaringMethod != null) return context.MethodParameter(type.DeclaringMethod, type.GenericParameterPosition, mapper); if (type.DeclaringType != null) return context.TypeParameter(type.DeclaringType, type.GenericParameterPosition, mapper); throw new InvalidOperationException(); }
TypeReference ImportGenericInstance(Type type, ImportGenericContext context, ISRImportMapper mapper) { var element_type = ImportType(type.GetGenericTypeDefinition(), context, ImportGenericKind.Definition, mapper); var instance = new GenericInstanceType (element_type); var arguments = type.GetGenericArguments (); var instance_arguments = instance.GenericArguments; context.Push (element_type); try { for (int i = 0; i < arguments.Length; i++) instance_arguments.Add(ImportType(arguments[i], context, mapper)); return instance; } finally { context.Pop (); } }
internal FieldReference ImportField(SR.FieldInfo field, ImportGenericContext context, ISRImportMapper mapper) { var declaring_type = ImportType(field.DeclaringType, context, mapper); if (IsGenericInstance (field.DeclaringType)) field = ResolveFieldDefinition(field); context.Push (declaring_type); try { return new FieldReference { Name = field.Name, DeclaringType = declaring_type, FieldType = ImportType(field.FieldType, context, mapper), }; } finally { context.Pop (); } }
public TypeReference TypeParameter(Type type, int position, ISRImportMapper typeMapper) { for (int i = stack.Count - 1; i >= 0; i--) { var candidate = GenericTypeFor(stack[i]); if (candidate.FullName != NormalizedFullName(typeMapper.MapType(type))) continue; return candidate.GenericParameters[position]; } throw new InvalidOperationException(); }
public TypeReference MethodParameter(SR.MethodBase method, int position, ISRImportMapper mapper) { for (int i = stack.Count - 1; i >= 0; i--) { var candidate = stack[i] as MethodReference; if (candidate == null) continue; if (method.Name != mapper.MapMethod(candidate).Name) continue; return candidate.GenericParameters[position]; } throw new InvalidOperationException(); }