我有以下类,我试图从ExportFileBaseBL类调用Compare方法,但我得到错误
无法将类型'Class1'隐式转换为'T'.存在显式转换(您是否错过了演员?)
public abstract class Class1<T> where T: Class2
{
public abstract Class1<T> Compare(Class1<T> otherObj);
}
public abstract class Class3<T, U> where T: Class1<U>
where U: Class2
{
public T Compare(T obj1, T obj2)
{
if (obj1.Prop1 > obj2.Prop1)
{
return obj1.Compare(obj2); // Compiler Error here
}
else
{
return obj2.Compare(obj1); // Compiler Error here
}
}
}
Run Code Online (Sandbox Code Playgroud)
类型转换不应该隐含吗?我错过了什么吗?
我有两个类和一个web方法如下
[Serializable]
public class BaseClass
{
public int Key;
public bool IsModified;
public bool IsNew;
public bool IsDeleted;
}
[Serializable]
public class DerivedClass : BaseClass
{
public string Name;
}
[WebMethod]
public List<DerivedClass> GetDerivedClassObjects()
{
}
Run Code Online (Sandbox Code Playgroud)
但是当我看到SOAP响应时,我没有看到基类中的字段.它们不应该被序列化吗?如果我希望它们被序列化应该做什么?