|
Hello. I am sorry to post this here, because it is
a question not regarding mono specifically but c# in general, but i did not find
answers to my question anywhere else.
I would like to serialize a class that has the
following structure (this is an abstraction)
public var1;
public var2;
public type;
where one instance of this class can only have var1
or var2 instantiated. Therefore I introduced variable type. So
I can know which variable is currently the right one (i.e. type=var1 or
type=var2).
When it comes to serialization, i would like to get
only the "used" variable serialized (i.e if type=var1 then I would like to have
onle var1 serialized, and not both)
So far i have found that in order to serialize a
class i could prepend the [Serializable] attribute to my class, and it
would serialize every public variable. In order not to get variable type
serialized, i could prepend the [XmlIgnore] attribute and that would do the job;
but how can i tell that one variable should get serialized based on the contents
of another variable of an instance of my class. I was thinking of something
like...
[if this.type="var2" then XmlIgnore]
public var1;
[if this.type="var1" then XmlIgnore]
public var2;
but of course this does not work at
all.
If anyone out there knows a hint to give me, I
would really apreciate it.
With regards, (and apologizing for my
english)
Ricardo Kirkner
|
- Re: [Mono-list] c# serialization Ricardo Kirkner
- Re: [Mono-list] c# serialization A Rafael D Teixeira
- RE: [Mono-list] c# serialization Elan Feingold
- Re: [Mono-list] c# serialization Ricardo Kirkner
- Re: [Mono-list] c# serialization A Rafael D Teixeira
