public int InsertOrReplace <T>(T item) where T : class, new() { lock (tableLocks[typeof(T)]) { if (typeof(IEncryptable).IsAssignableFrom(typeof(T))) { item = SqliteEncryptHelper.EncryptItem <T>(item); } return(connection.InsertOrReplace(item)); } }
private T EncryptWithChildren <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()) { EncryptWithChildren(seq.Current); } } else { EncryptWithChildren(refTypePropertyValue); } } if (typeof(IEncryptable).IsAssignableFrom(item.GetType())) { item = SqliteEncryptHelper.EncryptItem(item); } return(item); }