public virtual T GetItem <T>(object primaryKey) where T : class, new() { lock (tableLocks[typeof(T)]) { T itemResult = connection.Find <T>(primaryKey); return(typeof(IEncryptable).IsAssignableFrom(typeof(T)) ? SqliteEncryptHelper.DecryptItem <T>(itemResult) : itemResult); } }
public virtual T GetItem <T>(Expression <Func <T, bool> > predicate) where T : class, new() { lock (tableLocks[typeof(T)]) { T itemResult = connection.Find <T>(predicate); return(typeof(IEncryptable).IsAssignableFrom(typeof(T)) ? SqliteEncryptHelper.DecryptItem <T>(itemResult) : itemResult); } }
private T DecryptWithChildren <T>(T item) where T : class, new() { if (item == null) { return(item); } var refTypeProperties = typeof(T).GetTypeInfo().DeclaredProperties.Where( x => x.CanWrite && !x.PropertyType.GetTypeInfo().IsValueType&& x.PropertyType != typeof(string)); foreach (var refTypeProperty in refTypeProperties) { var refTypePropertyValue = refTypeProperty.GetValue(item); if (typeof(IEnumerable).IsAssignableFrom(refTypeProperty.PropertyType)) { var seq = (refTypePropertyValue as IEnumerable).GetEnumerator(); while (seq.MoveNext()) { DecryptWithChildren(seq.Current); } } else { DecryptWithChildren(refTypePropertyValue); } } if (typeof(IEncryptable).IsAssignableFrom(item.GetType())) { item = SqliteEncryptHelper.DecryptItem(item); } return(item); }