Example #1
0
        /// <summary>
        /// For real fun, combine HyperDynamo with a 
        /// HyperDictionary member provider for some
        /// JavaScript-like Prototype inhertance!
        /// </summary>
        public static void CombiningHyperDictionaryWithHyperDynamo(dynamic third)
        {
            Console.WriteLine("Using HyperDynamo with HyperDictionary MemberProvider to show\ndynamic mappings and inheritance!\n==================================================");

            dynamic dynoThird = new HyperDynamo(third);  //Manually use HyperDictionary with HyperDynamo
            dynoThird.toes = "third toes set through dynamic property";
            Console.WriteLine("eyes:\t{0}", dynoThird["eyes"]);
            Console.WriteLine("eyes:\t{0}", dynoThird.eyes);
            Console.WriteLine("toes:\t{0}", dynoThird["toes"]);
            Console.WriteLine("toes:\t{0}", dynoThird.toes);

            Console.WriteLine();
            try
            {
                //Should throw an exception since it got removed at this level
                Console.WriteLine("hair:\t{0}", dynoThird.hair);
            }
            catch (Microsoft.CSharp.RuntimeBinder.RuntimeBinderException rbe)
            {
                Console.WriteLine("EXPECTED EXCEPTION SINCE PROPERTY WAS REMOVED:\n{0}", rbe);
            }
            Pause();

            Console.WriteLine("Properties in the HyperDynamo object built off of 3 levels of HyperDictionary\ninheritance and a couple dynamic property setters\n========================================================================");
            DumpEnumerable(dynoThird);
            Pause();
        }
Example #2
0
        /// <summary>
        /// Show how even with a basic Dictionary member provider, 
        /// HyperDynamo is cooler than ExpandoObject
        /// </summary>
        private static void HyperDynamoGiveJSLikeSettersAndGettersAndForEach()
        {
            Console.WriteLine("Using HyperDynamo with Plain Dictionary MemberProvider\n==================================================");

            dynamic person = new HyperDynamo();
            person.FirstName = "Tony";
            person.LastName = "Heupel";
            person["MiddleInitial"] = "C";

            Console.WriteLine(person["FirstName"] + " " + person.MiddleInitial + ". " + person.LastName);

            DumpEnumerable(person);
            Pause();
        }