MethodReference ImportMethodSpecification(SR.MethodBase method, ImportGenericContext context) { var method_info = method as SR.MethodInfo; if (method_info == null) { throw new InvalidOperationException(); } var element_method = ImportMethod(method_info.GetGenericMethodDefinition(), context, ImportGenericKind.Definition); 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)); } return(instance); } finally { context.Pop(); } }
public 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(); } }
public FieldReference ImportField(FieldReference field, ImportGenericContext context) { var declaring_type = ImportType(field.DeclaringType, context); context.Push(declaring_type); try { return(new FieldReference { Name = field.Name, DeclaringType = declaring_type, FieldType = ImportType(field.FieldType, context), }); } finally { context.Pop(); } }
public MethodReference ImportMethod(MethodReference method, ImportGenericContext context) { if (method.IsGenericInstance) { return(ImportMethodSpecification(method, context)); } var declaring_type = ImportType(method.DeclaringType, context); var reference = new MethodReference { Name = method.Name, HasThis = method.HasThis, ExplicitThis = method.ExplicitThis, DeclaringType = declaring_type, CallingConvention = method.CallingConvention, }; if (method.HasGenericParameters) { ImportGenericParameters(reference, method); } context.Push(reference); try { reference.ReturnType = ImportType(method.ReturnType, context); if (!method.HasParameters) { return(reference); } var reference_parameters = reference.Parameters; var parameters = method.Parameters; for (int i = 0; i < parameters.Count; i++) { reference_parameters.Add( new ParameterDefinition(ImportType(parameters [i].ParameterType, context))); } return(reference); } finally { context.Pop(); } }
TypeReference ImportGenericInstance(Type type, ImportGenericContext context) { var element_type = ImportType(type.GetGenericTypeDefinition(), context, ImportGenericKind.Definition); 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)); } return(instance); } finally { context.Pop(); } }
public FieldReference ImportField(SR.FieldInfo field, ImportGenericContext context) { var declaring_type = ImportType(field.DeclaringType, context); 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), }); } finally { context.Pop(); } }
public MethodReference ImportMethod (MethodReference method, ImportGenericContext context) { if (method.IsGenericInstance) return ImportMethodSpecification (method, context); var declaring_type = ImportType (method.DeclaringType, context); var reference = new MethodReference { Name = method.Name, HasThis = method.HasThis, ExplicitThis = method.ExplicitThis, DeclaringType = declaring_type, CallingConvention = method.CallingConvention, }; if (method.HasGenericParameters) ImportGenericParameters (reference, method); context.Push (reference); try { reference.ReturnType = ImportType (method.ReturnType, context); if (!method.HasParameters) return reference; var reference_parameters = reference.Parameters; var parameters = method.Parameters; for (int i = 0; i < parameters.Count; i++) reference_parameters.Add ( new ParameterDefinition (ImportType (parameters [i].ParameterType, context))); return reference; } finally { context.Pop(); } }
public FieldReference ImportField (FieldReference field, ImportGenericContext context) { var declaring_type = ImportType (field.DeclaringType, context); context.Push (declaring_type); try { return new FieldReference { Name = field.Name, DeclaringType = declaring_type, FieldType = ImportType (field.FieldType, context), }; } finally { context.Pop (); } }
MethodReference ImportMethodSpecification (SR.MethodBase method, ImportGenericContext context) { var method_info = method as SR.MethodInfo; if (method_info == null) throw new InvalidOperationException (); var element_method = ImportMethod (method_info.GetGenericMethodDefinition (), context, ImportGenericKind.Definition); 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)); return instance; } finally { context.Pop (); } }
public 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 (); } }
public FieldReference ImportField (SR.FieldInfo field, ImportGenericContext context) { var declaring_type = ImportType (field.DeclaringType, context); 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), }; } finally { context.Pop (); } }
TypeReference ImportGenericInstance (Type type, ImportGenericContext context) { var element_type = ImportType (type.GetGenericTypeDefinition (), context, ImportGenericKind.Definition); 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)); return instance; } finally { context.Pop (); } }