概要
方法
GetClass(className: string,filter: Dictionary):ReflectedClass? |
GetClasses(filter: Dictionary):{ReflectedClass} |
GetEventsOfClass(className: string,filter: Dictionary):{ReflectedEvent} |
GetMethodsOfClass(className: string,filter: Dictionary):{ReflectedMethod} |
GetPropertiesOfClass(className: string,filter: Dictionary):{ReflectedProperty} |
代码示例
ReflectionService 概述
local ReflectionService = game:GetService("ReflectionService")
-- 创建一个具有所有能力的 SecurityCapabilities 对象
local allCapabilities = SecurityCapabilities.new(table.unpack(Enum.SecurityCapability:GetEnumItems()))
-- 获取所有可访问的类,具有所有能力
local allClasses = ReflectionService:GetClasses({ Security = allCapabilities })
print("总类数:", #allClasses)
-- 获取特定类
local partClass = ReflectionService:GetClass("Part")
if partClass then
print("\nPart 类:")
print(" 名称:", partClass.Name)
print(" 超类:", partClass.Superclass and tostring(partClass.Superclass) or "无")
end
-- 获取类的前 5 个属性
local properties = ReflectionService:GetPropertiesOfClass("Part", { Security = allCapabilities })
print("\nPart 属性:", #properties)
for i = 1, math.min(5, #properties) do
print(" -", properties[i].Name)
endAPI 参考
方法
GetClass
参数
| 默认值:"nil" |
返回
ReflectedClass?
GetClasses
参数
| 默认值:"nil" |
返回
{ReflectedClass}
GetEventsOfClass
参数
| 默认值:"nil" |
返回
{ReflectedEvent}
GetMethodsOfClass
参数
| 默认值:"nil" |
返回
{ReflectedMethod}
GetPropertiesOfClass
参数
| 默认值:"nil" |
返回
{ReflectedProperty}