Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to AddProperty to a C# class at runtime
Message
De
29/07/2007 03:31:59
 
 
À
29/07/2007 00:56:08
Information générale
Forum:
ASP.NET
Catégorie:
Web Services
Divers
Thread ID:
01243387
Message ID:
01244410
Vues:
26
Bernard,

You are taking the demo code too seriously.

The XML code you refer to from the sample has nothing to do with anything - I just left it in for good measure (effectively to show you how to build an XML document in .NET and load it from a generic dictionary - a tutorial, for want of a better expression).

>2. The other code uses a File based stream and Deserializes it. Again I don't want to have anything file based.

This code, again, is demo code only. It is a way for you to test the class and prove to yourself that it will serialize and then deserialize, without having to rig it up in a web service. Over here, I don't have your web service. So, to ensure that the new class works, the simplest way to test it is to serialize it to/from a simple disk based file.

All you need is code similar to the following in your web method :-
            ...

            PropertyWrapper wrapper = new PropertyWrapper();

            // Add a few properties to it.
            wrapper.AddProperty("Name", "Bernard Bout");
            wrapper.AddProperty("DOB", Convert.ToDateTime("01/01/1970"));
            wrapper.AddProperty("Phone", "+44 161 777 5555");
            wrapper.AddProperty("Email", "bernard@someplace.com");
            return wrapper;
If you decide to run the test to and from the file, you can satisfy yourself that the class is in fact serializable. Thereafter, treat it as any other serializable .NET class in so far as your web method is concerned.
-=Gary
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform