locked
Should I use Generic Type or just use string ? RRS feed

  • Question

  • User-2071549094 posted

    Hi experts,

    I am now stuck cos I do not know if I should use Generic or just string for the serialized model that is needed for my Web service.

    I have a Material Class so do I just bring in Material m or I have to separately use string MaterialName and do a get set ? or how ?

    Hope to hear from someone soon.

    Tks.

    Tuesday, January 24, 2017 9:49 AM

All replies

  • User-359936451 posted

    Generic type is for flexibility, if you are certain your variable will always be strongly typed, no reason not to.

    Wednesday, January 25, 2017 9:46 PM
  • User-2071549094 posted

    Hi march11,

    In this case, the DataMember annotation do I then add it on the Generic Type class there ?

    Or do I just bring in the class like this :

    [DataMember]
    Material material;

    And then I do not need to repeat all the fields in Material.

    Is that how it is done ?

    Hope to hear from you soon.

    Tks.

    Thursday, January 26, 2017 8:31 AM
  • User753101303 posted

    Hi,

    My understanding is that you have an object member inside another object? If you mark it with DataMember it will be serialized based on what you applied to the Material type. If you tried something, discuss directly the error or the bad behavior you see.

    Edit: and yes it's not related to WCF. If a member of a class is an object you just have available this exact class and all its members as part of the parent class.

    Thursday, January 26, 2017 8:47 AM