コード例 #1
0
        public static IEnumerable <Type> FindTypes(TypeIncludes flags, Type baseType)
        {
            if (baseType == null)
            {
                throw new ArgumentNullException("baseType", "Must be set to a type");
            }

            Func <Type, bool> predicate = BuildPredicate(flags);
            var foundTypes = from containedType in FindTypes(baseType)
                             where predicate(containedType)
                             select containedType;

            if (!(IsSet(flags, TypeIncludes.ConcreteTypes) && IsConcreteType(baseType)))
            {
                if (foundTypes.Contains(baseType))
                {
                    IList <Type> b = new List <Type>();
                    b.Add(baseType);
                    foundTypes = foundTypes.Except(b.AsQueryable());
                }
            }

            if (IsSet(flags, TypeIncludes.PrimitiveTypes))
            {
                foundTypes = foundTypes.Concat(FindPrimitiveTypes());
            }
            return(foundTypes);
        }
コード例 #2
0
ファイル: TypeLocator.cs プロジェクト: DBailey635/C1-CMS
        public static IEnumerable<Type> FindTypes(TypeIncludes flags, Type baseType)
        {
            if (baseType == null) throw new ArgumentNullException("baseType", "Must be set to a type");

            Func<Type, bool> predicate = BuildPredicate(flags);
            var foundTypes = from containedType in FindTypes(baseType)
                             where predicate(containedType)
                             select containedType;

            if (!(IsSet(flags, TypeIncludes.ConcreteTypes) && IsConcreteType(baseType)))
            {
                if(foundTypes.Contains(baseType))
                {
                    IList<Type> b = new List<Type>();
                    b.Add(baseType);
                    foundTypes = foundTypes.Except(b.AsQueryable());
                }
            }
            
            if (IsSet(flags, TypeIncludes.PrimitiveTypes))
            {
                foundTypes = foundTypes.Concat(FindPrimitiveTypes());
            }
            return foundTypes;
        }
コード例 #3
0
        private static Func <Type, bool> BuildPredicate(TypeIncludes flags)
        {
            IList <Func <Type, bool> > functions = SelectFuntions(flags);

            Func <Func <Type, bool>, Func <Type, bool>, Func <Type, bool> >
            or = (f1, f2) => (t => f1(t) || f2(t));

            Func <Type, bool> current = (x => false);

            foreach (Func <Type, bool> func in functions)
            {
                current = or(func, current);
            }
            return(current);
        }
コード例 #4
0
        private static IList <Func <Type, bool> > SelectFuntions(TypeIncludes flags)
        {
            bool includeAllInterfaces = IsSet(flags, TypeIncludes.InterfaceTypes);
            bool includeConcreteTypes = IsSet(flags, TypeIncludes.ConcreteTypes);

            List <Func <Type, bool> > functions = new List <Func <Type, bool> >();

            if (includeAllInterfaces)
            {
                functions.Add(x => x.IsInterface);
            }
            if (includeConcreteTypes)
            {
                functions.Add(x => (IsConcreteType(x)));
            }

            return(functions);
        }
コード例 #5
0
        private IEnumerable <Type> EnumerateWithCompositeSelector()
        {
            TypeIncludes includes = new TypeIncludes();

            if (IsSet(Mode, UiControlTypeSelectorMode.ConcreteTypes))
            {
                includes = TypeIncludes.ConcreteTypes;
            }
            if (IsSet(Mode, UiControlTypeSelectorMode.InterfaceTypes))
            {
                includes = includes | TypeIncludes.InterfaceTypes;
            }
            if (IsSet(Mode, UiControlTypeSelectorMode.PrimitiveTypes))
            {
                includes = includes | TypeIncludes.PrimitiveTypes;
            }
            return(TypeLocator.FindTypes(includes, this.AssignableTo));
        }
コード例 #6
0
        public async Task <BaseDTO> FindByIdAsync(int id, int templateId)
        {
            //1. get template
            var template = await _templateRepository.FindByIdAsync(templateId, new string[] { "TemplateIncludes", "TemplateType" });

            if (template == null)
            {
                return(null);
            }

            string typeName = template.TemplateType.Route;

            //2. Getdata
            T data = await _dataRepository.FindByIdAsync(id, TypeIncludes.GetIncludes(typeName.ToLower()));

            if (data == null)
            {
                return(null);
            }
            //3. map and return
            return(_mapper.map(data, template.TemplateIncludes.Select(p => p.Include).ToArray()));
        }
コード例 #7
0
 private IEnumerable<Type> EnumerateWithCompositeSelector()
 {
     TypeIncludes includes = new TypeIncludes();
     if (IsSet(Mode, UiControlTypeSelectorMode.ConcreteTypes))
     {
         includes = TypeIncludes.ConcreteTypes;
     }
     if (IsSet(Mode, UiControlTypeSelectorMode.InterfaceTypes))
     {
         includes = includes | TypeIncludes.InterfaceTypes;
     }
     if (IsSet(Mode, UiControlTypeSelectorMode.PrimitiveTypes))
     {
         includes = includes | TypeIncludes.PrimitiveTypes;
     }
     return TypeLocator.FindTypes(includes, this.AssignableTo);
 }
コード例 #8
0
ファイル: TypeLocator.cs プロジェクト: DBailey635/C1-CMS
 public static IEnumerable<Type> FindTypes(TypeIncludes flags)
 {
     return FindTypes(flags, typeof(object));
 }
コード例 #9
0
ファイル: TypeLocator.cs プロジェクト: DBailey635/C1-CMS
 public BaseTypeIncludesAttribute(Type baseType, TypeIncludes includes)
 {
     _baseType = baseType;
     _includes = includes;
 }
コード例 #10
0
ファイル: TypeLocator.cs プロジェクト: DBailey635/C1-CMS
 private static bool IsSet(TypeIncludes flags, TypeIncludes compareFlag)
 {
     return ((flags & compareFlag) == compareFlag);
 }
コード例 #11
0
ファイル: TypeLocator.cs プロジェクト: DBailey635/C1-CMS
        private static Func<Type, bool> BuildPredicate(TypeIncludes flags)
        {
            IList<Func<Type, bool>> functions = SelectFuntions(flags);

            Func<Func<Type, bool>, Func<Type, bool>, Func<Type, bool>>
                or = (f1, f2) => (t => f1(t) || f2(t));

            Func<Type, bool> current = (x => false);
            foreach (Func<Type, bool> func in functions)
            {
                current = or(func, current);
            }
            return current;
        }
コード例 #12
0
ファイル: TypeLocator.cs プロジェクト: DBailey635/C1-CMS
        private static IList<Func<Type, bool>> SelectFuntions(TypeIncludes flags)
        {
            bool includeAllInterfaces = IsSet(flags, TypeIncludes.InterfaceTypes);
            bool includeConcreteTypes = IsSet(flags, TypeIncludes.ConcreteTypes);

            List<Func<Type, bool>> functions = new List<Func<Type, bool>>();
            if (includeAllInterfaces)
            {
                functions.Add(x => x.IsInterface);
            }
            if (includeConcreteTypes)
            {
                functions.Add(x => (IsConcreteType(x)));
            }

            return functions;
        }
コード例 #13
0
 public static IEnumerable <Type> FindTypes(TypeIncludes flags)
 {
     return(FindTypes(flags, typeof(object)));
 }
コード例 #14
0
 public BaseTypeIncludesAttribute(Type baseType, TypeIncludes includes)
 {
     _baseType = baseType;
     _includes = includes;
 }
コード例 #15
0
 private static bool IsSet(TypeIncludes flags, TypeIncludes compareFlag)
 {
     return((flags & compareFlag) == compareFlag);
 }