Mixing custom and basic serialization?

后端 未结 1 1324
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-24 05:14

I\'ve got a class with well over 100 properties (it\'s a database mapping class) and one of the properties has to be in a method. In other words this data is not exposed via a p

相关标签:
1条回答
  • 2021-01-24 05:45

    The first thing I'd try is adding a property for serialization, but hiding it from the UI:

    [Browsable(false)] // hide in UI
    public SomeType ABC {
        get {return GetABC();}
        set {SetABC(value);}
    }
    

    You can't really mix and match serialization unfortunately; once you implement IXmlSerializable, you own everything. If you were using WCF, then DataContractSerialier supports non-public properties for serialization, so you could use:

    [DataMember]
    private SomeType ABC {
        get {return GetABC();}
        set {SetABC(value);}
    }
    

    but this doesn't apply for "asmx" web-services via XmlSerializer.

    Does the [Browsable] trick work at all? Assuming the custom grid uses TypeDescriptor, another option might be to hide it via ICustomTypeDescriptor, but that is a lot of work just to hide a property...

    0 讨论(0)
提交回复
热议问题