【问题标题】:Lua / LuaInterface - How to access C# Attributes?Lua / LuaInterface - 如何访问 C# 属性?
【发布时间】:2011-05-09 07:05:57
【问题描述】:

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

我知道我可以实现一个普通的 C# 方法,并在该方法中使用普通的反射访问属性,然后在 Lua 对象上执行 registerMethod。

但在这种情况下,我不想编写 C# 方法,而只是使用 Lua 代码编写一个普通字符串,然后访问属性。

我的问题是怎么做?是做类似的事情的正确方法

require 'CLRPackage'
import "System.Reflection"

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

【问题讨论】:

    标签: c# attributes lua luainterface


    【解决方案1】:

    我知道这有点旧,但我能够让它与这样的东西一起工作:

    > 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
    

    【讨论】:

    • 谢谢!自从我写这篇文章以来,我还没有玩过 LUA,但如果我最终这样做了,我会试试你的东西 =)
    猜你喜欢
    • 2023-03-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-08-06
    • 2013-12-07
    • 1970-01-01
    相关资源
    最近更新 更多