internal TikListMerge(ITikConnection connection, IEnumerable <TEntity> expected, IEnumerable <TEntity> original) { _connection = connection; _metadata = TikEntityMetadataCache.GetMetadata <TEntity>(); _expected = expected; _original = original; }
/// <summary> /// .ctor /// </summary> /// <param name="owner">Metadata of the owning entity.</param> /// <param name="propertyInfo">PropertyInfo of the accessed entity property.</param> public TikEntityPropertyAccessor(TikEntityMetadata owner, PropertyInfo propertyInfo) { _owner = owner; PropertyInfo = propertyInfo; //From property code PropertyName = propertyInfo.Name; PropertyType = propertyInfo.PropertyType; //From TikPropertyAttribute attribute var propertyAttribute = propertyInfo.GetCustomAttribute<TikPropertyAttribute>(true); if (propertyAttribute == null) throw new ArgumentException("Property must be decorated by TikPropertyAttribute.", "propertyInfo"); FieldName = propertyAttribute.FieldName; _isReadOnly = (propertyInfo.GetSetMethod() == null) || (!propertyInfo.CanWrite) || (propertyAttribute.IsReadOnly); IsMandatory = propertyAttribute.IsMandatory; if (propertyAttribute.DefaultValue != null) DefaultValue = propertyAttribute.DefaultValue; else { if (PropertyType.IsValueType) DefaultValue = ConvertToString(Activator.CreateInstance(PropertyType)); //default value of value type. for example: (default)int else DefaultValue = ""; } UnsetOnDefault = propertyAttribute.UnsetOnDefault; }
private static void EnsureHasIdProperty(TikEntityMetadata metadata) { if (!metadata.HasIdProperty) { throw new InvalidOperationException(string.Format("Can not update/delete non-sigleton entity which doesn't contains property for '{0}' field.", TikSpecialProperties.Id)); } }
private static void EnsureSupportsOrdering(TikEntityMetadata entityMetadata) { if (!entityMetadata.IsOrdered) { throw new InvalidOperationException("Can not move entity without ordering support."); } }
private static void EnsureNotReadonlyEntity(TikEntityMetadata entityMetadata) { if (entityMetadata.IsReadOnly) { throw new InvalidOperationException("Can not save R/O entity."); } }
/// <summary> /// .ctor /// </summary> /// <param name="owner">Metadata of the owning entity.</param> /// <param name="propertyInfo">PropertyInfo of the accessed entity property.</param> public TikEntityPropertyAccessor(TikEntityMetadata owner, PropertyInfo propertyInfo) { _owner = owner; PropertyInfo = propertyInfo; //From property code PropertyName = propertyInfo.Name; PropertyType = propertyInfo.PropertyType; //From TikPropertyAttribute attribute var propertyAttribute = propertyInfo.GetCustomAttribute <TikPropertyAttribute>(true); if (propertyAttribute == null) { throw new ArgumentException("Property must be decorated by TikPropertyAttribute.", "propertyInfo"); } FieldName = propertyAttribute.FieldName; _isReadOnly = #if NET20 || NET35 || NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 (propertyInfo.GetSetMethod() == null) #else (propertyInfo.SetMethod == null) #endif || (!propertyInfo.CanWrite) || (propertyAttribute.IsReadOnly); IsMandatory = propertyAttribute.IsMandatory; if (propertyAttribute.DefaultValue != null) { DefaultValue = propertyAttribute.DefaultValue; } else { #if NET20 || NET35 || NET40 || NET45 || NET451 || NET452 || NET46 || NET461 || NET462 || NET47 || NET471 if (PropertyType.IsValueType) #else if (PropertyType.GetTypeInfo().IsValueType) #endif { DefaultValue = ConvertToString(Activator.CreateInstance(PropertyType)); //default value of value type. for example: (default)int } else { DefaultValue = ""; } } UnsetOnDefault = propertyAttribute.UnsetOnDefault; }
/// <summary> /// Gets (or creates new) <typeparamref name="TEntity"/> metadata via reflection of its attributes. /// </summary> /// <typeparam name="TEntity">Type of the entity.</typeparam> /// <returns>Entity metadata used by entity mapper.</returns> public static TikEntityMetadata GetMetadata <TEntity>() { Type key = typeof(TEntity); TikEntityMetadata result; if (!_cache.TryGetValue(key, out result)) { lock (_lockObj) { if (!_cache.TryGetValue(key, out result)) { result = new TikEntityMetadata(typeof(TEntity)); _cache.Add(key, result); } } } return(result); }