mercredi 4 juillet 2018

How can i create anonymous object property from a string

I want to create anonymous object with property which send as a string. Is that possible with reflection or something (from string to anonymous property)

 class Program
    {
        static void Main(string[] args)
        {

            object myobject = CreateAnonymousObjectandDoSomething("myhotproperty");
        }

        public static object CreateAnonymousObjectandDoSomething(string myproperystring)
        {
            //how can i create anonymous object from myproperystring
            return new { myproperystring = "mydata" }; //this is wrong !!
            // i want to create object like myhotproperty ="mydata"
        }
    }





Aucun commentaire:

Enregistrer un commentaire