See More On StackoverflowGive More Feedback

Well in your initial post you said 'I'm trying to serialize Nullable types and don't want to show the element if it is null.' So based on that we have suggested a way to serialize a nullable type as an element if the value is not null and not to show the element if it is null. Now you seem to have changed your requirement and want an attribute. As far as I can tell that is not possible with the approach taken so far, the nullable (.NET) type is mapped to a complex schema type and an attribute always needs to have a simple schema type. MVP Data Platform Development.

Yes, that was my main intent to show/hide an element. I guess I was trying to fix 2 of my problems within the same thread. 1.) element = Which your solution seems to fix it. 2.) attribute = still working on. I was thinking that they would be a little similar to finding the answer. When it comes to the attribute show/hide. I have a couple of sceanrios.

XmlElementAttribute.IsNullable Property. Gets or sets a value that indicates whether the XmlSerializer must serialize a member that is set to null as an empty. XmlElementAttribute.IsNullable Property. Gets or sets a value that indicates whether the XmlSerializer must serialize a member that is set to null as an empty. Nov 05, 2011 XML Serialization Nullable Types. Public double? Well in your initial post you said 'I'm trying to serialize Nullable types and don't want to.

1.) I have an int? Same as the element. If null = don't show, if some value = show. If I use an int, then it will always be some value ( i.e. I='0' which 0 could be a valid value).

2.) I have an enum? ( example below ). Again, same logic. If null, then don't show. If valule present, then show ( i.e myEnum='do something' ).

Anurag Gandhi is a Developer, Consultant, Architect, Blogger, and a Speaker. He is passionate about programming. He is extensively involved in Asp.Net Core, MVC/Web API, Microsoft Azure/Cloud, web application hosting/architecture, Angular, AngularJs, design and development.

His languages of choice are C#, Node/Express, JavaScript, Asp.NET MVC, Asp, C, C++. He is familiar with many other programming languages as well. Naruto Episode 44 Subtitle Indonesia Oh. He mostly works with MS Sql Server as the preferred database and has worked with Redis, MySQL, Oracle, MS Access, etc. He is active in programming communities and loves to share the knowledge with others whenever he gets the time for it.

He is also a passionate chess player. He can be contacted at: soft.gandhi@gmail.com.

KP Lee 9-Dec-14 16:37 9-Dec-14 16:37 When boxing a nullable field into a non-nullable field, it is critical that the boxed item isn't null before trying to box the non-null field or try-catch handles the problem. You should supply the consequences of ignoring that requirement in your article. For instance, outside of a try block executing int? Tst = null; int tst2 = ( int)tst; results in: An unhandled exception of type ' System.InvalidOperationException' occurred in mscorlib.dll Additional information: Nullable object must have a value.Not executing this in a debug session might lose even more information on what went wrong. There are plenty of other boxing errors that should be pre-checked. Like byte x = (byte) 354; There are plenty of articles in CodeProject that are a rehash of documentation and information in books. If you are using them in your article, it should reference the exact sources you used, but I don't mind a re-hash of something I already know about.

BeeGone 16-Oct-14 5:54 16-Oct-14 5:54 1. Never Post Untested Code. You cannot initialize the fields in a struct. You should always write code with clearness and fullness especially when you pretend to be teaching others.

treeburan – 2018