[quoted text, click to view] On Jul 31, 12:43 pm, Bruce Wood <brucew...@canada.com> wrote:
> On Jul 30, 9:00 pm, jan.lou...@gmail.com wrote:
>
>
>
> > On Jul 31, 11:52 am, Bruce Wood <brucew...@canada.com> wrote:
>
> > > On Jul 30, 8:47 pm, jan.lou...@gmail.com wrote:
>
> > > > Hi,
> > > > We're building a mapping application and inside we're using open
> > > > source dll called MapServer. This dll uses object model that has quite
> > > > a few classes. In our app we however need to little bit modify come of
> > > > the classes so they match our purpose better - mostly add a few
> > > > methods etc.
> > > > Example: Open source lib has classes Map and Layer defined. The
> > > > relationship between them is one to many.
> > > > We created our own versions (inherited) of Map called OurMap and our
> > > > version of Layer called OurLayer. The only difference between them is
> > > > that they have some extra methods (because we need them to do little
> > > > bit extra).
> > > > Is there any way how can I convert the base class (either Map or
> > > > Layer) to our inherited one (OurMap or OurLayer)?
> > > > I know that implicit or explicit conversion operators don't work
> > > > between inherited and base class
>
> > > Who told you that? It's certainly not true. C# allows you to write
> > > your own conversion operator, either implicit or explicit, that copies
> > > the members from your base class object into a new, derived class
> > > object, and return the derived object.
>
> > > The only hitch, of course, is that you end up with a copy, but there's
> > > no way around that.
>
> > When I try that the compiler complains:
> > C:\MapServer\IntraMaps60\SpatialEngineWS\Layers
> > \IntraMapsLayer.cs(208): 'DMS.IntraMaps.IntraMapsLayer.implicit
> > operator DMS.IntraMaps.IntraMapsLayer(layerObj)': user-defined
> > conversion to/from base class
> > I googled it and I found some articles that you cannot implicitly
> > convert from base class to it's child.
> > Am I doing something wrong?
>
> Could you post the code you wrote? Both your definition of the
> implicit conversion operator and your use of it?
This is my inherited class:
public class IntraMapsLayer : layerObj
{
public IntraMapsLayer(superMapObj map) : base (map)
{
this.currentSuperMapObj = map;
}
public static implicit operator IntraMapsLayer(layerObj layer)
{
IntraMapsLayer newLayer = new IntraMapsLayer(this.map);
newLayer.bandsitem = layer.bandsitem;
newLayer.classitem = layer.classitem;
newLayer.connection = layer.connection;
newLayer.connectiontype = layer.connectiontype;
newLayer.data = layer.data;
newLayer.debug = layer.debug;
newLayer.dump = layer.dump;
//newLayer.extent = layer.extent;
newLayer.filteritem = layer.filteritem;
newLayer.footer = layer.footer;
newLayer.group = layer.group;
newLayer.header = layer.header;
//newLayer.index = layer.index;
newLayer.labelangleitem = layer.labelangleitem;
newLayer.labelcache = layer.labelcache;
newLayer.labelitem = layer.labelitem;
newLayer.labelmaxscale = layer.labelmaxscale;
newLayer.labelminscale = layer.labelminscale;
newLayer.labelrequires = layer.labelrequires;
newLayer.labelsizeitem = layer.labelsizeitem;
//newLayer.map = layer.map;
newLayer.maxfeatures = layer.maxfeatures;
newLayer.maxscale = layer.maxscale;
//newLayer.metadata = layer.metadata;
newLayer.minscale = layer.minscale;
newLayer.name = layer.name;
//newLayer.numclasses = layer.numclasses;
//newLayer.numitems = layer.numitems;
//newLayer.numjoins = layer.numjoins;
//newLayer.numprocessing = layer.numprocessing;
newLayer.offsite = layer.offsite;
newLayer.plugin_library = layer.plugin_library;
newLayer.plugin_library_original = layer.plugin_library_original;
newLayer.postlabelcache = layer.postlabelcache;
newLayer.requires = layer.requires;
newLayer.sizeunits = layer.sizeunits;
newLayer.status = layer.status;
newLayer.styleitem = layer.styleitem;
newLayer.symbolscale = layer.symbolscale;
newLayer.template = layer.template;
newLayer.tileindex = layer.tileindex;
newLayer.tileitem = layer.tileitem;
newLayer.tolerance = layer.tolerance;
newLayer.toleranceunits = layer.toleranceunits;
newLayer.transform = layer.transform;
newLayer.transparency = layer.transparency;
newLayer.type = layer.type;
newLayer.units = layer.units;
return newLayer;
}
this implicit operator does not even compile. I haven't mentioned it
yet but we're bound to .NET 1.1 unfortunatelly