|
@@ -29,47 +29,6 @@ namespace InABox.Core
|
|
|
SQLite
|
|
|
}
|
|
|
|
|
|
- //public class DateTimeJsonConverter : JsonConverter<DateTime>
|
|
|
- //{
|
|
|
-
|
|
|
- // public override void WriteJson(JsonWriter writer, DateTime value, JsonSerializer serializer)
|
|
|
- // {
|
|
|
- // String result = String.Format("{0:o}", value);
|
|
|
- // writer.WriteValue(result);
|
|
|
- // }
|
|
|
-
|
|
|
- // public override DateTime ReadJson(JsonReader reader, Type objectType, DateTime existingValue, bool hasExistingValue, JsonSerializer serializer)
|
|
|
- // {
|
|
|
- // if (reader.Value is DateTime)
|
|
|
- // return (DateTime)reader.Value;
|
|
|
- // else
|
|
|
- // {
|
|
|
- // String value = reader.Value.ToString().Replace("\"","");
|
|
|
- // DateTime.TryParse(value, out DateTime result);
|
|
|
- // return result;
|
|
|
- // }
|
|
|
- // }
|
|
|
-
|
|
|
- // public override bool CanRead => true;
|
|
|
- // public override bool CanWrite => true;
|
|
|
- //}
|
|
|
-
|
|
|
- //public class TimeSpanJsonConverter : JsonConverter<TimeSpan>
|
|
|
- //{
|
|
|
-
|
|
|
- // public override void WriteJson(JsonWriter writer, TimeSpan value, JsonSerializer serializer)
|
|
|
- // {
|
|
|
- // TimeSpan timespan = (TimeSpan)value;
|
|
|
- // writer.WriteValue(timespan.Ticks.ToString());
|
|
|
- // }
|
|
|
-
|
|
|
- // public override TimeSpan ReadJson(JsonReader reader, Type objectType, TimeSpan existingValue, bool hasExistingValue, JsonSerializer serializer)
|
|
|
- // {
|
|
|
- // Int64 ticks = Int64.Parse(reader.Value.ToString().Replace("\"", ""));
|
|
|
- // return new TimeSpan(ticks);
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
public enum SyncfusionVersion
|
|
|
{
|
|
|
v16_3,
|
|
@@ -1422,24 +1381,25 @@ namespace InABox.Core
|
|
|
public static Columns<T> GetColumns<T>(Columns<T>? columns)
|
|
|
=> (GetColumns(typeof(T), columns) as Columns<T>)!;
|
|
|
|
|
|
+ /// <summary>
|
|
|
+ /// Ensures that <paramref name="columns"/> is not <see langword="null"/>, by setting it to <b>all</b> columns that are
|
|
|
+ /// writable, serializable and persistable if it is.<br/>
|
|
|
+ /// If <paramref name="columns"/> is not <see langword="null"/>, it is returned unchanged.
|
|
|
+ /// </summary>
|
|
|
public static IColumns GetColumns(Type T, IColumns? columns)
|
|
|
{
|
|
|
- //var cols = columns;
|
|
|
if (columns == null || columns.Count == 0)
|
|
|
{
|
|
|
if (!_columnscache.TryGetValue(T, out var result))
|
|
|
{
|
|
|
result = Columns.None(T);
|
|
|
- var props = PropertyList(T,
|
|
|
- x =>
|
|
|
- x.GetCustomAttribute<DoNotSerialize>() == null &&
|
|
|
- x.GetCustomAttribute<DoNotPersist>() == null &&
|
|
|
- x.CanWrite && x.PropertyType != typeof(UserProperties), true);
|
|
|
- foreach (var prop in props)
|
|
|
- result.Add(prop.Key);
|
|
|
- var custom = DatabaseSchema.Properties(T).Where(x => x is CustomProperty);
|
|
|
- foreach (var prop in custom)
|
|
|
- result.Add(prop.Name);
|
|
|
+ foreach(var prop in DatabaseSchema.Properties(T))
|
|
|
+ {
|
|
|
+ if (prop is StandardProperty stdProp
|
|
|
+ && (!stdProp.IsPersistable || !stdProp.IsSerializable || !stdProp.Property.CanWrite))
|
|
|
+ continue;
|
|
|
+ result.Add(prop);
|
|
|
+ }
|
|
|
_columnscache[T] = result;
|
|
|
}
|
|
|
|
|
@@ -1447,67 +1407,26 @@ namespace InABox.Core
|
|
|
}
|
|
|
|
|
|
return columns;
|
|
|
- //{
|
|
|
- // foreach (var col in cols.Items)
|
|
|
- // {
|
|
|
- // try
|
|
|
- // {
|
|
|
- // result.Add(col.Property);
|
|
|
-
|
|
|
- // //PropertyInfo prop = null;
|
|
|
- // //IProperty iprop = null;
|
|
|
- // //if (col.Property != null)
|
|
|
- // //{
|
|
|
- // // try
|
|
|
- // // {
|
|
|
- // // iprop = DatabaseSchema.Property(typeof(T), col.Property);
|
|
|
- // // }
|
|
|
- // // catch (Exception e2)
|
|
|
- // // {
|
|
|
- // // }
|
|
|
- // // if ((iprop != null) && (iprop is CustomProperty))
|
|
|
- // // result.Add(col.Property);
|
|
|
- // // else
|
|
|
- // // {
|
|
|
- // // prop = CoreUtils.GetProperty(typeof(T), col.Property);
|
|
|
- // // if ((prop.GetCustomAttribute<DoNotSerialize>() == null) && (prop.GetCustomAttribute<DoNotPersist>() == null) && prop.CanWrite)
|
|
|
- // // result.Add(col.Property);
|
|
|
- // // }
|
|
|
- // //}
|
|
|
- // //else
|
|
|
- // //{
|
|
|
- // // String property = CoreUtils.GetFullPropertyName((MemberExpression)col.Expression, ".");
|
|
|
- // // prop = CoreUtils.GetProperty(typeof(T), property);
|
|
|
- // // if ((prop.GetCustomAttribute<DoNotSerialize>() == null) && (prop.GetCustomAttribute<DoNotPersist>() == null) && prop.CanWrite)
|
|
|
- // // result.Add(property);
|
|
|
- // //}
|
|
|
-
|
|
|
-
|
|
|
- // }
|
|
|
- // catch (Exception e)
|
|
|
- // {
|
|
|
-
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
- //return result;
|
|
|
}
|
|
|
|
|
|
- public static List<string> GetColumnNames(Type T, Func<PropertyInfo, bool> Predicate)
|
|
|
+ /// <summary>
|
|
|
+ /// Return a list of the names of the columns of <paramref name="T"/> which are serializable, persistable and writable (i.e., a
|
|
|
+ /// <see langword="null"/> set of columns), <i>and</i> that match the <paramref name="Predicate"/>.
|
|
|
+ /// </summary>
|
|
|
+ /// <param name="T"></param>
|
|
|
+ /// <param name="Predicate"></param>
|
|
|
+ /// <returns></returns>
|
|
|
+ public static List<string> GetColumnNames(Type T, Func<IProperty, bool> predicate)
|
|
|
{
|
|
|
- //var cols = columns;
|
|
|
var result = new List<string>();
|
|
|
|
|
|
- var props = PropertyList(T,
|
|
|
- x =>
|
|
|
- x.GetCustomAttribute<DoNotSerialize>() == null &&
|
|
|
- x.GetCustomAttribute<DoNotPersist>() == null &&
|
|
|
- x.CanWrite && x.PropertyType != typeof(UserProperties) && Predicate(x), true);
|
|
|
- foreach (var prop in props)
|
|
|
- result.Add(prop.Key);
|
|
|
- var custom = DatabaseSchema.Properties(T).Where(x => x is CustomProperty);
|
|
|
- foreach (var prop in custom)
|
|
|
+ foreach(var prop in DatabaseSchema.Properties(T))
|
|
|
+ {
|
|
|
+ if ((prop is StandardProperty stdProp && (!stdProp.IsPersistable || !stdProp.IsSerializable || !stdProp.Property.CanWrite))
|
|
|
+ || !predicate(prop))
|
|
|
+ continue;
|
|
|
result.Add(prop.Name);
|
|
|
+ }
|
|
|
|
|
|
return result;
|
|
|
}
|