private static bool TryGetJsonPrimitiveConverter(ConverterSearchContext context, out IConverter converter) { bool isSuccess = false; if (context.SourceType == typeof(JToken) || context.SourceType == typeof(JValue)) { if (JsonPrimitiveConverter.Supported.Contains(context.TargetType)) { isSuccess = true; } } else if (context.TargetType == typeof(JToken) || context.TargetType == typeof(JValue)) { if (JsonPrimitiveConverter.Supported.Contains(context.SourceType)) { isSuccess = true; } } if (isSuccess) { converter = new JsonPrimitiveConverter(); } else { converter = null; } return(isSuccess); }
private static bool TryGetJsonObjectConverter(ConverterSearchContext context, out IConverter converter) { bool isSuccess = false; if (context.SourceType == typeof(JToken)) { if (context.TargetType.GetTypeInfo().IsClass&& !context.TargetType.GetTypeInfo().IsAbstract) { isSuccess = true; } } else if (context.TargetType == typeof(JToken)) { if (context.SourceType.GetTypeInfo().IsClass&& !context.SourceType.GetTypeInfo().IsAbstract) { isSuccess = true; } } if (isSuccess) { converter = new JsonObjectConverter(); } else { converter = null; } return(isSuccess); }
public bool TryFind(ConverterSearchContext context, out IConverter converter) { bool isSuccess = false; if (context.SourceType == typeof(JToken)) { if (context.TargetType.GetTypeInfo().IsEnum) { isSuccess = true; } else if (context.TargetType.IsNullableType() && context.TargetType.GetGenericArguments()[0].GetTypeInfo().IsEnum) { isSuccess = true; } } else if (context.TargetType == typeof(JToken)) { if (context.SourceType.GetTypeInfo().IsEnum) { isSuccess = true; } else if (context.SourceType.IsNullableType() && context.SourceType.GetGenericArguments()[0].GetTypeInfo().IsEnum) { isSuccess = true; } } if (isSuccess) { converter = new JsonEnumConverter(converterType); } else { converter = null; } return(isSuccess); }