public delegate Assembly ResolveEventHandler(object sender, ResolveEventArgs args);
+ [Flags]
+ public enum UniverseOptions
+ {
+ None = 0,
+ EnableFunctionPointers = 1,
+ }
+
public sealed class Universe : IDisposable
{
- internal readonly Dictionary<Type, Type> canonicalizedTypes = new Dictionary<Type, Type>();
+ private readonly Dictionary<Type, Type> canonicalizedTypes = new Dictionary<Type, Type>();
private readonly List<Assembly> assemblies = new List<Assembly>();
private readonly List<AssemblyBuilder> dynamicAssemblies = new List<AssemblyBuilder>();
private readonly Dictionary<string, Assembly> assembliesByName = new Dictionary<string, Assembly>();
private readonly Dictionary<System.Type, Type> importedTypes = new Dictionary<System.Type, Type>();
private Dictionary<ScopedTypeName, Type> missingTypes;
private bool resolveMissingMembers;
+ private readonly bool enableFunctionPointers;
private Type typeof_System_Object;
private Type typeof_System_ValueType;
private Type typeof_System_Enum;
private Type typeof_System_NonSerializedAttribute;
private Type typeof_System_SerializableAttribute;
private Type typeof_System_AttributeUsageAttribute;
- private Type typeof_System_Reflection_AssemblyCultureAttribute;
private Type typeof_System_Runtime_InteropServices_DllImportAttribute;
private Type typeof_System_Runtime_InteropServices_FieldOffsetAttribute;
private Type typeof_System_Runtime_InteropServices_InAttribute;
private Type typeof_System_Security_Permissions_SecurityAction;
private List<ResolveEventHandler> resolvers = new List<ResolveEventHandler>();
+ public Universe()
+ : this(UniverseOptions.None)
+ {
+ }
+
+ public Universe(UniverseOptions options)
+ {
+ enableFunctionPointers = (options & UniverseOptions.EnableFunctionPointers) != 0;
+ }
+
internal Assembly Mscorlib
{
get { return Load("mscorlib"); }
get { return typeof_System_AttributeUsageAttribute ?? (typeof_System_AttributeUsageAttribute = ImportMscorlibType(typeof(System.AttributeUsageAttribute))); }
}
- internal Type System_Reflection_AssemblyCultureAttribute
- {
- get { return typeof_System_Reflection_AssemblyCultureAttribute ?? (typeof_System_Reflection_AssemblyCultureAttribute = ImportMscorlibType(typeof(System.Reflection.AssemblyCultureAttribute))); }
- }
-
internal Type System_Runtime_InteropServices_DllImportAttribute
{
get { return typeof_System_Runtime_InteropServices_DllImportAttribute ?? (typeof_System_Runtime_InteropServices_DllImportAttribute = ImportMscorlibType(typeof(System.Runtime.InteropServices.DllImportAttribute))); }
get { return resolveMissingMembers; }
}
+ internal bool EnableFunctionPointers
+ {
+ get { return enableFunctionPointers; }
+ }
+
private struct ScopedTypeName : IEquatable<ScopedTypeName>
{
private readonly object scope;
}
throw new System.MissingMemberException(declaringType.ToString(), name);
}
+
+ internal Type CanonicalizeType(Type type)
+ {
+ Type canon;
+ if (!canonicalizedTypes.TryGetValue(type, out canon))
+ {
+ canon = type;
+ canonicalizedTypes.Add(canon, canon);
+ }
+ return canon;
+ }
+
+ public Type MakeFunctionPointer(__StandAloneMethodSig sig)
+ {
+ return FunctionPointerType.Make(this, sig);
+ }
+
+ public __StandAloneMethodSig MakeStandAloneMethodSig(System.Runtime.InteropServices.CallingConvention callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
+ {
+ return new __StandAloneMethodSig(true, callingConvention, 0, returnType ?? this.System_Void, Util.Copy(parameterTypes), Type.EmptyTypes,
+ PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes)));
+ }
+
+ public __StandAloneMethodSig MakeStandAloneMethodSig(CallingConventions callingConvention, Type returnType, CustomModifiers returnTypeCustomModifiers, Type[] parameterTypes, Type[] optionalParameterTypes, CustomModifiers[] parameterTypeCustomModifiers)
+ {
+ return new __StandAloneMethodSig(false, 0, callingConvention, returnType ?? this.System_Void, Util.Copy(parameterTypes), Util.Copy(optionalParameterTypes),
+ PackedCustomModifiers.CreateFromExternal(returnTypeCustomModifiers, parameterTypeCustomModifiers, Util.NullSafeLength(parameterTypes) + Util.NullSafeLength(optionalParameterTypes)));
+ }
}
}