Esempio n. 1
0
        /// <summary>
        /// Includes new property in the tree
        /// </summary>
        /// <param name="__pathPart">The path part.</param>
        /// <returns></returns>
        public PropertyExpression Add(String __pathPart, Object subhost = null)
        {
            //if (valueType == null) valueType = hostType.GetProperty(name)

            //if (subhost == null) subhost = getValue();
            if (subhost == null)
            {
                subhost = host.imbGetPropertySafe(name, null); //getValue();
            }


            var output = new PropertyExpression(subhost, __pathPart, this);

            // var sType = subhost.GetType();

            //Object subhost = getValue();//property.GetValue(host, null);// getValue();
            //  if (__pathPart == name) return this;

            // var p = valueType.GetProperty(__pathPart);  //property.PropertyType.GetProperty(__pathPart);//hostType.GetProperty(__pathPart);
            // var subsubhost = subhost.imbGetPropertySafe(__pathPart, null);
            // var p = property.PropertyType.GetProperty(__pathPart); //hostType.GetProperty(__pathPart, BindingFlags.Instance | BindingFlags.Public);
            // var output = new PropertyExpression(subhost, p, this);

            return(output);
        }
        /// <summary>
        /// Resolves the specified expresion <c>path</c>, having <c>host</c> as starting node
        /// </summary>
        /// <param name="host">The host object - the starting point for expression path interpretation</param>
        /// <param name="path">The path.</param>
        /// <returns></returns>
        public static PropertyExpression GetExpressionResolved(this Object host, String path)
        {
            PropertyExpression output = null;

            List <String> pathPart = imbSciStringExtensions.SplitSmart(path, EXPRESSION_PATH_DELIMITER);
            String        root     = "";

            if (pathPart.Any())
            {
                root   = pathPart.First();
                output = new PropertyExpression(host, root);

                pathPart = pathPart.GetRange(1, pathPart.Count() - 1);
            }
            // pathPart.Remove(pathPart.First());

            Object head = host;

            if (output.property == null)
            {
                output.state          = PropertyExpressionStateEnum.nothingResolved;
                output.undesolvedPart = path;
                return(output);
            }
            String currentPart = root;

            foreach (String pp in pathPart)
            {
                currentPart = pp;

                var tmp = output.Add(pp);
                if (tmp.host == null)
                {
                    output.state = PropertyExpressionStateEnum.resolvedSome;
                    break;
                }
                else
                {
                    output = tmp;
                }
            }

            if (pathPart.Any() && currentPart != pathPart.LastOrDefault())
            {
                String unp = "";
                Int32  i   = pathPart.IndexOf(currentPart);
                for (int j = i; j < pathPart.Count; j++)
                {
                    unp = imbSciStringExtensions.add(unp, pathPart[j], EXPRESSION_PATH_DELIMITER);
                }
                output.undesolvedPart = unp;
            }
            else
            {
                if (output.property != null)
                {
                    output.state = PropertyExpressionStateEnum.resolvedAll;
                }
            }
            return(output);
        }
Esempio n. 3
0
        /// <summary>
        /// Expands this property expression with sub properties, until specified <c>maxDepth</c> <see cref="IGraphNode.level"/>
        /// </summary>
        /// <param name="maxDepth">The maximum depth.</param>
        /// <param name="IncludeReadOnly">if set to <c>true</c> [include read only].</param>
        /// <param name="IncludeListsAndDictionaries">if set to <c>true</c> [include lists].</param>
        public void Expand(Int32 maxDepth = 100, Boolean IncludeReadOnly = false, Boolean IncludeListsAndDictionaries = true)
        {
            if (level < maxDepth)
            {
                if (hostType.IsClass)
                {
                    if (IncludeListsAndDictionaries)
                    {
                        if (parent == null || ((PropertyExpression)parent).host != host)
                        {
                            if (host is IList)
                            {
                                for (int i = 0; i < hostList.Count; i++)
                                {
                                    var subp = new PropertyExpression(hostList, i, this);
                                }
                            }
                            else if (host is IDictionary)
                            {
                                foreach (Object k in hostDictionary)
                                {
                                    if (k != null)
                                    {
                                        if (k is String)
                                        {
                                            var subp = new PropertyExpression(hostDictionary, k as String, this);
                                        }
                                    }
                                }
                            }
                        }
                    }
                    //var t = valueType;
                    //if (valueType == null)
                    //{
                    //    t = hostType;
                    //}

                    PropertyInfo[] sub_props = hostType.GetProperties(BindingFlags.Instance | BindingFlags.Public);

                    if (false) //!IsReady)
                    {
                        sub_props = valueType.GetProperties(BindingFlags.Instance | BindingFlags.Public);
                        foreach (var sp in sub_props)
                        {
                            if (sp.CanWrite || IncludeReadOnly)
                            {
                                Add(sp.Name);
                            }
                        }
                    }
                    else
                    {
                        Object sh = getValue();

                        foreach (var sp in sub_props)
                        {
                            if (sp.CanWrite || IncludeReadOnly)
                            {
                                Object subhost = host.imbGetPropertySafe(sp, null);

                                //var p = hostType.GetProperty(__pathPart);

                                var subpe = new PropertyExpression(subhost, sp, this);//Add(sp.Name); //
                                //subpe.host = host;

                                subpe.Expand(maxDepth, IncludeReadOnly, IncludeListsAndDictionaries);
                                //var subpe = host.GetExpressionResolved(name + "." +sp.Name); //Add(sp.Name);
                                //subpe.name = sp.Name;
                                //subpe.RegisterWithParent(this);
                            }
                        }
                    }

                    foreach (PropertyExpression ch in children.Values)
                    {
                        ch.Expand(maxDepth, IncludeReadOnly, IncludeListsAndDictionaries);
                    }
                }
            }
        }