private static bool TryConvertLeafValue( ITypeConversion converter, IHasClrType leafType, object value, out object scalarValue) { try { if (value is null) { scalarValue = value; return(true); } if (!leafType.ClrType.IsInstanceOfType(value)) { return(converter.TryConvert( typeof(object), leafType.ClrType, value, out scalarValue)); } scalarValue = value; return(true); } catch { scalarValue = null; return(false); } }
private static bool IsOfTypeWithClrType( IHasClrType objectType, object result) { if (result == null) { return(true); } return(objectType.ClrType.IsInstanceOfType(result)); }
private object EnsureClrTypeIsCorrect(IHasClrType type, object value) { if (type.ClrType != typeof(object) && value.GetType() != type.ClrType && _converter.TryConvert(value.GetType(), type.ClrType, value, out object converted)) { return(converted); } return(value); }