예제 #1
0
        static void MyTestExpando()
        {
            dynamic obj = new Expando()
            {
                { "clovo", "hello" },
                { "chislo", 42 },
                { "obect", new object() }
            };
            int value = obj.chislo;

            obj.chislo = 22;
            Console.WriteLine(value);
            Console.WriteLine(obj.clovo + " " + obj.chislo);
            obj.Add("ifelse", true);
            if (obj.ifelse)
            {
                Console.WriteLine("obj.ifelse = " + obj.ifelse);
            }
        }
        private static Object ToPersonalType(string str)
        {
            elementGlobal[0] = str;
            Dictionary <string, object> dictionaryInner = new Dictionary <string, object>();

            while ("}" != elementGlobal[0])
            {
                KeyValuePair <string, object> element = ElementPara();
                dictionaryInner.Add(element.Key, element.Value);
                if ("}" == elementGlobal[0] || "}]" == elementGlobal[0])
                {
                    break;
                }
                elementGlobal.RemoveAt(0);
            }
            dynamic dynamicObj = new Expando();

            foreach (var valueDictionary in dictionaryInner)
            {
                dynamicObj.Add(valueDictionary.Key, valueDictionary.Value);
            }
            return(dynamicObj);
        }