internal static Method CreateMethod(Class declaringType, string name, NativeFunction function, int vtableSlot) { Method method = new Method(); method.Name = name; method.Function = function; method.VTableSlot = vtableSlot; if (function != null) { function["m"] = var.Cast<Method>(method); } method.DeclaringClass = declaringType; declaringType.Methods.Push(method); return method; }
internal static Property CreateProperty(Class declaringType, string name, Method getMethod, Method setMethod) { Property property = new Property(); property.DeclaringClass = declaringType; property.Name = name; property.GetMethod = getMethod; property.SetMethod = setMethod; declaringType.Properties.Push(property); return property; }
internal static Class CreateClass( string ns, string name, Assembly assembly, UIntPtr vtableDataPointer, Class elementClass, bool isInterface, bool isArray ) { Class klass = new Class(); klass.Name = name; klass.Namespace = ns; klass.Assembly = assembly; klass.VTableDataPointer = vtableDataPointer; VTable vtable = GenerateCodeToDereferenceVTableDataPointer(vtableDataPointer); klass.VTable = vtable; vtable.Class = klass; klass.ElementClass = elementClass; klass.IsInterface = isInterface; klass.IsArray = isArray; assembly.Classes.Push(klass); return klass; }
internal static Constructor CreateConstructor(Class declaringType, string name, NativeFunction function) { Constructor ctor = new Constructor(); ctor.Name = name; ctor.Function = function; if (function != null) { function["m"] = var.Cast<Constructor>(ctor); } ctor.DeclaringClass = declaringType; declaringType.Constructors.Push(ctor); return ctor; }
private static RuntimeType GetTypeFromClass(Class klass) { // check cache. if not there, create the runtime type and save to cache if (!_runtimeTypeCache.ContainsKey(klass)) { RuntimeType declaringType; if (klass.DeclaringClass != null) { declaringType = GetTypeFromClass(klass.DeclaringClass); } else { declaringType = null; } RuntimeType runtimeType = new RuntimeType(klass, declaringType); _runtimeTypeCache[klass] = runtimeType; } return _runtimeTypeCache[klass]; }
private static Constructor GetDefaultConstructor(Class klass) { NativeArray<Constructor> constructors = klass.Constructors; for (int i = 0; i < constructors.Length; i++) { Constructor constructor = constructors[i]; if (constructor.Parameters.Length == 0) { return constructor; } } return null; }
private static object CreateInstance(Class klass) { // check for default constructor Constructor defaultConstructor = GetDefaultConstructor(klass); if (defaultConstructor == null) { // TODO: Throw MissingMethodException throw new ExecutionEngineException("No default constructor found in type " + klass); } return CreateInstance(defaultConstructor); }
// TODO: This method is not code generated correctly // root cause is likely the conditional expression // the arguments to RuntimeType::.ctor are reversed! private static RuntimeType BrokenGetTypeFromClass(Class klass) { // check cache. if not there, create the runtime type and save to cache if (!_runtimeTypeCache.ContainsKey(klass)) { RuntimeType runtimeType = new RuntimeType(klass, klass.DeclaringClass != null ? GetTypeFromClass(klass.DeclaringClass) : null); _runtimeTypeCache[klass] = runtimeType; } return _runtimeTypeCache[klass]; }
public RuntimeType(Class klass, RuntimeType declaringType) : base((RuntimeTypeHandle)klass.VTable) { _class = klass; }