private static bool TryCreate2ComponentType( List <Type> components, out Internal.TypeInfo typeInfo) { if (components.Count == 2) { if (IsListType(components[0]) && components[1].IsValueType) { typeInfo = new Internal.TypeInfo(components[1], t => new ListType(new NonNullType(t))); return(true); } if (IsListType(components[0]) && IsPossibleNamedType(components[1])) { typeInfo = new Internal.TypeInfo(components[1], t => new ListType(t)); return(true); } if (IsNullableType(components[0]) && components[1].IsValueType) { typeInfo = new Internal.TypeInfo(components[1], t => t); return(true); } } typeInfo = default; return(false); }
private static bool TryCreate3ComponentType( List <Type> components, out Internal.TypeInfo typeInfo) { if (components.Count == 3 && IsListType(components[0]) && IsNullableType(components[1]) && components[2].IsValueType) { typeInfo = new Internal.TypeInfo(components[2], t => new ListType(t)); return(true); } typeInfo = default; return(false); }
public bool TryCreate(Type type, out Internal.TypeInfo typeInfo) { if (type == null) { throw new ArgumentNullException(nameof(type)); } if (CanHandle(type)) { List <Type> components = DecomposeType(type); if (components.Any() && (TryCreate3ComponentType(components, out typeInfo) || TryCreate2ComponentType(components, out typeInfo) || TryCreate1ComponentType(components, out typeInfo))) { return(true); } } typeInfo = default; return(false); }