/// <summary> /// Resolves a parameter value based on the provided object. /// </summary> /// <param name="descriptor">Parameter descriptor.</param> /// <param name="value">Value to resolve the parameter value from.</param> /// <returns>The parameter value.</returns> public virtual object ResolveParameter(ParameterDescriptor descriptor, IJsonValue value) { if (descriptor == null) { throw new ArgumentNullException("descriptor"); } if (value == null) { throw new ArgumentNullException("value"); } if (value.GetType() == descriptor.ParameterType) { return value; } return value.ConvertTo(descriptor.ParameterType); }
public override object ResolveParameter(ParameterDescriptor descriptor, IJsonValue value) { if (value.GetType() == descriptor.ParameterType) return value; if (_valueField == null) _valueField = value.GetType().GetField("_value", BindingFlags.Instance | BindingFlags.NonPublic); var json = (string)_valueField.GetValue(value); using (var reader = new StringReader(json)) return _serializer.Deserialize(reader, descriptor.ParameterType); }