コード例 #1
0
        private static bool CheckFilter(PathNode pathNode, ContextMemberFilter filter)
        {
            if (filter.IsOptionSet(ContextMemberFilter.Fields) && pathNode.Info.Field != null)
            {
                return(true);
            }

            if (filter.IsOptionSet(ContextMemberFilter.Properties) && pathNode.Info.Property != null)
            {
                return(true);
            }

            if (filter.IsOptionSet(ContextMemberFilter.Methods) && pathNode.Info.Method != null)
            {
                return(true);
            }

            if (filter.IsOptionSet(ContextMemberFilter.Contexts) &&
                typeof(IDataContext).IsAssignableFrom(pathNode.Type))
            {
                return(true);
            }

            if (filter.IsOptionSet(ContextMemberFilter.Triggers) && typeof(DataTrigger).IsAssignableFrom(pathNode.Type))
            {
                return(true);
            }

            return(false);
        }
コード例 #2
0
ファイル: ContextTypeCache.cs プロジェクト: UpPower/ZFrame
        private static List <string> CreatePaths(PathNode pathNode, ContextMemberFilter filter, int depth)
        {
            var paths = new List <string>();

            // Check for maximum path depth.
            if (depth > MaxPathDepth)
            {
                return(paths);
            }

            // Check if node has children.
            if (pathNode.Children == null)
            {
                return(paths);
            }

            foreach (var childNode in pathNode.Children)
            {
                // Check if node should be considered.
                if (CheckFilter(childNode, filter))
                {
                    var childName = childNode.Info.Name;
                    paths.Add(childName);
                }

                // Check if to step into child nodes.
                if (filter.IsOptionSet(ContextMemberFilter.Recursive))
                {
                    var subContextPaths = CreatePaths(childNode, filter, depth + 1);
                    paths.AddRange(subContextPaths.Select(subContextPath => childNode.Info.Name + "." + subContextPath));
                }
            }

            return(paths);
        }
コード例 #3
0
        /// <summary>
        ///   Returns all available paths of the specified <see cref="Context"/> type.
        /// </summary>
        /// <param name="type">Type of context to get paths for.</param>
        /// <param name="filter">Filter to only return specific members of the context.</param>
        /// <returns>List of available paths of the specified <see cref="Context"/> type.</returns>
        public static List<string> GetPaths(Type type, ContextMemberFilter filter = ContextMemberFilter.All)
        {
            if (type == null)
            {
                return null;
            }

            var pathNode = GetPathNode(type);
            return CreatePaths(pathNode, filter);
        }
コード例 #4
0
        /// <summary>
        ///     Returns all available paths of the specified <see cref="IDataContext" /> type.
        /// </summary>
        /// <param name="type">Type of context to get paths for.</param>
        /// <param name="filter">Filter to only return specific members of the context.</param>
        /// <returns>List of available paths of the specified <see cref="IDataContext" /> type.</returns>
        public static List <string> GetPaths(Type type, ContextMemberFilter filter = ContextMemberFilter.All)
        {
            if (type == null)
            {
                return(null);
            }

            var pathNode = GetPathNode(type);

            return(CreatePaths(pathNode, filter, 0));
        }
コード例 #5
0
        private static bool CheckFilter(PathNode pathNode, ContextMemberFilter filter)
        {
            if (filter.IsOptionSet(ContextMemberFilter.Fields) && pathNode.Info.Field != null)
            {
                return true;
            }
            if (filter.IsOptionSet(ContextMemberFilter.Properties) && pathNode.Info.Property != null)
            {
                return true;
            }
            if (filter.IsOptionSet(ContextMemberFilter.Methods) && pathNode.Info.Method != null)
            {
                return true;
            }

            if (filter.IsOptionSet(ContextMemberFilter.Contexts) && typeof(Context).IsAssignableFrom(pathNode.Type))
            {
                return true;
            }

            return false;
        }
コード例 #6
0
        private static List<string> CreatePaths(PathNode pathNode, ContextMemberFilter filter)
        {
            var paths = new List<string>();
            if (pathNode.Children == null)
            {
                return paths;
            }

            foreach (var childNode in pathNode.Children)
            {
                // Check if node should be considered.
                if (CheckFilter(childNode, filter))
                {
                    var childName = childNode.Info.Name;
                    paths.Add(childName);
                }

                // Check if to step into child nodes.
                if (filter.IsOptionSet(ContextMemberFilter.Recursive))
                {
                    var subContextPaths = CreatePaths(childNode, filter);
                    paths.AddRange(
                        subContextPaths.Select(subContextPath => childNode.Info.Name + "." + subContextPath));
                }
            }

            return paths;
        }