views:

42

answers:

1

Hey everyone,

I whould like to creat a serialization mechanism, to work on a variety of entities, all of which are based on a few base-classes. Now I want to work with DataContractSerializer, so I need to mark all my classes with [DataContract]. but I dont want to do that because that is a big room for error for other members of my team. instead I want to place a singel attribute on my base-class(es), and not to worry about every calss I add.

I would actually prefer to inherit from [DataContract], should I ever wish to change the mechanism I will need to change only my inheriting attribute and not all my classes (the same goes for the [DataMember]). Now the problem is that DataContractAttribute is a seald class.

I thought up 3 solution, but i dont know how to implement any of them...

First, I heard a rommer that there is a way to inherit from a seald class, that will be greate and save me a lot of fuzz.

Second, I know that with reflection it's possible to change a class in runtime and re-compile back to runtime, so I thought to create my on attribute and at runtime replace all my custom attribute with
[DataContract]

Third, to use some sort of pre-compile tool that will replace my attribute with [DataContract]

So if you have an idea how to implement any of these three (first and third preferred), or if you have an other idea it'll be great.

Thank you.

A: 

umm.... don't do that. just don't. trust me.

Mentor team members and use the framework as designed. You will get much more mileage.

word....

Sky Sanders
It's more then that.i need to be able to change the mechanism reletivly easy,starting to add\remove\replace all the entites attribute is just to comlicated and leave to mauch room for error, I rather hava one place withe realy nasty code that lots of places with not so pretty code.Thats why if i could use my own attribute I could define it in own place, use it all over the code, and if I need to change it in the future i could go specifcly to that class defintion, and not have to serch every singel attribute in the code...
Matan Liberman
good luck with that.
Sky Sanders