/// <summary> /// 初始化IL类型 /// </summary> /// <param name="def">MONO返回的类型定义</param> /// <param name="domain">ILdomain</param> public ILType(TypeReference def, Runtime.Enviorment.AppDomain domain) { this.typeRef = def; RetriveDefinitino(def); appdomain = domain; jitFlags = domain.DefaultJITFlags; }
void InitializeMethods() { if (definition.HasCustomAttributes) { for (int i = 0; i < definition.CustomAttributes.Count; i++) { ILRuntimeJITFlags f; if (definition.CustomAttributes[i].GetJITFlags(AppDomain, out f)) { this.jitFlags = f; break; } } } methods = new Dictionary <string, List <ILMethod> >(); constructors = new List <ILMethod>(); if (definition == null) { return; } foreach (var i in definition.Methods) { if (i.IsConstructor) { if (i.IsStatic) { staticConstructor = new ILMethod(i, this, appdomain, jitFlags); } else { constructors.Add(new ILMethod(i, this, appdomain, jitFlags)); } } else { List <ILMethod> lst; if (!methods.TryGetValue(i.Name, out lst)) { lst = new List <ILMethod>(); methods[i.Name] = lst; } var m = new ILMethod(i, this, appdomain, jitFlags); lst.Add(m); } } if (!appdomain.SuppressStaticConstructor && !staticConstructorCalled) { staticConstructorCalled = true; if (staticConstructor != null && (!TypeReference.HasGenericParameters || IsGenericInstance)) { appdomain.Invoke(staticConstructor, null, null); } } }
public ILMethod(MethodDefinition def, ILType type, ILRuntime.Runtime.Enviorment.AppDomain domain, ILRuntimeJITFlags flags) { this.def = def; declaringType = type; this.jitFlags = flags; if (def.ReturnType.IsGenericParameter) { ReturnType = FindGenericArgument(def.ReturnType.Name); } else { ReturnType = domain.GetType(def.ReturnType, type, this); } if (type.IsDelegate && def.Name == "Invoke") { isDelegateInvoke = true; } this.appdomain = domain; paramCnt = def.HasParameters ? def.Parameters.Count : 0; if (def.HasCustomAttributes) { for (int i = 0; i < def.CustomAttributes.Count; i++) { ILRuntimeJITFlags f; if (def.CustomAttributes[i].GetJITFlags(domain, out f)) { this.jitFlags = f; break; } } } jitImmediately = (jitFlags & ILRuntimeJITFlags.JITImmediately) == ILRuntimeJITFlags.JITImmediately; jitOnDemand = (jitFlags & ILRuntimeJITFlags.JITOnDemand) == ILRuntimeJITFlags.JITOnDemand; #if DEBUG && !DISABLE_ILRUNTIME_DEBUG if (def.HasBody) { var sp = GetValidSequence(0, 1); if (sp != null) { StartLine = sp.StartLine; sp = GetValidSequence(def.Body.Instructions.Count - 1, -1); if (sp != null) { EndLine = sp.EndLine; } } } #endif }