added list comprehension
This commit is contained in:
1 parent
390d901463
commit
d009deea0e
1 file changed
+33
-7
@@ -232,13 +232,36 @@ namespace bts.websocket_core {
|
||||
cri = new SecurityCriteria(cls);
|
||||
return true;
|
||||
}
|
||||
public struct ListWrapper : IEnumerable<string> {
|
||||
public List<string> Lis { get; set; }
|
||||
public ListWrapper(List<string> l) {
|
||||
Lis = l;
|
||||
}
|
||||
|
||||
IEnumerator<string> IEnumerable<string>.GetEnumerator() {
|
||||
return Lis.GetEnumerator();
|
||||
}
|
||||
|
||||
System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() {
|
||||
return Lis.GetEnumerator();
|
||||
}
|
||||
}
|
||||
public static bool TryParse<T>(JObject filter, string key, out T[]? list, out string error) where T : struct {
|
||||
T? obj;
|
||||
if (TryParse<T>(filter, key, out obj, out error)) {
|
||||
list = obj == null ? null : new T[] { (T)(object)obj };
|
||||
T[] values = new T[] { };
|
||||
list = null;
|
||||
ListWrapper? wrap;
|
||||
if (TryParse<ListWrapper>(filter, key, out wrap, out error) && wrap != null) {
|
||||
foreach (var item in wrap) {
|
||||
T? obj;
|
||||
if (TryParse<T>(item, key, out obj, out error) && obj != null) {
|
||||
values = values.ToList().Append<T>((T)obj).ToArray();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
list = values;
|
||||
return true;
|
||||
}
|
||||
list = null;
|
||||
return false;
|
||||
}
|
||||
public static bool TryParse<T>(string value, string key, [NotNullWhen(true)] out T? obj, [NotNull] out string error) where T : struct {
|
||||
@@ -260,9 +283,12 @@ namespace bts.websocket_core {
|
||||
obj = (T)(object)value;
|
||||
return true;
|
||||
}
|
||||
if (typeof(T) == typeof(List<string>)) {
|
||||
|
||||
|
||||
if (typeof(T) == typeof(ListWrapper)) {
|
||||
if (!string.IsNullOrWhiteSpace(value) && value.Length > 1 && value[0] == '[' && value[-1] == ']') {
|
||||
value = value.Substring(1, value.Length - 2);
|
||||
obj = (T)(object)new ListWrapper((List<string>)value.Split(',').Select(v => v.Trim()));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (typeof(T) == typeof(DateTime) && DateTime.TryParseExact(value, "yyyy/MM/dd", CultureInfo.InvariantCulture,
|
||||
DateTimeStyles.None, out var dt)) {
|
||||
|
||||
Reference in new issue
Block a user