jeudi 3 décembre 2015

Overloads New Method With Args

I've been build a large application that requires the need to overload the NEW method with args (Common I guess).

I have lots of properties in some classes and most if not all get overloaded in the new method. I wondered if there is a way to capture the arguments from the method and assign the values to the custom object by looking through the properties/args. All my property name within the class match the ones being passed as args in the method so matching the "name" properties should be possible???

OR a less taxing way of manually typing me.property = arg for each and every argument...

for example:

public class myClass
    property arg1 as string
    property arg2 as string
    property arg3 as string

    public sub new(arg1 as string, arg2 as string, arg3 as string)
        For each arg in methodbase.getcurrentmethod.getParameters
            custObj(<property name>).value = arg.value where custObj.name = arg.name
        end for
    end sub
end class

This isn't valid VB.net syntax is just an example of what I'm trying to achieve.





Aucun commentaire:

Enregistrer un commentaire