private IEntityLogInfo <T> CreateEntityLogInfo(EntityLogActionType logAction, T entity, bool autoUpdate = true, string logActionName = null) { try { IEntityLogInfo <T> result; if (_createEmptyEntityLog) { result = EntityLogInfo <T> .CreateEmptyEntityLogInfo(entity); } else { result = new EntityLogInfoImpl <T>(logAction, entity, this.DbContext, logActionName); // EntityLogInfo<T>.CreateDefaultEntityLogInfo(logAction, entity); } if (autoUpdate && _autoUpdateEntityLog) { result.Update(this.AutoCommitEnabled); } return(result); } catch { return(EntityLogInfo <T> .CreateEmptyEntityLogInfo(entity)); } }
private static EntityLogInfo EntityLogPropertyInfos(Type entityType) { if (s_EntityLogPropertyInfos == null) { s_EntityLogPropertyInfos = new Dictionary <Type, EntityLogInfo>(); } EntityLogInfo result = null; if (s_EntityLogPropertyInfos.ContainsKey(entityType)) { result = s_EntityLogPropertyInfos[entityType]; } else { s_EntityLogPropertyInfos.Add(entityType, result = new EntityLogInfo { EntityType = entityType }); //result.Attributes.AddRange(entityType.GetCustomAttributes<EntityLogAttribute>(true)); var properties = entityType.GetProperties(); foreach (var property in properties) { //var customAttributes = property.GetCustomAttributes<EntityPropertyLogAttribute>(true); //if (!customAttributes.Any()) //{ // continue; //} var propertyLogInfo = new EntityPropertyLogInfo { Property = property, Owner = result }; //propertyLogInfo.Attributes.AddRange(customAttributes); bool isEnumerable = property.PropertyType != typeof(string) && typeof(IEnumerable).IsAssignableFrom(property.PropertyType); //propertyLogInfo.Enumerable = customAttributes.Where(x => x.Enumerable).Any() || isEnumerable; //propertyLogInfo.PropertyType = customAttributes.Where(x => x.PropertyType != null).Select(x => x.PropertyType).FirstOrDefault(); if (propertyLogInfo.PropertyType == null) { if (propertyLogInfo.Enumerable) { if (property.PropertyType.IsCompatibleToGenericType(typeof(IEnumerable <>))) { propertyLogInfo.PropertyType = property.PropertyType.GetCompatibleGenericTypeParameterTypes(typeof(IEnumerable <>))[0]; } else { propertyLogInfo.PropertyType = typeof(object); } } else { propertyLogInfo.PropertyType = property.PropertyType; } } //var referenceIdPropertyName = customAttributes.Where(x => x.ReferenceIdPropertyName.HasValue()).Select(x => x.ReferenceIdPropertyName).FirstOrDefault(); //if (referenceIdPropertyName.HasValue()) //{ // propertyLogInfo.ReferenceIdProperty = properties.Where(x => string.Equals(x.Name, referenceIdPropertyName, StringComparison.CurrentCultureIgnoreCase)).FirstOrDefault(); //} result.Properties.Add(propertyLogInfo); } } return(result); }