2010-11-12 32 views
1

嘿,我一直在尋找一種方式,讓我在Lua腳本中可以訪問一個類的自定義屬性。Lua/LuaInterface - 如何訪問C#屬性?

我知道我可以實現一個普通的C#方法,並在該方法中使用普通的Reflection訪問Attribute,然後在Lua對象上執行registerMethod。

但在這種情況下,我不想寫一個C#方法,只是寫一個普通的字符串與Lua代碼,並在那裏訪問屬性。

問題是怎麼做到的?是正確的方式來做類似

require 'CLRPackage' 
import "System.Reflection" 

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

任何提示? =)

回答

0

我知道這是有點老了,但我能得到這個像這樣的東西的工作:

> 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 
+0

THX!自從我寫這篇文章以來,我沒有玩過LUA,但如果我最終這樣做,我會嘗試你的事情=) – Ted 2011-08-24 10:54:01