internal static void CriticalFailure(string message, Exception x) { Tracer.Error(Tracer.Runtime, "CRITICAL FAILURE: {0}", message); System.Type messageBox = null; #if !STUB_GENERATOR // NOTE we use reflection to invoke MessageBox.Show, to make sure we run in environments where WinForms isn't available /*Assembly winForms = IsUnix ? null : Assembly.Load("System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); * if(winForms != null) * { * messageBox = winForms.GetType("System.Windows.Forms.MessageBox"); * }*/ #endif message = String.Format("****** Critical Failure: {1} ******{0}{0}" + "PLEASE FILE A BUG REPORT FOR IKVM.NET WHEN YOU SEE THIS MESSAGE{0}{0}" + (messageBox != null ? "(on Windows you can use Ctrl+C to copy the contents of this message to the clipboard){0}{0}" : "") + "{2}{0}" + "{3}{0}" + "{4} {5}-bit{0}{0}" + "{6}{0}" + "{7}{0}" + "{8}", Environment.NewLine, message, System.Reflection.Assembly.GetExecutingAssembly().FullName, System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(), Environment.Version, IntPtr.Size * 8, x, x != null ? new StackTrace(x, true).ToString() : "", new StackTrace(true)); Console.Error.WriteLine(message); }
/// <summary> /// Translate a System.Type into the universe's type representation /// </summary> protected internal override Type MapType(System.Type type, bool demand) { if (type == null) { return(null); } #if DEBUG if (type.Assembly == typeof(IKVM.Reflection.Type).Assembly) { throw new InvalidOperationException(string.Format( "Somebody is passing me IKVM types! {0} should be fully-qualified at the call-site", type.Name)); } #endif Type result = universe.GetType(type.AssemblyQualifiedName); if (result == null) { // things also tend to move around... *a lot* - especially in WinRT; search all as a fallback strategy foreach (Assembly a in universe.GetAssemblies()) { result = a.GetType(type.FullName); if (result != null) { break; } } if (result == null && demand) { throw new InvalidOperationException("Unable to map type: " + type.AssemblyQualifiedName); } } return(result); }
static Attribute CreateMajorMinorAttribute(System.Type type, PlatformName platform, int major, int minor, byte arch, string message) { var ctorValues = new object [] { (byte)platform, major, minor, arch, message }; var ctorTypes = new System.Type [] { PlatformEnum, typeof(int), typeof(int), PlatformArch, typeof(string) }; return(CreateNewAttribute(type, ctorTypes, ctorValues)); }
public static System.Attribute CreateUnavailableAttribute(PlatformName platformName, byte arch = 0xff, string message = null) { var ctorValues = new object [] { (byte)platformName, arch, message }; var ctorTypes = new System.Type [] { PlatformEnum, PlatformArch, typeof(string) }; return(CreateNewAttribute(UnavailableAttributeType, ctorTypes, ctorValues)); }
/// <summary> /// Creates a new instance from a protocol-buffer stream /// </summary> /// <param name="type">The type to be created.</param> /// <param name="source">The binary stream to apply to the new instance (cannot be null).</param> /// <returns>A new, initialized instance.</returns> public static object Deserialize(System.Type type, Stream source) { if (typeof(IParseable).IsAssignableFrom(type)) { ProtoReader reader = null; object obj = null; try { reader = ProtoReader.Create(source, RuntimeTypeModel.Default, null, -1); //if (value != null) reader.SetRootObject(value); //object obj = DeserializeCore(reader, type, value, autoCreate); obj = Activator.CreateInstance(type); IParseable objProxy = obj as IParseable; objProxy.Parse(reader); reader.CheckFullyConsumed(); return(obj); } finally { ProtoReader.Recycle(reader); } return(obj); } UnityEngine.Debug.LogWarning("Old Form Load Table " + type.Name + "!!"); return(RuntimeTypeModel.Default.Deserialize(source, null, type)); }
internal static Type Import(System.Type type) { #if STATIC_COMPILER || STUB_GENERATOR return(StaticCompiler.Universe.Import(type)); #else return(type); #endif }
public static bool IsAssignableFrom(System.Type t, Type @from) { if (t == null) { throw new ArgumentNullException(nameof(t)); } return(IsAssignableFrom(t.FullName, @from)); }
internal static System.Type GetUnderlyingType(System.Type type) { #if NO_GENERICS return null; // never a Nullable<T>, so always returns null #else return Nullable.GetUnderlyingType(type); #endif }
/// <summary> /// Writes a Type to the stream, using the model's DynamicTypeFormatting if appropriate; supported wire-types: String /// </summary> public static void WriteType(System.Type value, ProtoWriter writer) { if (writer == null) { throw new ArgumentNullException("writer"); } WriteString(writer.SerializeType(value), writer); }
public static bool IsAssignableFrom(System.Type t, Type @from, ITypeMapper typeMapper) { if (t == null) { throw new ArgumentNullException(nameof(t)); } return(typeMapper.MapType(t).IsAssignableFrom(@from)); }
public static IList <CustomAttributeData> GetCustomAttributes(MemberInfo m, System.Type type, bool inherit, ITypeMapper mapper = null) { if (mapper != null) { return(m.__GetCustomAttributes(mapper.MapType(type), inherit)); } return(GetCustomAttributes(m, type.FullName, inherit)); }
internal static void CriticalFailure(string message, Exception x) { try { Tracer.Error(Tracer.Runtime, "CRITICAL FAILURE: {0}", message); System.Type messageBox = null; #if !STUB_GENERATOR // NOTE we use reflection to invoke MessageBox.Show, to make sure we run in environments where WinForms isn't available Assembly winForms = IsUnix ? null : Assembly.Load("System.Windows.Forms, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"); if (winForms != null) { messageBox = winForms.GetType("System.Windows.Forms.MessageBox"); } #endif message = String.Format("****** Critical Failure: {1} ******{0}{0}" + "PLEASE FILE A BUG REPORT FOR IKVM.NET WHEN YOU SEE THIS MESSAGE{0}{0}" + (messageBox != null ? "(on Windows you can use Ctrl+C to copy the contents of this message to the clipboard){0}{0}" : "") + "{2}{0}" + "{3}{0}" + "{4} {5}-bit{0}{0}" + "{6}{0}" + "{7}{0}" + "{8}", Environment.NewLine, message, System.Reflection.Assembly.GetExecutingAssembly().FullName, System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory(), Environment.Version, IntPtr.Size * 8, x, x != null ? new StackTrace(x, true).ToString() : "", new StackTrace(true)); if (messageBox != null) { try { Version ver = SafeGetAssemblyVersion(typeof(JVM).Assembly); messageBox.InvokeMember("Show", System.Reflection.BindingFlags.InvokeMethod | System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public, null, null, new object[] { message, "IKVM.NET " + ver + " Critical Failure" }); } catch { Console.Error.WriteLine(message); } } else { Console.Error.WriteLine(message); } } catch (Exception ex) { Console.Error.WriteLine(ex); } finally { Environment.Exit(666); } }
public static bool CanParse(System.Type type) { bool bCan = typeof(IParseable).IsAssignableFrom(type); if (bCan == false) { UnityEngine.Debug.LogWarning("Old Form Load Table " + type.Name + "!!"); } return(bCan); }
public static ProtoTypeCode GetTypeCode(System.Type type) { #if WINRT int idx = Array.IndexOf <Type>(knownTypes, type); if (idx >= 0) { return(knownCodes[idx]); } return(type == null ? ProtoTypeCode.Empty : ProtoTypeCode.Unknown); #else TypeCode code = System.Type.GetTypeCode(type); switch (code) { case TypeCode.Empty: case TypeCode.Boolean: case TypeCode.Char: case TypeCode.SByte: case TypeCode.Byte: case TypeCode.Int16: case TypeCode.UInt16: case TypeCode.Int32: case TypeCode.UInt32: case TypeCode.Int64: case TypeCode.UInt64: case TypeCode.Single: case TypeCode.Double: case TypeCode.Decimal: case TypeCode.DateTime: case TypeCode.String: return((ProtoTypeCode)code); } if (type == typeof(TimeSpan)) { return(ProtoTypeCode.TimeSpan); } if (type == typeof(Guid)) { return(ProtoTypeCode.Guid); } if (type == typeof(Uri)) { return(ProtoTypeCode.Uri); } if (type == typeof(byte[])) { return(ProtoTypeCode.ByteArray); } if (type == typeof(System.Type)) { return(ProtoTypeCode.Type); } return(ProtoTypeCode.Unknown); #endif }
public static System.Attribute CreateNewAttribute(System.Type attribType, System.Type [] ctorTypes, object [] ctorValues) { var ctor = attribType.GetConstructor(ctorTypes); if (ctor == null) { throw ErrorHelper.CreateError(1058, "Internal error: could not find a constructor for the mock attribute '{0}'. Please file a bug report (https://github.com/xamarin/xamarin-macios/issues/new) with a test case.", attribType.FullName); } return((System.Attribute)ctor.Invoke(ctorValues)); }
public static System.Attribute CreateNewAttribute(System.Type attribType, System.Type [] ctorTypes, object [] ctorValues) { var ctor = attribType.GetConstructor(ctorTypes); if (ctor == null) { throw ErrorHelper.CreateError(1058, attribType.FullName); } return((System.Attribute)ctor.Invoke(ctorValues)); }
internal static System.Type GetNullableUnderlyingType(System.Type type) { if (type == null) { return(null); } #if NO_GENERICS return(null); // never a Nullable<T>, so always returns null #else return(Nullable.GetUnderlyingType(type)); #endif }
// This method gets the IKVM.Reflection.Type for a System.Type. // It knows about our mock attribute logic, so it will return the mocked IKVM.Reflection.Type for a mocked System.Type. static Type ConvertType(System.Type type, ICustomAttributeProvider provider) { Type rv; if (type.Assembly == typeof(int).Assembly) { rv = TypeManager.CorlibAssembly.GetType(type.FullName); } else if (type.Assembly == typeof(System.ComponentModel.EditorBrowsableAttribute).Assembly) { rv = TypeManager.SystemAssembly.GetType(type.FullName); } else if (type.Assembly == typeof(TypeManager).Assembly) { // Types (attributes) in the generator are mocked types from // either the binding assembly or the platform assembly. rv = TypeManager.BindingAssembly.GetType(type.FullName); if (rv == null) { string fullname; // HACK ?? if (type.Namespace?.StartsWith("XamCore.", System.StringComparison.Ordinal) == true) { var prefix = BindingTouch.NamespacePlatformPrefix; if (!string.IsNullOrEmpty(prefix)) { fullname = prefix + "." + type.FullName.Substring(8); } else { fullname = type.FullName.Substring(8); } } else { fullname = type.FullName; } rv = TypeManager.PlatformAssembly.GetType(fullname); } } else { throw ErrorHelper.CreateError(1054, "Internal error: can't convert type '{0}' (unknown assembly). Please file a bug report (https://github.com/xamarin/xamarin-macios/issues/new) with a test case.", type.AssemblyQualifiedName); } if (rv == null) { throw ErrorHelper.CreateError(1055, "Internal error: failed to convert type '{0}'. Please file a bug report (https://github.com/xamarin/xamarin-macios/issues/new) with a test case.", type.AssemblyQualifiedName); } return(rv); }
// This method gets the IKVM.Reflection.Type for a System.Type. // It knows about our mock attribute logic, so it will return the mocked IKVM.Reflection.Type for a mocked System.Type. Type ConvertType(System.Type type, ICustomAttributeProvider provider) { Type rv; if (type.Assembly == typeof(int).Assembly) { rv = TypeManager.CorlibAssembly.GetType(type.FullName); } else if (type.Assembly == typeof(System.ComponentModel.EditorBrowsableAttribute).Assembly) { rv = TypeManager.SystemAssembly.GetType(type.FullName); } else if (type.Assembly == typeof(TypeManager).Assembly) { // Types (attributes) in the generator are mocked types from // either the binding assembly or the platform assembly. rv = TypeManager.BindingAssembly.GetType(type.FullName); if (rv == null) { string fullname; // HACK ?? if (type.Namespace?.StartsWith("XamCore.", System.StringComparison.Ordinal) == true) { fullname = type.FullName.Substring(8); } else { fullname = type.FullName; } rv = TypeManager.PlatformAssembly.GetType(fullname); } } else { throw ErrorHelper.CreateError(1054, type.AssemblyQualifiedName); } if (rv == null) { throw ErrorHelper.CreateError(1055, type.AssemblyQualifiedName); } return(rv); }
// This method gets the IKVM.Reflection.Type for a System.Type. Type ConvertType(System.Type type, ICustomAttributeProvider provider) { var ikvm_type_lookup = BindingTouch.IKVMTypeLookup; if (!ikvm_type_lookup.TryGetValue(type, out var rv)) { // Brute force: look everywhere. // Due to how types move around between assemblies in .NET 5 it gets complicated // to figure out which assembly each type comes from, so just look in every assembly. // Report a warning if we find the same type in multiple assemblies though. var assemblies = BindingTouch.universe.GetAssemblies(); foreach (var asm in assemblies) { var lookup = asm.FindType(new TypeName(type.Namespace, type.Name)); if (lookup == null) { continue; } if (lookup.Assembly != asm) { // Apparently looking for type X in assembly A can return type X from assembly B... ignore those. continue; } if (rv != null) { ErrorHelper.Warning(1119, /*"Internal error: found the same type ({0}) in multiple assemblies ({1} and {2}). Please file a bug report (https://github.com/xamarin/xamarin-macios/issues/new) with a test case.", */ type.FullName, rv.AssemblyQualifiedName, lookup.AssemblyQualifiedName); break; // no need to report this more than once } rv = lookup; } ikvm_type_lookup [type] = rv; } if (rv == null) { throw ErrorHelper.CreateError(1055, type.AssemblyQualifiedName); } return(rv); }
public static object ParseEx(System.Type type, Stream source) { ProtoReader reader = null; object obj = null; try { reader = ProtoReader.Create(source, RuntimeTypeModel.Default, null, -1); //if (value != null) reader.SetRootObject(value); //object obj = DeserializeCore(reader, type, value, autoCreate); obj = Activator.CreateInstance(type); IParseable objProxy = obj as IParseable; objProxy.Parse(reader); reader.CheckFullyConsumed(); return(obj); } finally { ProtoReader.Recycle(reader); } return(obj); }
public TypeGen Class(System.Type baseType, string name) { return(Class(name, TypeMapper.MapType(baseType))); }
/// <summary> /// Creates a new instance from a protocol-buffer stream /// </summary> /// <param name="type">The type to be created.</param> /// <param name="source">The binary stream to apply to the new instance (cannot be null).</param> /// <returns>A new, initialized instance.</returns> public static object Deserialize(System.Type type, Stream source) { return(RuntimeTypeModel.Default.Deserialize(source, null, type)); }
public Outline(System.Type t, TextWriter output, bool declared_only, bool show_private, bool filter_obsolete) { throw new NotImplementedException(); }
public FieldGen Attribute(System.Type attributeType, params object[] args) { return(Attribute(TypeMapper.MapType(attributeType), args)); }
public FieldGen Attribute(System.Type attributeType) { return(Attribute(TypeMapper.MapType(attributeType))); }
public AttributeGen <FieldGen> BeginAttribute(System.Type attributeType) { return(BeginAttribute(TypeMapper.MapType(attributeType))); }
///<summary> /// Creates a new instance of the ProtoIncludeAttribute. /// </summary> /// <param name="tag">The unique index (within the type) that will identify this data.</param> /// <param name="knownType">The additional type to serialize/deserialize.</param> public ProtoIncludeAttribute(int tag, System.Type knownType) : this(tag, knownType == null ? "" : knownType.AssemblyQualifiedName) { }
public TypeGen Class(string name, System.Type baseType, params Type[] interfaces) { return(Class(name, TypeMapper.MapType(baseType), interfaces)); }
public DelegateGen Delegate(System.Type returnType, string name) { return(Delegate(TypeMapper.MapType(returnType), name)); }
public LongLiteral(System.Type t, long value) { _t = t; Value = value; }