我需要一个包装类来公开实体类ProfileEntity
的一些属性。无法执行转换
我试着从这个实体派生出来,然后创建返回特定实体属性的属性,但它说我不能从ProfileEntity
投到ProfileEntityWrapper
。
当我尝试将返回一个'ProfileEntity'的方法的返回值放入包装中时,我得到上述错误。
如何创建这样一个可浇注的包装类?
例
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!!!
}
}
你能表现出一定的代码? class a:b {}可以让你做(a)b;你不需要做(b)a;因为a已经是b @ – 2010-03-09 10:43:53
@Rune FS:添加了一些示例代码 – 2010-03-09 10:49:43
,因为SomeMethod返回ProfileEntity的实例,但不是ProfileEntityWrapper的实例。 – garik 2010-03-09 11:12:51