Ejemplo n.º 1
0
        private static void CreateAClassWithAccessorsInJSStyle()
        {
            Console.WriteLine("Using HyperHypo (HyperDynamo with HyperDictionary)\nand closures to create JavaScript-style object declarations\n==========================================================================");
            // Define the class as a function constructor and
            // private variables using closures.
            // NOTE: No overrides on constructor --
            //       to do this, move the definition out into
            //       static methods and just call them directly
            //       (see the Image and the global JS functions
            //       like Boolean in this project).
            dynamic Person = new Func<string, string, dynamic>(delegate(string firstName, string lastName)
            {
                var _firstName = firstName;
                var _lastName = lastName;

                dynamic p = new HyperHypo();
                p.getFirstName = new Func<dynamic>(delegate() { return _firstName; });
                p.getLastName = new Func<dynamic>(delegate() { return _lastName; });

                p.setFirstName = new Func<string, object>(value => _firstName = value);
                p.setLastName = new Func<string, object>(value => _lastName = value);

                p.toString = new Func<string>(delegate() { return String.Format("{0} {1}", _firstName, _lastName); });
                return p;
            });

            dynamic me = Person("Tony", "Heupel");
            dynamic singer = Person(null, null);

            singer.setFirstName("Paul");
            singer.setLastName("Hewson");

            OutputPeople(me, singer);
        }
Ejemplo n.º 2
0
 public HyperHypo(HyperHypo prototype)
 {
     this.MemberProvider = new HyperDictionary();
     Prototype = prototype;
 }
Ejemplo n.º 3
0
        /// <summary>
        /// Formalize a HyperDynamo using a HyperDictionary into a concrete class
        /// called HyperHypo (Hyper - more than C#; Hypo - less than JavaScript)
        /// </summary>
        private static void HelloHyperHypo()
        {
            Console.WriteLine("Using HyperDynamo with HyperDictionary membership provider\n==========================================================");

            Console.WriteLine("First example: prototype inheritance where only one.Whassup is set");
            dynamic one = new HyperHypo();
            one.Whassup = new Func<string>(SayHello);
            Console.WriteLine("one.Whassup(): {0}", one.Whassup());

            //two inherits from one (set's it's prototype)
            dynamic two = new HyperHypo(one);
            two.HowsItGoing = new Func<string, string>(name => String.Format("How's it going, {0}?", name));
            Console.WriteLine("two.Whassup(): {0}", two.Whassup());
            Console.WriteLine("two.HowsItGoing(\"buddy\"): {0}", two.HowsItGoing("buddy"));
            Pause();
        }