示例#1
0
        static void Main(string[] args)
        {
            Console.WriteLine("started");

            dynamic ebscoObj = new DynamicJsonWrapper(Client.ebscoSample);

            Console.WriteLine("Id is " + ebscoObj.Id) ;

            //need to handle not existant values
            //var nothing = ebscoObj.Monkey;

            var members = ebscoObj.members;

            foreach (var item in members)
            {
                Console.WriteLine("Title : " + item.Title);
                Console.WriteLine("Abstract : " + item.Abstract);

                Console.WriteLine("--------");
            }

             //push the dynamic part into f#. have function that returns dynamic objects.

            Console.ReadKey();
        }
示例#2
0
        static void Main(string[] args)
        {
            Console.WriteLine("started");

            dynamic ebscoObj = new DynamicJsonWrapper(Client.ebscoSample);

            Console.WriteLine("Id is " + ebscoObj.Id);

            //need to handle not existant values
            //var nothing = ebscoObj.Monkey;

            var members = ebscoObj.members;

            foreach (var item in members)
            {
                Console.WriteLine("Title : " + item.Title);
                Console.WriteLine("Abstract : " + item.Abstract);

                Console.WriteLine("--------");
            }

            //push the dynamic part into f#. have function that returns dynamic objects.

            Console.ReadKey();
        }
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (_data == null)
            {
                result = "[error-json-document-is-null]";
                return(false);
            }

            var propertyName = binder.Name;

            if (propertyName == "Id")
            {
                propertyName = "@id";
            }

            if (propertyName == "Title")
            {
                propertyName = "dc.title";
            }


            if (propertyName == "Abstract")
            {
                propertyName = "fabio:abstract";
            }

            var temp = Client.getBetterGenericJsonValue(_data, propertyName);

            if (temp is JsonValue)
            {
                result = new DynamicJsonWrapper(temp as JsonValue);
                return(true);
            }

            if (temp is JsonValue[])
            {
                var array = temp as JsonValue[];
                result = array.Select(item => new DynamicJsonWrapper(item)).ToList();
                return(true);
            }

            result = temp;

            return(true);
        }
        public override bool TryGetMember(GetMemberBinder binder, out object result)
        {
            if (_data == null)
            {
                result = "[error-json-document-is-null]";
                return false;
            }

            var propertyName = binder.Name;

            if (propertyName == "Id")
                propertyName = "@id";

            if (propertyName == "Title")
                propertyName = "dc.title";

            if (propertyName == "Abstract")
                propertyName = "fabio:abstract";

            var temp = Client.getBetterGenericJsonValue(_data, propertyName);

            if (temp is JsonValue)
            {
                result = new DynamicJsonWrapper(temp as JsonValue);
                return true;
            }

            if (temp is JsonValue[])
            {
                var array = temp as JsonValue[];
                result = array.Select(item => new DynamicJsonWrapper(item)).ToList();
                return true;
            }

            result = temp;

            return true;
        }