private IKVM.Reflection.Type FindSurrogateSourceType(IKVM.Reflection.Type type, IKVM.Reflection.Universe universe) { var attributeType = universe.GetType("System.Attribute, mscorlib"); const IKVM.Reflection.BindingFlags flags = IKVM.Reflection.BindingFlags.Static | IKVM.Reflection.BindingFlags.Public | IKVM.Reflection.BindingFlags.NonPublic; foreach (var m in type.GetMethods(flags)) { var parameters = m.GetParameters(); if (parameters.Length == 1 && m.ReturnType.Name != "Void" && m.ReturnType != type) { foreach (var attrib in m.__GetCustomAttributes(attributeType, true)) { if (attrib.Constructor.DeclaringType.FullName == "ProtoBuf.ProtoConverterAttribute") { return(m.ReturnType); } } if (m.Name == "op_Implicit" || m.Name == "op_Explicit") { return(m.ReturnType); } } } return(null); }
static string TryInferFramework(string path) { string imageRuntimeVersion = null; try { using (var uni = new IKVM.Reflection.Universe()) { uni.AssemblyResolve += (s, a) => ((IKVM.Reflection.Universe)s).CreateMissingAssembly(a.Name); var asm = uni.LoadFile(path); imageRuntimeVersion = asm.ImageRuntimeVersion; var attr = uni.GetType("System.Attribute, mscorlib"); foreach (var attrib in asm.__GetCustomAttributes(attr, false)) { if (attrib.Constructor.DeclaringType.FullName == "System.Runtime.Versioning.TargetFrameworkAttribute" && attrib.ConstructorArguments.Count == 1) { var parts = ((string)attrib.ConstructorArguments[0].Value).Split(','); string runtime = null, version = null, profile = null; for (int i = 0; i < parts.Length; i++) { int idx = parts[i].IndexOf('='); if (idx < 0) { runtime = parts[i]; } else { switch (parts[i].Substring(0, idx)) { case "Version": version = parts[i].Substring(idx + 1); break; case "Profile": profile = parts[i].Substring(idx + 1); break; } } } if (runtime != null) { var sb = new StringBuilder(runtime); if (version != null) { sb.Append(Path.DirectorySeparatorChar).Append(version); } if (profile != null) { sb.Append(Path.DirectorySeparatorChar).Append("Profile").Append(Path.DirectorySeparatorChar).Append(profile); } string targetFramework = sb.ToString(); return(targetFramework); } } } } } catch (Exception ex) { // not really fussed; we could have multiple inputs to try, and the user // can always use -f:blah to specify it explicitly Debug.WriteLine(ex.Message); } if (!string.IsNullOrEmpty(imageRuntimeVersion)) { string frameworkPath = Path.Combine( Environment.ExpandEnvironmentVariables(@"%windir%\Microsoft.NET\Framework"), imageRuntimeVersion); if (Directory.Exists(frameworkPath)) { return(frameworkPath); } } return(null); }