Fix missing getter/setter methods attributes

This commit is contained in:
Wojtek Figat
2023-02-06 10:43:08 +01:00
parent 1ff49e1faf
commit 547f4d1180
3 changed files with 40 additions and 30 deletions

View File

@@ -60,8 +60,8 @@ namespace FlaxEngine
internal IntPtr name;
internal ManagedHandle getterHandle;
internal ManagedHandle setterHandle;
internal uint getterFlags;
internal uint setterFlags;
internal uint getterAttributes;
internal uint setterAttributes;
}
[StructLayout(LayoutKind.Sequential)]
@@ -1904,7 +1904,7 @@ namespace FlaxEngine
{
Type type = Unsafe.As<Type>(typeHandle.Target);
List<MethodInfo> methods = new List<MethodInfo>();
var methods = new List<MethodInfo>();
var staticMethods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
var instanceMethods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
foreach (MethodInfo method in staticMethods)
@@ -1912,11 +1912,11 @@ namespace FlaxEngine
foreach (MethodInfo method in instanceMethods)
methods.Add(method);
NativeMethodDefinitions* arr = (NativeMethodDefinitions*)NativeAlloc(methods.Count, Unsafe.SizeOf<NativeMethodDefinitions>());
var arr = (NativeMethodDefinitions*)NativeAlloc(methods.Count, Unsafe.SizeOf<NativeMethodDefinitions>());
for (int i = 0; i < methods.Count; i++)
{
IntPtr ptr = IntPtr.Add(new IntPtr(arr), Unsafe.SizeOf<NativeMethodDefinitions>() * i);
NativeMethodDefinitions classMethod = new NativeMethodDefinitions()
var classMethod = new NativeMethodDefinitions
{
name = NativeAllocStringAnsi(methods[i].Name),
numParameters = methods[i].GetParameters().Length,
@@ -1977,7 +1977,7 @@ namespace FlaxEngine
Type type = Unsafe.As<Type>(typeHandle.Target);
var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
NativePropertyDefinitions* arr = (NativePropertyDefinitions*)NativeAlloc(properties.Length, Unsafe.SizeOf<NativePropertyDefinitions>());
var arr = (NativePropertyDefinitions*)NativeAlloc(properties.Length, Unsafe.SizeOf<NativePropertyDefinitions>());
for (int i = 0; i < properties.Length; i++)
{
IntPtr ptr = IntPtr.Add(new IntPtr(arr), Unsafe.SizeOf<NativePropertyDefinitions>() * i);
@@ -1985,19 +1985,19 @@ namespace FlaxEngine
var getterMethod = properties[i].GetGetMethod(true);
var setterMethod = properties[i].GetSetMethod(true);
NativePropertyDefinitions classProperty = new NativePropertyDefinitions()
var classProperty = new NativePropertyDefinitions
{
name = NativeAllocStringAnsi(properties[i].Name),
};
if (getterMethod != null)
{
var getterHandle = GetMethodGCHandle(getterMethod);
classProperty.getterHandle = getterHandle;
classProperty.getterHandle = GetMethodGCHandle(getterMethod);
classProperty.getterAttributes = (uint)getterMethod.Attributes;
}
if (setterMethod != null)
{
var setterHandle = GetMethodGCHandle(setterMethod);
classProperty.setterHandle = setterHandle;
classProperty.setterHandle = GetMethodGCHandle(setterMethod);
classProperty.setterAttributes = (uint)setterMethod.Attributes;
}
Unsafe.Write(ptr.ToPointer(), classProperty);
}

View File

@@ -58,8 +58,8 @@ struct NativePropertyDefinitions
const char* name;
void* getterHandle;
void* setterHandle;
uint32 getterFlags;
uint32 setterFlags;
uint32 getterAttributes;
uint32 setterAttributes;
};
struct ClassAttribute
@@ -166,8 +166,13 @@ private:
int _monoType;
public:
CoreCLRClass(void* typeHandle, StringAnsi name, StringAnsi fullname, StringAnsi namespace_, uint32 typeAttributes, CoreCLRAssembly* image)
: _typeHandle(typeHandle), _name(name), _fullname(fullname), _namespace(namespace_), _typeAttributes(typeAttributes), _image(image)
CoreCLRClass(void* typeHandle, StringAnsi&& name, StringAnsi&& fullname, StringAnsi&& namespace_, uint32 typeAttributes, CoreCLRAssembly* image)
: _fullname(MoveTemp(fullname))
, _name(MoveTemp(name))
, _namespace(MoveTemp(namespace_))
, _typeAttributes(typeAttributes)
, _image(image)
, _typeHandle(typeHandle)
{
_typeToken = TypeTokenPool++;
_monoType = 0;
@@ -199,10 +204,8 @@ public:
{
if (_size != 0)
return _size;
uint32 align;
_size = mono_class_value_size((MonoClass*)this, &align);
return _size;
}
@@ -289,7 +292,8 @@ public:
CoreCLR::CallStaticMethod<void, void*, NativePropertyDefinitions**, int*>(GetClassPropertiesPtr, _typeHandle, &foundProperties, &numProperties);
for (int i = 0; i < numProperties; i++)
{
CoreCLRProperty* prop = New<CoreCLRProperty>(StringAnsi(foundProperties[i].name), foundProperties[i].getterHandle, foundProperties[i].setterHandle, foundProperties[i].getterFlags, foundProperties[i].setterFlags, this);
const NativePropertyDefinitions& foundProp = foundProperties[i];
CoreCLRProperty* prop = New<CoreCLRProperty>(StringAnsi(foundProp.name), foundProp.getterHandle, foundProp.setterHandle, foundProp.getterAttributes, foundProp.setterAttributes, this);
_properties.Add(prop);
CoreCLR::Free((void*)foundProperties[i].name);
@@ -369,8 +373,12 @@ private:
uint32 _methodAttributes;
public:
CoreCLRMethod(StringAnsi name, int numParams, void* methodHandle, uint32 flags, CoreCLRClass* klass)
:_name(name), _numParams(numParams), _methodHandle(methodHandle), _methodAttributes(flags), _class(klass)
CoreCLRMethod(StringAnsi&& name, int numParams, void* methodHandle, uint32 flags, CoreCLRClass* klass)
: _name(MoveTemp(name))
, _numParams(numParams)
, _class(klass)
, _methodHandle(methodHandle)
, _methodAttributes(flags)
{
_returnType = nullptr;
}
@@ -481,15 +489,16 @@ private:
CoreCLRMethod* _setMethod;
public:
CoreCLRProperty(StringAnsi name, void* getter, void* setter, uint32 getterFlags, uint32 setterFlags, CoreCLRClass* klass)
:_name(name), _class(klass)
CoreCLRProperty(StringAnsi&& name, void* getter, void* setter, uint32 getterAttributes, uint32 setterAttributes, CoreCLRClass* klass)
: _name(MoveTemp(name))
, _class(klass)
{
if (getter != nullptr)
_getMethod = New<CoreCLRMethod>(StringAnsi(_name + "Get"), 1, getter, getterFlags, klass);
_getMethod = New<CoreCLRMethod>(StringAnsi(_name + "Get"), 1, getter, getterAttributes, klass);
else
_getMethod = nullptr;
if (setter != nullptr)
_setMethod = New<CoreCLRMethod>(StringAnsi(_name + "Set"), 1, setter, setterFlags, klass);
_setMethod = New<CoreCLRMethod>(StringAnsi(_name + "Set"), 1, setter, setterAttributes, klass);
else
_setMethod = nullptr;
}
@@ -524,8 +533,11 @@ private:
CoreCLRClass* _attributeClass;
public:
CoreCLRCustomAttribute(StringAnsi name, void* handle, CoreCLRClass* owningClass, CoreCLRClass* attributeClass)
:_name(name), _handle(handle), _owningClass(owningClass), _attributeClass(attributeClass)
CoreCLRCustomAttribute(StringAnsi&& name, void* handle, CoreCLRClass* owningClass, CoreCLRClass* attributeClass)
: _name(MoveTemp(name))
, _handle(handle)
, _owningClass(owningClass)
, _attributeClass(attributeClass)
{
}
@@ -550,9 +562,8 @@ CoreCLRAssembly* GetAssembly(void* assemblyHandle)
CoreCLRClass* GetClass(void* type)
{
CoreCLRClass* klass;
if (classHandles.TryGet(type, klass))
return klass;
CoreCLRClass* klass = nullptr;
classHandles.TryGet(type, klass);
return nullptr;
}

View File

@@ -25,7 +25,6 @@ MMethod::MMethod(MonoMethod* monoMethod, const char* name, MClass* parentClass)
#endif
const uint32_t flags = mono_method_get_flags(monoMethod, nullptr);
_isStatic = (flags & MONO_METHOD_ATTR_STATIC) != 0;
switch (flags & MONO_METHOD_ATTR_ACCESS_MASK)
{