diff --git a/BeefLibs/corlib/src/Reflection/MethodInfo.bf b/BeefLibs/corlib/src/Reflection/MethodInfo.bf index 7e1f1727..d3211743 100644 --- a/BeefLibs/corlib/src/Reflection/MethodInfo.bf +++ b/BeefLibs/corlib/src/Reflection/MethodInfo.bf @@ -12,6 +12,14 @@ namespace System.Reflection TypeInstance mTypeInstance; TypeInstance.MethodData* mMethodData; + public bool IsInitialized + { + get + { + return mMethodData != null; + } + } + public StringView Name { get @@ -157,7 +165,7 @@ namespace System.Reflection if ((paramType.IsPrimitive) && (underlyingType.IsTypedPrimitive)) // Boxed primitive? underlyingType = underlyingType.UnderlyingType; - if (argType.IsBoxedStructPtr) + if ((argType.IsBoxedStructPtr) || (argIdx == -1)) { dataPtr = *(void**)dataPtr; handled = true; diff --git a/BeefLibs/corlib/src/Reflection/TypeInstance.bf b/BeefLibs/corlib/src/Reflection/TypeInstance.bf index 8d3ccc60..4979bea0 100644 --- a/BeefLibs/corlib/src/Reflection/TypeInstance.bf +++ b/BeefLibs/corlib/src/Reflection/TypeInstance.bf @@ -32,6 +32,21 @@ namespace System return .Err(.NoResults); return .Ok(matched); } + + public virtual Result CreateObject() + { + return .Err; + } + + public virtual Result CreateValue() + { + return .Err; + } + + public virtual Result CreateValueDefault() + { + return .Err; + } } } @@ -59,5 +74,77 @@ namespace System.Reflection { return MethodInfo.Enumerator(this, bindingFlags); } + + public override Result CreateObject() + { + if (mTypeClassVData == null) + return .Err; + + MethodInfo methodInfo = default; + for (int methodId < mMethodDataCount) + { + let methodData = &mMethodDataPtr[methodId]; + if (!methodData.mFlags.HasFlag(.Constructor)) + continue; + if (methodData.mParamCount != 0) + continue; + + methodInfo = .(this, methodData); + break; + } + + if (!methodInfo.IsInitialized) + return .Err; + Object obj = Internal.Dbg_ObjectAlloc(mTypeClassVData, mInstSize, mInstAlign, 1); + + if (methodInfo.Invoke(obj) case .Err) + { + delete obj; + return .Err; + } + + return obj; + } + + public override Result CreateValue() + { + if (!IsValueType) + return .Err; + + MethodInfo methodInfo = default; + for (int methodId < mMethodDataCount) + { + let methodData = &mMethodDataPtr[methodId]; + if (!methodData.mFlags.HasFlag(.Constructor)) + continue; + if (methodData.mParamCount != 0) + continue; + + methodInfo = .(this, methodData); + break; + } + + if (!methodInfo.IsInitialized) + return .Err; + + void* data = new uint8[mInstSize]*; + + if (methodInfo.Invoke(data) case .Err) + { + delete data; + return .Err; + } + + return data; + } + + public override Result CreateValueDefault() + { + if (!IsValueType) + return .Err; + + void* data = new uint8[mInstSize]*; + return data; + } } }