小编log*_*ik6的帖子

C#泛型 - 从泛型类调用泛型方法

我有以下类,我试图从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)

类型转换不应该隐含吗?我错过了什么吗?

c# generics casting explicit

5
推荐指数
1
解决办法
570
查看次数

从ASMX Web方法返回派生类对象时,为什么我的基类字段没有被序列化?

我有两个类和一个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响应时,我没有看到基类中的字段.它们不应该被序列化吗?如果我希望它们被序列化应该做什么?

c# web-services asmx

5
推荐指数
1
解决办法
2520
查看次数

标签 统计

c# ×2

asmx ×1

casting ×1

explicit ×1

generics ×1

web-services ×1