예제 #1
0
        /// <summary>
        /// Returns an object as a dynamic object. Use this to convert from an anonymous type parameter to a dynamic object.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static dynamic ToDynamic(this Object obj)
        {
            if (obj == null)
            {
                return(null);
            }

            dynamic value = new AgileObject();

            Type objectType = obj.GetType();

            foreach (var property in objectType.GetProperties())
            {
                var propertyName  = property.Name;
                var propertyValue = property.GetValue(obj, null);

                ((IDictionary <string, object>)value)[propertyName] = propertyValue;
            }

            foreach (var field in objectType.GetFields())
            {
                var fieldName  = field.Name;
                var fieldValue = field.GetValue(obj);

                ((IDictionary <string, object>)value)[fieldName] = fieldValue;
            }

            return(value);
        }
예제 #2
0
        /// <summary>
        /// Returns an object as a dynamic object. Use this to convert from an anonymous type parameter to a dynamic object.
        /// </summary>
        /// <param name="obj"></param>
        /// <returns></returns>
        public static dynamic ToDynamic(this Object obj)
        {
            if (obj == null)
                return null;

            dynamic value = new AgileObject();

            Type objectType = obj.GetType();

            foreach (var property in objectType.GetProperties())
            {
                var propertyName = property.Name;
                var propertyValue = property.GetValue(obj, null);

                ((IDictionary<string, object>)value)[propertyName] = propertyValue;
            }

            foreach (var field in objectType.GetFields())
            {
                var fieldName = field.Name;
                var fieldValue = field.GetValue(obj);

                ((IDictionary<string, object>)value)[fieldName] = fieldValue;
            }

            return value;
        }
예제 #3
0
파일: NSQProtocol.cs 프로젝트: 40a/NSQnet
        public void Identify(String short_id, String long_id, Int32 heartbeat_interval, Boolean feature_negotiation)
        {
            dynamic json = new AgileObject();
            json.short_id = short_id;
            json.long_id = long_id;
            json.heartbeat_interval = heartbeat_interval;
            json.feature_negotiation = feature_negotiation;

            var jsonText = JsonSerializer.Current.SerializeObject(json);
            WriteAscii("IDENTIFY\n");
            WriteBinary(PackMessage(jsonText));
        }