/// <summary>
        /// Creates properties for the given <see cref="JsonContract"/>.
        /// </summary>
        /// <param name="type">The type to create properties for.</param>
        /// /// <param name="memberSerialization">The member serialization mode for the type.</param>
        /// <returns>Properties for the given <see cref="JsonContract"/>.</returns>
        protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
        {
            List <MemberInfo> members = GetSerializableMembers(type);

            if (members == null)
            {
                throw new JsonSerializationException("Null collection of seralizable members returned.");
            }

            JsonPropertyCollection properties = new JsonPropertyCollection(type);

            foreach (MemberInfo member in members)
            {
                JsonProperty property = CreateProperty(member, memberSerialization);

                if (property != null)
                {
                    properties.AddProperty(property);
                }
            }

            IList <JsonProperty> orderedProperties = properties.OrderBy(p => p.Order ?? -1).ToList();

            return(orderedProperties);
        }
        /// <summary>
        /// Creates the constructor parameters.
        /// </summary>
        /// <param name="constructor">The constructor to create properties for.</param>
        /// <param name="memberProperties">The type's member properties.</param>
        /// <returns>Properties for the given <see cref="ConstructorInfo"/>.</returns>
        protected virtual IList <JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties)
        {
            var constructorParameters = constructor.GetParameters();

            JsonPropertyCollection parameterCollection = new JsonPropertyCollection(constructor.DeclaringType);

            foreach (ParameterInfo parameterInfo in constructorParameters)
            {
                JsonProperty matchingMemberProperty = memberProperties.GetClosestMatchProperty(parameterInfo.Name);
                // type must match as well as name
                if (matchingMemberProperty != null && matchingMemberProperty.PropertyType != parameterInfo.ParameterType)
                {
                    matchingMemberProperty = null;
                }

                JsonProperty property = CreatePropertyFromConstructorParameter(matchingMemberProperty, parameterInfo);

                if (property != null)
                {
                    parameterCollection.AddProperty(property);
                }
            }

            return(parameterCollection);
        }
        protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
        {
            List <MemberInfo> serializableMembers = this.GetSerializableMembers(type);

            if (serializableMembers == null)
            {
                throw new JsonSerializationException("Null collection of seralizable members returned.");
            }
            JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(type);

            using (List <MemberInfo> .Enumerator enumerator = serializableMembers.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    MemberInfo   current      = enumerator.get_Current();
                    JsonProperty jsonProperty = this.CreateProperty(current, memberSerialization);
                    if (jsonProperty != null)
                    {
                        jsonPropertyCollection.AddProperty(jsonProperty);
                    }
                }
            }
            return(Enumerable.ToList <JsonProperty>(Enumerable.OrderBy <JsonProperty, int>(jsonPropertyCollection, delegate(JsonProperty p)
            {
                int?order = p.Order;
                return (!order.get_HasValue()) ? -1 : order.get_Value();
            })));
        }
        protected virtual IList <JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties)
        {
            ParameterInfo[]        parameters             = constructor.GetParameters();
            JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(constructor.DeclaringType);

            foreach (ParameterInfo parameterInfo in parameters)
            {
                JsonProperty jsonProperty = memberProperties.GetClosestMatchProperty(parameterInfo.Name);
                if (jsonProperty != null && jsonProperty.PropertyType != parameterInfo.ParameterType)
                {
                    jsonProperty = null;
                }
                JsonProperty jsonProperty2 = this.CreatePropertyFromConstructorParameter(jsonProperty, parameterInfo);
                if (jsonProperty2 != null)
                {
                    jsonPropertyCollection.AddProperty(jsonProperty2);
                }
            }
            return(jsonPropertyCollection);
        }
Beispiel #5
0
        protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
        {
            List <MemberInfo> serializableMembers = this.GetSerializableMembers(type);

            if (serializableMembers == null)
            {
                throw new JsonSerializationException("Null collection of seralizable members returned.");
            }
            JsonPropertyCollection propertyCollection = new JsonPropertyCollection(type);

            foreach (MemberInfo member in serializableMembers)
            {
                JsonProperty property = this.CreateProperty(member, memberSerialization);
                if (property != null)
                {
                    propertyCollection.AddProperty(property);
                }
            }
            return((IList <JsonProperty>)Enumerable.ToList <JsonProperty>((IEnumerable <JsonProperty>)Enumerable.OrderBy <JsonProperty, int>((IEnumerable <JsonProperty>)propertyCollection, (Func <JsonProperty, int>)(p => p.Order ?? -1))));
        }
        protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
        {
            List <MemberInfo> serializableMembers = GetSerializableMembers(type);

            if (serializableMembers == null)
            {
                throw new JsonSerializationException("Null collection of seralizable members returned.");
            }
            JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(type);

            foreach (MemberInfo item in serializableMembers)
            {
                JsonProperty jsonProperty = CreateProperty(item, memberSerialization);
                if (jsonProperty != null)
                {
                    jsonPropertyCollection.AddProperty(jsonProperty);
                }
            }
            return(jsonPropertyCollection.OrderBy((JsonProperty p) => p.Order ?? (-1)).ToList());
        }
        protected virtual IList <JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties)
        {
            ParameterInfo[]        parameters = constructor.GetParameters();
            JsonPropertyCollection propertys  = new JsonPropertyCollection(constructor.DeclaringType);

            foreach (ParameterInfo info in parameters)
            {
                JsonProperty matchingMemberProperty = (info.Name != null) ? memberProperties.GetClosestMatchProperty(info.Name) : null;
                if ((matchingMemberProperty != null) && (matchingMemberProperty.PropertyType != info.ParameterType))
                {
                    matchingMemberProperty = null;
                }
                JsonProperty property = this.CreatePropertyFromConstructorParameter(matchingMemberProperty, info);
                if (property != null)
                {
                    propertys.AddProperty(property);
                }
            }
            return(propertys);
        }
Beispiel #8
0
        protected virtual IList <JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties)
        {
            ParameterInfo[]        parameters         = constructor.GetParameters();
            JsonPropertyCollection propertyCollection = new JsonPropertyCollection(constructor.DeclaringType);

            foreach (ParameterInfo parameterInfo in parameters)
            {
                JsonProperty matchingMemberProperty = parameterInfo.Name != null?memberProperties.GetClosestMatchProperty(parameterInfo.Name) : (JsonProperty)null;

                if (matchingMemberProperty != null && matchingMemberProperty.PropertyType != parameterInfo.ParameterType)
                {
                    matchingMemberProperty = (JsonProperty)null;
                }
                JsonProperty constructorParameter = this.CreatePropertyFromConstructorParameter(matchingMemberProperty, parameterInfo);
                if (constructorParameter != null)
                {
                    propertyCollection.AddProperty(constructorParameter);
                }
            }
            return((IList <JsonProperty>)propertyCollection);
        }
Beispiel #9
0
        protected virtual IList <JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties)
        {
            ParameterInfo[]        parameters             = constructor.GetParameters();
            JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(constructor.DeclaringType);

            ParameterInfo[] parameterInfoArray = parameters;
            for (int i = 0; i < (int)parameterInfoArray.Length; i++)
            {
                ParameterInfo parameterInfo        = parameterInfoArray[i];
                JsonProperty  closestMatchProperty = memberProperties.GetClosestMatchProperty(parameterInfo.Name);
                if (closestMatchProperty != null && closestMatchProperty.PropertyType != parameterInfo.ParameterType)
                {
                    closestMatchProperty = null;
                }
                JsonProperty jsonProperty = this.CreatePropertyFromConstructorParameter(closestMatchProperty, parameterInfo);
                if (jsonProperty != null)
                {
                    jsonPropertyCollection.AddProperty(jsonProperty);
                }
            }
            return(jsonPropertyCollection);
        }
        /// <summary>
        /// Creates properties for the given <see cref="JsonObjectContract"/>.
        /// </summary>
        /// <param name="contract">The contract to create properties for.</param>
        /// <returns>Properties for the given <see cref="JsonObjectContract"/>.</returns>
        protected virtual IList <JsonProperty> CreateProperties(JsonObjectContract contract)
        {
            List <MemberInfo> members = GetSerializableMembers(contract.UnderlyingType);

            if (members == null)
            {
                throw new JsonSerializationException("Null collection of seralizable members returned.");
            }

            JsonPropertyCollection properties = new JsonPropertyCollection(contract);

            foreach (MemberInfo member in members)
            {
                JsonProperty property = CreateProperty(contract, member);

                if (property != null)
                {
                    properties.AddProperty(property);
                }
            }

            return(properties);
        }
        protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
        {
            List <MemberInfo> serializableMembers = this.GetSerializableMembers(type);

            if (serializableMembers == null)
            {
                throw new JsonSerializationException("Null collection of seralizable members returned.");
            }
            JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(type);

            foreach (MemberInfo member in serializableMembers)
            {
                JsonProperty jsonProperty = this.CreateProperty(member, memberSerialization);
                if (jsonProperty != null)
                {
                    jsonPropertyCollection.AddProperty(jsonProperty);
                }
            }
            return(jsonPropertyCollection.OrderBy(delegate(JsonProperty p)
            {
                int?order = p.Order;
                return (order == null) ? -1 : order.Value;
            }).ToList <JsonProperty>());
        }
        protected virtual IList <JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
        {
            List <MemberInfo> serializableMembers = this.GetSerializableMembers(type);

            if (serializableMembers == null)
            {
                throw new JsonSerializationException("Null collection of seralizable members returned.");
            }
            JsonPropertyCollection source = new JsonPropertyCollection(type);

            foreach (MemberInfo info in serializableMembers)
            {
                JsonProperty property = this.CreateProperty(info, memberSerialization);
                if (property != null)
                {
                    source.AddProperty(property);
                }
            }
            if (func_3 == null)
            {
                func_3 = new Func <JsonProperty, int>(DefaultContractResolver.smethod_8);
            }
            return(source.OrderBy <JsonProperty, int>(func_3).ToList <JsonProperty>());
        }