Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Feb 10, 2012 01:33 PM by kushalrdalal
Member
292 Points
516 Posts
Feb 10, 2012 12:25 PM|LINK
My class has several datamembers, but let's say a few of them end up being null or empty.
How can I set those particular members to [IgnoreDataMember] so that they're not exposed in the result?
Thanks.
Contributor
7130 Points
1273 Posts
Feb 10, 2012 12:45 PM|LINK
You do not have to make it ignore in order to not expose.
You can expose it and the client will not pass anything.
Like
<FirstName></FirstName>
You have to make sure that once it is returned by client before processing you check for null and do the needful.
Feb 10, 2012 12:48 PM|LINK
Thanks for your reply.
I cannot even display the xml tag. The member must not be displayed in the XML if the member is null or empty.
Feb 10, 2012 01:28 PM|LINK
I used
[DataMember(EmitDefaultValue = false)]
Feb 10, 2012 01:33 PM|LINK
As per microsoft they are not recommedning to use emitdefaultvalue= false.
Check this links -
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.emitdefaultvalue.aspx
http://stackoverflow.com/questions/5382402/why-is-using-datamemberemitdefaultvalue-false-not-recommended
vmhatup
Member
292 Points
516 Posts
Set [IgnoreDataMember] attribute dynamically?
Feb 10, 2012 12:25 PM|LINK
My class has several datamembers, but let's say a few of them end up being null or empty.
How can I set those particular members to [IgnoreDataMember] so that they're not exposed in the result?
Thanks.
kushalrdalal
Contributor
7130 Points
1273 Posts
Re: Set [IgnoreDataMember] attribute dynamically?
Feb 10, 2012 12:45 PM|LINK
You do not have to make it ignore in order to not expose.
You can expose it and the client will not pass anything.
Like
<FirstName></FirstName>
You have to make sure that once it is returned by client before processing you check for null and do the needful.
My Blog
LinkedIn Profile
vmhatup
Member
292 Points
516 Posts
Re: Set [IgnoreDataMember] attribute dynamically?
Feb 10, 2012 12:48 PM|LINK
Thanks for your reply.
I cannot even display the xml tag. The member must not be displayed in the XML if the member is null or empty.
vmhatup
Member
292 Points
516 Posts
Re: Set [IgnoreDataMember] attribute dynamically?
Feb 10, 2012 01:28 PM|LINK
I used
[DataMember(EmitDefaultValue = false)]
kushalrdalal
Contributor
7130 Points
1273 Posts
Re: Set [IgnoreDataMember] attribute dynamically?
Feb 10, 2012 01:33 PM|LINK
As per microsoft they are not recommedning to use emitdefaultvalue= false.
Check this links -
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.datamemberattribute.emitdefaultvalue.aspx
http://stackoverflow.com/questions/5382402/why-is-using-datamemberemitdefaultvalue-false-not-recommended
My Blog
LinkedIn Profile