Lua / LuaInterface - 如何访问 C# 属性?

我一直在寻找一种方法,使得在Lua脚本中我能够访问类的自定义属性。

我知道可以实现一个普通的C#方法,在其中使用普通的Reflection访问Attribute,然后在Lua对象上进行registerMethod。

但在这种情况下,我不想编写一个C#方法,而只是编写一个带有Lua代码的普通字符串,通过它来访问Attribute。

我的问题是如何做到这一点?是像这样做对吗?

require 'CLRPackage'
import "System.Reflection"

typeOfObject = type(myClrObject)
typeOfObject.GetCustomAttribute(...)
-- something more...

原文链接 https://stackoverflow.com/questions/4168696

点赞
stackoverflow用户95573
stackoverflow用户95573

我知道这有些旧了,但我能够通过以下方式使它工作:

> require 'CLRPackage'
> import "System"
> int_type = Type.GetType("System.Int32")
> attrs = int_type:GetCustomAttributes(true)
> for i=0,attrs.Length-1 do Console.WriteLine(attrs:GetValue(i)) end
System.SerializableAttribute
System.Runtime.InteropServices.ComVisibleAttribute
2011-08-23 21:19:09