C# 序列化引用的类对象 //Reference.cs //凸序列化 [System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“4.0.30319.225”)] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute(“代码”)] [System.Xml.Serialization.XmlTypeAttribute(Namespace=“urn:schemas sc jp:mfp:osa-1-1”)] 公共部分类凭据\u类型:凭据\u基本\u类型{ 私有字符串数据类型字段; 私有不透明数据类型元数据字段; /// [System.Xml.Serialization.XmlElementAttribute(“数据类型”)] 公共字符串数据类型{ 得到{ 返回this.datatypeField; } 设置{ this.datatypeField=值; } } /// 公共不透明数据类型元数据{ 得到{ 返回this.metadataField; } 设置{ this.metadataField=值; } } } /// [System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“4.0.30319.225”)] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute(“代码”)] [System.Xml.Serialization.XmlTypeAttribute(Namespace=“urn:schemas sc jp:mfp:osa-1-1”)] 公共部分类不透明\u数据\u类型{ private System.Xml.xmlement[]anyField; private System.Xml.xmldattribute[]anyAttrField; /// [System.Xml.Serialization.XmlAnyElementAttribute()] public System.Xml.xmlement[]任何{ 得到{ 返回这个.anyField; } 设置{ this.anyField=值; } } /// [System.Xml.Serialization.XmlAnyAttributeAttribute()] public System.Xml.xmldattribute[]AnyAttr{ 得到{ 返回此.anyAttrField; } 设置{ this.anyAttrField=值; } } }

C# 序列化引用的类对象 //Reference.cs //凸序列化 [System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“4.0.30319.225”)] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute(“代码”)] [System.Xml.Serialization.XmlTypeAttribute(Namespace=“urn:schemas sc jp:mfp:osa-1-1”)] 公共部分类凭据\u类型:凭据\u基本\u类型{ 私有字符串数据类型字段; 私有不透明数据类型元数据字段; /// [System.Xml.Serialization.XmlElementAttribute(“数据类型”)] 公共字符串数据类型{ 得到{ 返回this.datatypeField; } 设置{ this.datatypeField=值; } } /// 公共不透明数据类型元数据{ 得到{ 返回this.metadataField; } 设置{ this.metadataField=值; } } } /// [System.CodeDom.Compiler.GeneratedCodeAttribute(“System.Xml”,“4.0.30319.225”)] [System.SerializableAttribute()] [System.Diagnostics.DebuggerStepThroughAttribute()] [System.ComponentModel.DesignerCategoryAttribute(“代码”)] [System.Xml.Serialization.XmlTypeAttribute(Namespace=“urn:schemas sc jp:mfp:osa-1-1”)] 公共部分类不透明\u数据\u类型{ private System.Xml.xmlement[]anyField; private System.Xml.xmldattribute[]anyAttrField; /// [System.Xml.Serialization.XmlAnyElementAttribute()] public System.Xml.xmlement[]任何{ 得到{ 返回这个.anyField; } 设置{ this.anyField=值; } } /// [System.Xml.Serialization.XmlAnyAttributeAttribute()] public System.Xml.xmldattribute[]AnyAttr{ 得到{ 返回此.anyAttrField; } 设置{ this.anyAttrField=值; } } },c#,.net,serialization,xml-serialization,asmx,C#,.net,Serialization,Xml Serialization,Asmx,我有一个webmethod,它从网络上的设备获取数据,其中一部分数据是用于授权设备的凭据 我们正在使用一个API,因此要接收此数据,我必须在webmethod中将凭证类型作为参数类型。我需要做的是保存这些数据,这样就可以在不使用webmethod的情况下获取这些数据 现在我以前已经将类序列化为XML文件,所以我使用了熟悉的选项,但只使用了我自己创建的类我想知道,对于一个不是我的引用类,是否真的可以做同样的事情? 我必须创建一个与凭据类型匹配的类并跨多个类型复制数据,但我还没有找到在不同类型之间转

我有一个webmethod,它从网络上的设备获取数据,其中一部分数据是用于授权设备的凭据

我们正在使用一个API,因此要接收此数据,我必须在webmethod中将凭证类型作为参数类型。我需要做的是保存这些数据,这样就可以在不使用webmethod的情况下获取这些数据

现在我以前已经将类序列化为XML文件,所以我使用了熟悉的选项,但只使用了我自己创建的类我想知道,对于一个不是我的引用类,是否真的可以做同样的事情?

我必须创建一个与凭据类型匹配的类并跨多个类型复制数据,但我还没有找到在不同类型之间转换的方法

“CREDENTAILS_类型”来自一个MFP,因此在我的情况下反射和更改代码是没有好处的,因为我无论如何都无法更新它


有什么建议吗?

既然你不能修改一个你没有源代码的类,那就用你需要的序列化属性创建你自己的DTO,然后用它在这两个类之间来回传输字段数据。

为什么这个类是“你的”还是“你的”很重要?“我的”到底是什么意思?我的,比如我可以访问源代码,并且可以更改和重新编译它们。我的问题是,为什么你认为你必须修改它?当我尝试它时,它不起作用。我已经把它修好了,不需要修改>\u>你是怎么修好的?如果您的修复程序对其他人有帮助,您应该将其添加为答案,我将向上投票。谢谢您,Automapper看起来可能正符合我的要求。:)因为这是我想要的,所以我不需要它。
// Reference.cs
// Conveintly serializable
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:schemas-sc-jp:mfp:osa-1-1")]
public partial class CREDENTIALS_TYPE : CREDENTIALS_BASE_TYPE {

    private string datatypeField;

    private OPAQUE_DATA_TYPE metadataField;

    /// <remarks/>
    [System.Xml.Serialization.XmlElementAttribute("data-type")]
    public string datatype {
        get {
            return this.datatypeField;
        }
        set {
            this.datatypeField = value;
        }
    }

    /// <remarks/>
    public OPAQUE_DATA_TYPE metadata {
        get {
            return this.metadataField;
        }
        set {
            this.metadataField = value;
        }
    }
}

/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.225")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="urn:schemas-sc-jp:mfp:osa-1-1")]
public partial class OPAQUE_DATA_TYPE {

    private System.Xml.XmlElement[] anyField;

    private System.Xml.XmlAttribute[] anyAttrField;

    /// <remarks/>
    [System.Xml.Serialization.XmlAnyElementAttribute()]
    public System.Xml.XmlElement[] Any {
        get {
            return this.anyField;
        }
        set {
            this.anyField = value;
        }
    }

    /// <remarks/>
    [System.Xml.Serialization.XmlAnyAttributeAttribute()]
    public System.Xml.XmlAttribute[] AnyAttr {
        get {
            return this.anyAttrField;
        }
        set {
            this.anyAttrField = value;
        }
    }
}