小编GDS*_*GDS的帖子

如何在WCF中使用DataContract/DataMember序列化Func <int,int>(甚至是一般委托)类型字段

我正在尝试序列化Func<int, int>标记有[DataMember]类的标记的字段[DataContract],其目标或Lambda表达式定义也是合同的一部分,或者甚至可以在类本身中.

我正在使用一个自定义DataContractResolver,当我取消标记该Func字段时,它非常有效,但是当我标记它时,它不能解析System.DelegateSerializationHolder序列化所需的类型.我试图将此类型添加到我的自定义,DataContractResolver但我无法在系统命名空间中找到它.

我可以在[OnDeserialized]每个使用这个类的客户端类的方法中重新定义它,但是每次我使用这个类时我都需要这样做,当然我想避免(客户端类也是其中的一部分DataContract).

此序列化暂时用于将应用程序的状态保存到磁盘,因此保存委托(甚至是我不感兴趣的事件)具有逻辑意义,因为它是对象图的所有部分.

那么如何Func<int, int>使用WCF对其进行序列化DataContract呢?

c# wcf serialization

8
推荐指数
1
解决办法
4568
查看次数

C#6.0多个相同的空条件运算符检查与单个传统检查

在主要性能和易用性或清晰度等方面,以下两种等效方式对于零条件运算符最佳?

这个:

idString = child?.Id;
fatherName = child?.Father?.Name;
motherName = child?.Mother?.Name;
Run Code Online (Sandbox Code Playgroud)

或者(假设所有本地变量都已为空)这:

if (child != null)
{
    idString = child.Id;
    fatherName = child.Father?.Name;
    motherName = child.Mother?.Name;    
}
Run Code Online (Sandbox Code Playgroud)

性能甚至是一个问题吗?

c# c#-6.0 null-conditional-operator

8
推荐指数
1
解决办法
1028
查看次数

当派生类型为1作为参数传递时,双向隐式可转换类型的重载之间的模糊调用

(试图找到一个总结问题的标题可能是一项非常艰巨的任务!)

我有以下类与一些重载方法,产生一个调用歧义编译器错误:

public class MyClass
{
    public static void OverloadedMethod(MyClass l) { }
    public static void OverloadedMethod(MyCastableClass l) { }

    //Try commenting this out separately from the next implicit operator. 
    //Comment out the resulting offending casts in Test() as well.
    public static implicit operator MyCastableClass(MyClass l)
    {
        return new MyCastableClass();
    }

    //Try commenting this out separately from the previous implicit operator.
    //Comment out the resulting offending casts in Test() as well.
    public static implicit operator MyClass(MyCastableClass l)
    {
        return new …
Run Code Online (Sandbox Code Playgroud)

c# overloading ambiguous implicit-cast

6
推荐指数
1
解决办法
785
查看次数