Re: [Vala] How to get the base class name with out the spacename?



3ks to your help....

best regards....

在 2015年11月16日 16:02, Daniel Espinosa 写道:

From LibreSCL source, at

https://github.com/powerwaremediacore/librescl/blob/master/librescl/Serializable.vala

You always know your class prefix because the name space, in your case
PlatformX, Then just use:

nname = get_type ().name ();

      if ("Lsclt" in nname)

        nname = nname.replace ("Lsclt","");

this is, from the type name get a string and replace the prefix (name
space) with nothing, and you'll get your class name.

El nov. 15, 2015 8:04 PM, "Matrix" <pigex zhang gmail com
<mailto:pigex zhang gmail com>> escribió:

    i'm implementing a simple ORM model,  which will crate the table refer
    to the class name


    namespace PlatformX {
        public class User () {
                .....// with create a database table named user or users
        }
    }



    在 2015年11月16日 02:24, Al Thomas 写道:
    >> From: Matrix <pigex zhang gmail com <mailto:pigex zhang gmail com>>
    >> Sent: Sunday, 15 November 2015, 14:45
    >> Subject: [Vala] How to get the base class name with out the
    spacename?
    >>
    >> Hi :
    >>
    >> i want to get the base class name with out the spacename
    >>
    >> for example :
    >>
    >> namespace PlatformX {
    >>     public class User () {
    >>             this.get_type().name();
    >>     }
    >> }
    >>
    >> the name is PlatformXUser not User .....
    >>
    >> any methods to query this ?
    >
    > Why would you want to do that?
    >
    > Class names should be for programming, not presenting nicely
    formatted strings.
    > It makes sense to prepend the namespace. This avoids any name
    conflict with another
    > class of the same name, but in a different namespace.
    >
    > If you are looking to create multiple classes of the same name,
    but each doing
    > things in a different way, then you want to be using interfaces.
    That way each
    > class has a unique class name, but the interface it implements
    is the same name.
    > This is how you achieve polymorphism in Vala. There is then
    nothing stopping you
    > from using the interface name as the type in a methods
    parameters. This allows
    > you to pass different classes of object to the method, so long
    as they implement
    > the common interface.
    >
    > Hope that makes sense,
    >
    > Al

    _______________________________________________
    vala-list mailing list
    vala-list gnome org <mailto:vala-list gnome org>
    https://mail.gnome.org/mailman/listinfo/vala-list




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]