public override void ProcessType(TypeDefinition type) { if (!type.Is (Namespaces.ObjCRuntime, "Runtime")) return; foreach (MethodDefinition m in type.Methods) { if (!m.IsStatic || m.Name != "CreateRegistrar" || !m.HasParameters || m.Parameters.Count != 1) continue; OptimizeRegistrar (m); } }
public override void ProcessType(TypeDefinition type) { if (!type.Is ("ObjCRuntime", "RuntimeOptions")) return; MethodDefinition method = type.Methods.First (x => x.Name == "GetHttpMessageHandler" && !x.HasParameters); AssemblyDefinition systemNetHTTPAssembly = context.GetAssemblies ().First (x => x.Name.Name == "System.Net.Http"); TypeDefinition handler = RuntimeOptions.GetHttpMessageHandler (Options.RuntimeOptions, systemNetHTTPAssembly.MainModule, type.Module); MethodReference handler_ctor = handler.Methods.First (x => x.IsConstructor && !x.HasParameters && !x.IsStatic); // HttpClientHandler is defined not in Xamarin.Mac.dll so we need to import if (handler.Name.Contains ("HttpClientHandler")) handler_ctor = type.Module.Import (handler_ctor); var body = new MethodBody (method); var il = body.GetILProcessor (); il.Emit (OpCodes.Newobj, handler_ctor); il.Emit (OpCodes.Ret); method.Body = body; }
public override void ProcessType(TypeDefinition type) { #if XAMARIN_NO_TLS return; #else if (!type.Is (Namespaces.ObjCRuntime, "Runtime")) return; MethodDefinition callbackMethod = null; foreach (var m in type.Methods) { if (!m.IsStatic || m.HasParameters) continue; if (m.Name.Equals ("TlsProviderFactoryCallback", StringComparison.Ordinal)) { callbackMethod = m; break; } } if (callbackMethod == null) throw new Exception ("Could not set the default TlsProvider"); var providerCtor = FindProviderConstructor (type.Module); if (providerCtor == null) return; // re-write TlsProviderFactoryCallback() var body = new MethodBody (callbackMethod); var il = body.GetILProcessor (); if (providerCtor != null) il.Emit (OpCodes.Newobj, providerCtor); else il.Emit (OpCodes.Ldnull); il.Emit (OpCodes.Ret); callbackMethod.Body = body; #endif }
public override void ProcessType(TypeDefinition type) { // no code to remove in interfaces, skip processing if (type.IsInterface) return; // [MonoTouch.]ObjCRuntime.Runtime.RegisterEntryAssembly is needed only for the simulator // and does not have to be preserved on devices if (product) { if (Device && type.Is (Namespaces.ObjCRuntime, "Runtime")) { foreach (var m in type.Methods) { if (m.Name == "RegisterEntryAssembly") { ProcessMethod (m); type.Module.Import (get_nse); } } } // Remove the warning that we show (console) if someone subclass UIButton using the UIButtonType ctor // https://trello.com/c/Nf2B8mIM/484-remove-debug-code-in-the-linker if (!Debug && type.Is (Namespaces.UIKit, "UIButton")) { foreach (var m in type.Methods) { if (m.IsConstructor && m.HasParameters && m.Parameters [0].ParameterType.Is (Namespaces.UIKit, "UIButtonType")) ProcessUIButtonCtor (m); } } // all other candidates are in mscorlib.dll (not the product .dll) return; } if (!IsCandidate (type)) return; ProcessMethods (type); if (type.HasNestedTypes) { foreach (TypeDefinition nested in type.NestedTypes) ProcessMethods (nested); } }
public override void ProcessType(TypeDefinition type) { if (!type.Is ("System.Net.Http", "HttpClient")) return; MethodDefinition default_ctor = null; MethodDefinition full_ctor = null; foreach (var m in type.Methods) { if (m.IsStatic || !m.IsConstructor) continue; if (!m.HasParameters) { default_ctor = m; } else if (m.Parameters.Count == 2) { full_ctor = m; } } if (default_ctor == null || full_ctor == null) throw new Exception ("Could not set the default HttpMessageHandler"); var handler = RuntimeOptions.GetHttpMessageHandler (Options.RuntimeOptions, type.Module); MethodDefinition handler_ctor = null; foreach (var m in handler.Methods) { if (m.IsStatic || !m.IsConstructor || m.HasParameters) continue; handler_ctor = m; break; } // re-write default ctor var body = new MethodBody (default_ctor); var il = body.GetILProcessor (); il.Emit (OpCodes.Ldarg_0); il.Emit (OpCodes.Newobj, handler_ctor); il.Emit (OpCodes.Ldc_I4_1); il.Emit (OpCodes.Call, full_ctor); il.Emit (OpCodes.Ret); default_ctor.Body = body; }