XMLIgnore Atribute

G

Guest

A while back I posted this:
http://msdn.microsoft.com/newsgroup...ools-vcsharp&lang=en&cr=US&sloc=en-us&m=1&p=1

Well, I never did get the built-in XML Serialization method working so I
wrote my own. I use Reflection to work its way through my complex object
and "manually" write out what I need to do. It works great.

I'm now expanding my XML Save method to write out a bunch of system-type
properties. But some of them I don't actually want to write out. So I stuck
the [XMLIgnore] attribute before those I want to ignore. But I can't figure
out what to look for in the Reflection code to spot those properties that are
so labelled.

Does anyone know precisely what field(s) this attribute changes within a
Property structure?
 
N

Nicholas Paldino [.NET/C# MVP]

Robert,

You will want to call the GetCustomAttributes method on the PropertyInfo
representing the property. You can pass typeof(XMLIgnore) to the method,
and it will return the attribute if it exists on the property.

Hope this helps.
 
G

Guest

Nicholas,

Thank you, thank you, thank you!!! A few lines of code and IT WORKS!!!

I struggled with this for HOURS!!!! I still don't understand why I wasn't
able to "see" the presence of the XMLIgnore attribute when I used QuickWatch
during Reflection. I clearly was looking at the PropertyInfo object but
could not see any difference between those properties I had so marked and
those with no attributes.

The mysteries of dotNet!!!!

Once again, thank you! You just made the sun rise in my day!

--
Robert W.
Vancouver, BC
www.mwtech.com



Nicholas Paldino said:
Robert,

You will want to call the GetCustomAttributes method on the PropertyInfo
representing the property. You can pass typeof(XMLIgnore) to the method,
and it will return the attribute if it exists on the property.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Robert W. said:
A while back I posted this:
http://msdn.microsoft.com/newsgroup...ltools-vcsharp〈=en&cr=US&sloc=en-us&m=1&p=1

Well, I never did get the built-in XML Serialization method working so I
wrote my own. I use Reflection to work its way through my complex object
and "manually" write out what I need to do. It works great.

I'm now expanding my XML Save method to write out a bunch of system-type
properties. But some of them I don't actually want to write out. So I
stuck
the [XMLIgnore] attribute before those I want to ignore. But I can't
figure
out what to look for in the Reflection code to spot those properties that
are
so labelled.

Does anyone know precisely what field(s) this attribute changes within a
Property structure?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top