Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
C# - Create object from a string?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
VB 9.0
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Divers
Thread ID:
01308851
Message ID:
01309060
Vues:
7
Hi,

>I'm very new to C# so please forgive me if this is a really simple question.

Simple question but the only *simple* answer is 'No'

>Given the following code:
>
>string myString = "{fname='Joe', lname='Smith'}";
>
>
>Is there any way to use myString to actually instantiate an object with two properties (fname and lname)?
>
>I know I can do this:
>
>var myObject = new {fname='Joe', lname='Smith'};
>
The type will be defined at compile time (i.e. by the compiler). Maybe there's an alternative approach - anonymous types are pretty limiting anyway. Can you tell us a bit more about the context?
Regards,
Viv

>
>So I guess what I'm asking is, is there a way to dynamically use myString something like this: (I know this doesn't work but its here to give an idea of what I'm wanting to do)
>
>var myObject = new (myString);
>
>
>Thanks for your help!
>
>Rodd
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform