2012-04-17 64 views
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; 
     } 
    } 
} 

我有一個webmethod從網絡上的設備獲取數據,這部分數據是用於授權與設備的憑據。序列化引用的類對象

我們正在使用API​​,因此爲了接收此數據,我必須將CREDENTIALS_TYPE作爲webmethod中的參數類型。我需要做的是保存這些數據,所以可以在沒有webmethod的情況下獲得。

現在我已將序列化到XML文件之前,所以我去熟悉的選項,但只有我自己創建的類。 我想知道是否真的有可能對一個不是我的引用類做同樣的事情?

我必須創建一個匹配CREDENTIALS_TYPE的類並複製數據,但我一直無法找到在不同類型之間進行轉換的方法。

「CREDENTAILS_TYPE」來自MFP,因此反映和更改代碼在我的情況下並不好,因爲我無法更新它。

任何建議/意見?

+0

爲什麼這個班級是「你的」還是沒有?什麼是「我的」甚至_mean_? – 2012-04-17 16:46:00

+0

Mine,因爲我可以訪問源代碼並可以更改並重新編譯它們。 – Amicable 2012-04-18 08:18:17

+1

我的問題是,你爲什麼認爲你必須修改它? – 2012-04-18 13:54:24

回答

1

由於您無法修改您不擁有源代碼的類,因此您需要使用序列化屬性創建您自己的DTO,然後使用Automapper在兩者之間來回傳輸字段數據。

+0

謝謝你,Automapper看起來像它可能做我正在尋找的東西。 :) – Amicable 2012-04-18 08:23:59

+0

接受,因爲這是我正在尋找,我只是不需要它。 – Amicable 2012-04-19 09:10:28