0
// 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;
        }
    }
}

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

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

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

我必须创建一个与 CREDENTIALS_TYPE 匹配的类并复制数据,但我无法找到在不同类型之间进行转换的方法。

The "CREDENTAILS_TYPE" is coming from an MFP, so reflecting and changing the code is no good in my situation because I couldn't update it anyway.

Any suggestions/advice?

4

1 回答 1

1

Since you can't modify a class you don't own the source code to, create your own DTO with the serialization attributes you require and then use Automapper to transfer the field data back and forth between the two.

于 2012-04-17T17:40:34.217 回答