【问题标题】:How to implement introspection on RealBasic?如何在 RealBasic 上实现自省?
【发布时间】:2012-12-11 14:41:50
【问题描述】:

RealBasic 的 Introspection 与我的预期有些不同。

我的意图是:

创建一个 MainObject,其他对象将从中继承两三个方法,以进行简化。

Method 1-> Returns to the child class itself all of its properties, types and values.

Method 2-> Would call Method1 and with the information, save the child Object.

因此,对于方法 1,我考虑编写一个通用的内省,它可以为每个子类轻松返回方法 2 完成工作所需的内容。

我为什么要这个?因此,我可以让数十个对象知道如何保存、绘制自己,而不必过多担心在此处或那里修改属性等...

但是使用 RealBasic 教程和参考提供的东西是行不通的,因为它需要我让它发生在对象等之外......即:我可以很容易地在 ObjectA 内部获取 ObjectB 的属性、方法等,但我想要进入 ObjectA,A 的属性,而不是 B 的

提前谢谢...

【问题讨论】:

    标签: oop introspection realbasic


    【解决方案1】:

    我发现了如何...非常简单,创建 MainClass 并在其中创建一个简单的方法 WhoAmI,它可以返回数组、字典等...

      Dim thisClassTypeInfo As Introspection.TypeInfo = Introspection.GetType(Self)
    
      Dim thisClassProperties() As Introspection.PropertyInfo = thisClassTypeInfo.GetProperties
    
      Dim thisClassMethods() As Introspection.MethodInfo = thisClassTypeInfo.GetMethods
    
    
      For Each myProperty As Introspection.PropertyInfo In thisClassProperties
    
    // Then here use myProperty.Name, myProperty.Value(Self).StringValue
    // or myProperty.Value(Self).anyotheroption and create a dictionary 
    // or array with the results and return it.
    
      Next
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-19
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 1970-01-01
      • 2011-01-30
      • 2018-05-24
      • 2016-08-18
      相关资源
      最近更新 更多