Exemplo n.º 1
0
 /// <summary>
 /// Check the given type if it has an LogicalDeleteAttribute on any property, and returns with the first property it founds (or null)
 /// </summary>
 /// <param name="type">Checked type</param>
 /// <returns></returns>
 public static PropertyInfo GetLogicalDeleteProperty(Type type)
 {
     if (!LogicalDeleteCache.ContainsKey(type.FullName))
     {
         LogicalDeleteCache.Add(type.FullName, type.GetProperties().FirstOrDefault(x => x.GetCustomAttributes <LogicalDeleteAttribute>().Any()));
     }
     return(LogicalDeleteCache[type.FullName]);
 }
Exemplo n.º 2
0
        /// <summary>
        /// Check the given type if it has an LogicalDeleteAttribute on any property, and returns with the first property it founds (or null)
        /// </summary>
        /// <param name="type">Checked type</param>
        /// <returns></returns>
        public static PropertyInfo GetLogicalDeleteProperty(Type type)
        {
            if (!LogicalDeleteCache.ContainsKey(type.FullName ?? throw new InvalidOperationException()))
            {
                var logicalDeleteProperty = type.GetProperties()
                                            .FirstOrDefault(x => x.GetCustomAttributes <LogicalDeleteAttribute>().Any());
                if (logicalDeleteProperty == null)
                {
                    logicalDeleteProperty =
                        type.GetInterfaces()
                        .Select(x =>
                                x.GetProperties().FirstOrDefault(y =>
                                                                 y.GetCustomAttributes <LogicalDeleteAttribute>().Any()))
                        ?.FirstOrDefault(x => x != null);
                }

                LogicalDeleteCache.Add(type.FullName, logicalDeleteProperty);
            }

            return(LogicalDeleteCache[type.FullName]);
        }