Forum Discussion

amarr1143l's avatar
amarr1143l
Contributor
9 years ago

Base class of custom object

Hi,

 

Is it possibile to get standard base class of custom object using any property? ClrClassName will give me the custom class name to which the object belongs which might be extended/ inhertied from a standard class. e.g. the application has extended Java Button class as ExtendedButton. So, my ClrClassName will give me ExtendedButton. However, I want to know if there is any property which can give me the base class name i.e. JButton.

3 Replies

  • HKosova's avatar
    HKosova
    SmartBear Alumni (Retired)

    For .NET, use obj.GetBase().BaseType.Name (or .FullName for the full class name including the assembly name).

    For Java, use obj.getClass().getSuperclass().getSimpleName(), (or .getName() for the full class name including the package name).

     

     

    Here's an example that logs a .NET object's base class chain, up to System.Object:

     

    function Test()
    { var obj = Sys.Process("Orders").WinFormsObject("MainForm"); // Log the object's base class chain var baseType = obj.GetType(); do { Log.Message(baseType.FullName); baseType = baseType.BaseType; }
    while (baseType != null); } 

     

    • amarr1143l's avatar
      amarr1143l
      Contributor

      Thank you, Helen! This is exactly what I am doing at this point of time in my code. However, as the original post suggests, I am looking for a property which I can retrieve from NameMapping or Object Browser which gives me this information without having to call a routine which returns it.

       

      Is it possibile to set this piece of code returning me a value and assigning it to all the objects as custom default property?

      • HKosova's avatar
        HKosova
        SmartBear Alumni (Retired)

        Unfortunately, TestComplete doesn't support defining custom properties on objects.

         

        Could you clarify what exactly you are trying to achieve here? This sounds like an XY problem to me.