/// <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> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties) { ParameterInfo[] parameters = constructor.GetParameters(); JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(constructor.DeclaringType); ParameterInfo[] array = parameters; for (int i = 0; i < array.Length; i++) { ParameterInfo parameterInfo = array[i]; JsonProperty jsonProperty = (parameterInfo.Name != null) ? memberProperties.GetClosestMatchProperty(parameterInfo.Name) : null; if (jsonProperty != null && jsonProperty.PropertyType != parameterInfo.ParameterType) { jsonProperty = null; } if (jsonProperty != null || parameterInfo.Name != null) { JsonProperty jsonProperty2 = this.CreatePropertyFromConstructorParameter(jsonProperty, parameterInfo); if (jsonProperty2 != null) { jsonPropertyCollection.AddProperty(jsonProperty2); } } } return(jsonPropertyCollection); }
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); }
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); }
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); }