Creating a castable entity class wrapper

Posted by Tony on Stack Overflow See other posts from Stack Overflow or by Tony
Published on 2010-03-09T10:40:59Z Indexed on 2010/03/09 10:51 UTC
Read the original article Hit count: 437

Filed under:
|
|

Hi

I need to have a wrapper class that exposes some properties of my entity class called ProfileEntity.

I tried doing it by deriving from this entity and then creating properties that return specific entity properties, but it says I cannot cast from ProfileEntity to ProfileEntityWrapper.

When I try to put the return values of a method that returns a 'ProfileEntity' into the wrapper I get the above error.

How do I create such a wrapper class that is castable?

Example

class ProfileEntityWrapper : ProfileEntity
{

public string Name
{
  get
  {
     return this.ProfileEntityName;
  }
}

public class Someclass
{

  public ProfileEntity SomeMethod()
  {
     return ProfileEntity; // example of method returning this object
  }

}

public class SomeOtherlClass
{

   SomeClass sc = new SomeClass();

  public void DoSomething()
  {
    ProfileEntityWrapper ew = (ProfileEntityWrapper)sc.SomeMethod(); // Cannot do this cast!!!
   }

}

© Stack Overflow or respective owner

Related posts about c#

Related posts about wrapper