views:

45

answers:

2

Ok, I am making a wrapper of a class that has very long path to get variables. By example, it has the following:

Class1.Location.Point.X
Class1.Location.Point.Y
Class1.Location.Point.Z
Class1.Location.Curve.get_EndPoint(0).X
Class1.Location.Curve.get_EndPoint(0).Y
Class1.Location.Curve.get_EndPoint(0).Z
Class1.Location.Curve.get_EndPoint(1).X
Class1.Location.Curve.get_EndPoint(1).Y
Class1.Location.Curve.get_EndPoint(1).Z

Now, in my wrapper, I would like to simplify it to this:

Wrapper.X
Wrapper.Y
Wrapper.Z
Wrapper.P0.X
Wrapper.P0.Y
Wrapper.P0.Z
Wrapper.P1.X
Wrapper.P1.Y
Wrapper.P1.Z

My wrapper look like about this:

public class Wrapper
{
    protected Class1 c1 = null
    public Wrapper(Class1 cc1)
    {
         c1 = cc1;
    }

    public int X
    {
            get{return C1.Location.Point.X;}
    }
    public int Y
    {
            get{return C1.Location.Point.Y;}
    }
    public int Z
    {
            get{return C1.Location.Point.Z;}
    }
}

Now my problem is the P0.X and cie. I don't know how to do it. I tried with a subclass, but it doesnt allow me to get access to my variable c1. How can I do this?

A: 

Well, I figured it out (it seems I need post a question here to figure out much of my stuff by myself).

Was rather basic stuff, I dont understand why I didnt figure it out faster.

I made a subclass Point0(Class1 c1) and added to my Wrapper a variable Point0 named point0 and a property named P0 that return point0, so it gives me Wrapper.P0.X

Wildhorn
A: 

Two ideas to get something similar to what you are looking for. You could implement an indexed property on Wrapper

class Wrapper{
  public int this[int index]{
    get{ return C1.Location.Curve.get_EndPoint(index); }
  }
}

This would leave the user calling this with something similar to:

Wrapper[0].X

Alternatively, if you really want to have the properties of "P0" and "P1", you can just make them return the object returned by get_EndPoint(int) (as Frederic suggested in his comment).

class Wrapper{
  public EndPoint P0{
    get{ return C1.Location.Curve.get_EndPoint(0); }
  }
}
drovani
Yeah, but there is like a million more stuff in get_EndPoint() and only needed/wanted the X,Y,Z for that wrapper. That is why. Like I said, the idea of this wrapper is to simplify a way too much complicated maze class.
Wildhorn