How to derive from PointLatLng

Sep 1, 2010 at 12:03 PM

Hi,

I would to create some objects that are PointLatLng (i.e. : IDPointLatLng), with some adding properties, i.e. an ID string. I've discovered that PointLatLong is a struct, and I can't derive from a struct. Am I forced to do a composition class, or exists a different way to do it?

Thanks,

Cosimo.

Sep 1, 2010 at 1:19 PM

nope, don't think there is a different way. use a composite class.

Greetz Manuel

 

 

Sep 1, 2010 at 1:48 PM

Well, maybe I've found a simply alternative: the conversion operators. I'll try to make a CPointLatLng class that contains a PointLatLng, and to implement an operator like this:

struct CPointLatLng
{
    private PointLatLng _p;

    public CPointLatLng(double lat, double lng)
    {
        _p = new PointLatLng(lat, lng);
    }

    PointLatLng getPLL()
    {
         return _p;
    }

    public static implicit operator PointLatLng(CPointLatLng cp)
    {
         return cp.getPLL();
    }
}

So, if I've a function that request a PointLatLng, I can pass a CPointLatLng, and it will automagically converted to PointLatLong.

At that point, I can derive from CPointLatLng as I want. I'll try it.

 

http://msdn.microsoft.com/en-us/library/85w54y0a.aspx

Sep 2, 2010 at 7:33 AM

Ok, it seems working. Well, actually it's a composition, but the behaviour is like a polymorphic PointLatLng.

 

Cosimo.