Deserialize to self

前端 未结 4 661
灰色年华
灰色年华 2021-01-11 18:08

Ok, I\'m probably just having an epic fail here, but my mind wants to say this should work.

Assume DataProtect.DecryptData takes an encrypted string as input and a d

4条回答
  •  天命终不由人
    2021-01-11 18:28

    What you want is a static factory method that creates the object you require.

    class ArrivedDetails
    {
    ///...
    
        public static ArrivedDetails CreateFromEncryptedKey(string encrypted)
        {
            return DataProtect.deserializeXML(DataProtect.DecryptData(encrypted));
        }
    ///...
    

    The reason your initial approach didn't work is because this is a private read-only instance field that returns the object from which it is called. You can't write to this.

提交回复
热议问题