private void InitializeConstructorParameters(Dictionary <string, JsonPropertyInfo> propertyCache, ConstructorInfo constructorInfo) { ParameterInfo[] parameters = constructorInfo !.GetParameters(); Dictionary <string, JsonParameterInfo> parameterCache = CreateParameterCache(parameters.Length, Options); foreach (ParameterInfo parameterInfo in parameters) { PropertyInfo?firstMatch = null; bool isBound = false; foreach (JsonPropertyInfo jsonPropertyInfo in PropertyCacheArray !) { // This is not null because it is an actual // property on a type, not a "policy property". PropertyInfo propertyInfo = jsonPropertyInfo.PropertyInfo !; string camelCasePropName = JsonNamingPolicy.CamelCase.ConvertName(propertyInfo.Name); if (parameterInfo.Name == camelCasePropName && parameterInfo.ParameterType == propertyInfo.PropertyType) { if (isBound) { Debug.Assert(firstMatch != null); // Multiple object properties cannot bind to the same // constructor parameter. ThrowHelper.ThrowInvalidOperationException_MultiplePropertiesBindToConstructorParameters( Type, parameterInfo, firstMatch, propertyInfo, constructorInfo); } JsonParameterInfo jsonParameterInfo = AddConstructorParameter(parameterInfo, jsonPropertyInfo, Options); // One object property cannot map to multiple constructor // parameters (ConvertName above can't return multiple strings). parameterCache.Add(jsonPropertyInfo.NameAsString !, jsonParameterInfo); // Remove property from deserialization cache to reduce the number of JsonPropertyInfos considered during JSON matching. propertyCache.Remove(jsonPropertyInfo.NameAsString !); isBound = true; firstMatch = propertyInfo; } } } // It is invalid for the extension data property to bind with a constructor argument. if (DataExtensionProperty != null && parameterCache.ContainsKey(DataExtensionProperty.NameAsString !)) { ThrowHelper.ThrowInvalidOperationException_ExtensionDataCannotBindToCtorParam(DataExtensionProperty.PropertyInfo !, Type, constructorInfo); } ParameterCache = parameterCache; ParameterCount = parameters.Length; PropertyCache = propertyCache; }