using System; using System.Collections.Generic; using System.Linq; using System.Text; using ILRuntime.Runtime.Stack; namespace ILRuntime.Runtime { public static class Extensions { public static bool GetJITFlags(this Mono.Cecil.CustomAttribute attribute, Enviorment.AppDomain appdomain, out int flags) { var at = appdomain.GetType(attribute.AttributeType, null, null); flags = ILRuntimeJITFlags.None; if (at == appdomain.JITAttributeType) { if (attribute.HasConstructorArguments) { flags = (int)attribute.ConstructorArguments[0].Value; } else flags = ILRuntimeJITFlags.JITOnDemand; return true; } else return false; } public static void GetClassName(this Type type, out string clsName, out string realClsName, out bool isByRef, bool simpleClassName = false) { isByRef = type.IsByRef; int arrayRank = 1; if (isByRef) { type = type.GetElementType(); } bool isArray = type.IsArray; if (isArray) { arrayRank = type.GetArrayRank(); type = type.GetElementType(); if (type.IsArray) { type.GetClassName(out clsName, out realClsName, out isByRef, simpleClassName); clsName += "_Array"; if (!simpleClassName) clsName += "_Binding"; if (arrayRank > 1) clsName += arrayRank; if (arrayRank <= 1) realClsName += "[]"; else { StringBuilder sb = new StringBuilder(); sb.Append(realClsName); sb.Append('['); for (int i = 0; i < arrayRank - 1; i++) { sb.Append(','); } sb.Append(']'); realClsName = sb.ToString(); } return; } } string realNamespace = null; bool isNestedGeneric = false; if (type.IsNested) { string bClsName, bRealClsName; bool tmp; var rt = type.ReflectedType; if(rt.IsGenericType && rt.IsGenericTypeDefinition) { if (type.IsGenericType) { rt = rt.MakeGenericType(type.GetGenericArguments()); isNestedGeneric = true; } } GetClassName(rt, out bClsName, out bRealClsName, out tmp); clsName = bClsName + "_"; realNamespace = bRealClsName + "."; } else { clsName = simpleClassName ? "" : (!string.IsNullOrEmpty(type.Namespace) ? type.Namespace.Replace(".", "_") + "_" : ""); if (string.IsNullOrEmpty(type.Namespace)) { if (type.IsArray) { var elementType = type.GetElementType(); if (elementType.IsNested && elementType.DeclaringType != null) { realNamespace = elementType.Namespace + "." + elementType.DeclaringType.Name + "."; } else { realNamespace = elementType.Namespace + "."; } } else { realNamespace = "global::"; } } else { realNamespace = type.Namespace + "."; } } clsName = clsName + type.Name.Replace(".", "_").Replace("`", "_").Replace("<", "_").Replace(">", "_"); bool isGeneric = false; string ga = null; if (type.IsGenericType && !isNestedGeneric) { isGeneric = true; clsName += "_"; ga = "<"; var args = type.GetGenericArguments(); bool first = true; foreach (var j in args) { if (first) first = false; else { clsName += "_"; ga += ", "; } string a, b; bool tmp; GetClassName(j, out a, out b, out tmp, true); clsName += a; ga += b; } ga += ">"; } if (isArray) { clsName += "_Array"; if (arrayRank > 1) clsName += arrayRank; } if (!simpleClassName) clsName += "_Binding"; realClsName = realNamespace; if (isGeneric) { int idx = type.Name.IndexOf("`"); if (idx > 0) { realClsName += type.Name.Substring(0, idx); realClsName += ga; } else realClsName += type.Name; } else realClsName += type.Name; if (isArray) { if (arrayRank <= 1) realClsName += "[]"; else { StringBuilder sb = new StringBuilder(); sb.Append(realClsName); sb.Append('['); for(int i=0;i