Reflection on constructors.. How to access method of new variant?

About Monkey 2 Forums Monkey 2 Programming Help Reflection on constructors.. How to access method of new variant?

This topic contains 4 replies, has 2 voices, and was last updated by  jondecker76 1 day, 21 hours ago.

Viewing 5 posts - 1 through 5 (of 5 total)

  • Author
    Posts
  • #15986

    jondecker76

    Participant

    I’m finally to the point where I can create new class instances using reflection…

    However, I’m stuck, as now I can’t do anything with the new variant.  The variant.DyanmicType property does indeed report that I’ve created the class that I want.  However, I can’t access anything within the class from this point, as I then get an error about the variant not having the property or method…

    Simple sample:

    #15988

    Danilo

    Participant

    You can store any Object in a Variant, and because of that you have to tell Monkey2 what it is.

    With casting you can tell Monkey2 that instance.a is an instance of class A:

    [/crayon]

    Using that way you could use different classes that implement the same methods:

    [/crayon]

    #15990

    jondecker76

    Participant

    Thanks for the reply.

     

    I was afraid of that.  It seems like there is no way to get a true object from the reflection system and have it usable as a normal object (without heaping up piles of GetType..GetDecl..Invoke..Cast.. and making the code overly complex)

    I’m trying to build an XML parser that builds objects out of “skeleton” classes from the XML data.  But I wanted to do so without special cases and Casts, as there are literally hundreds of skeleton classes.  I just can’t find a way to build a true object from it’s name:String in monkey2.  I’m guessing that I’m just going to have to bite the bullet and write a custom loader for each and every one of the hundreds of object types.  Bummer

     

    For example, I just need to make a function that:

    instance:=ObjectFromName(“class_name”)

    #15991

    Danilo

    Participant

    Could you use the following?
    instance:=ObjectFromName<class_name>(“class_name”)

    Creating an object just from a string, without telling Monkey2 what it is, is probably very hard if possible at all.

    #15994

    jondecker76

    Participant

    I’m going to take a hybrid approach – I’ll have to make routines to match the appropriate skeleton class to the XMLString – but then I’ll use reflection to fill in the fields in the class.  At least I’m hoping this method will work

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.