예제 #1
0
        public static PropertyDescriptorCollection GetObjectProperties(EnumReflectionMemberInfoSelectScope scope, object obj, bool browsableOnly)
        {
            bool includeClient = MethodInfoWebClient.IsWebClientObject(obj);
            bool includeServer = MethodInfoWebClient.IsWebServerObject(obj);
            PropertyDescriptorCollection ps = VPLUtil.GetProperties(obj, scope, false, browsableOnly, true);            // TypeDescriptor.GetProperties(obj, attrs, false);
            List <PropertyDescriptor>    l  = new List <PropertyDescriptor>();

            foreach (PropertyDescriptor p in ps)
            {
                bool include = false;
                if (includeClient)
                {
                    if (WebClientMemberAttribute.IsClientProperty(p))
                    {
                        include = true;
                    }
                }
                if (!include)
                {
                    if (includeServer)
                    {
                        if (WebServerMemberAttribute.IsServerProperty(p))
                        {
                            include = true;
                        }
                    }
                }
                if (!include)
                {
                    if (includeClient)
                    {
                        if (!(obj is Form) && (obj is IWebClientControl))
                        {
                            if (string.CompareOrdinal(p.Name, "Location") != 0)
                            {
                                include = true;
                            }
                        }
                    }
                }
                if (!include)
                {
                    if (includeServer)
                    {
                        if (obj is IWebServerProgrammingSupport)
                        {
                            include = true;
                        }
                    }
                }
                if (include)
                {
                    l.Add(p);
                }
            }
            return(new PropertyDescriptorCollection(l.ToArray()));
        }
예제 #2
0
        public static MethodInfo[] GetWebMethods(bool isStatic, object obj)
        {
            bool includeClient    = MethodInfoWebClient.IsWebClientObject(obj);
            bool includeServer    = MethodInfoWebClient.IsWebServerObject(obj);
            List <MethodInfo> lst = new List <MethodInfo>();
            BindingFlags      flags;

            if (isStatic)
            {
                flags = BindingFlags.Public | BindingFlags.Static;
            }
            else
            {
                flags = BindingFlags.Public | BindingFlags.Instance;
            }
            Type t = obj as Type;

            if (t == null)
            {
                t = obj.GetType();
            }
            bool isPhp = PhpTypeAttribute.IsPhpType(t);
            bool isJs  = JsTypeAttribute.IsJsType(t);

            MethodInfo[] ret = t.GetMethods(flags);
            if (ret != null && ret.Length > 0)
            {
                for (int i = 0; i < ret.Length; i++)
                {
                    if (!ret[i].IsSpecialName)
                    {
                        if (VPLUtil.IsNotForProgramming(ret[i]))
                        {
                            continue;
                        }
                        bool include = false;
                        if (isPhp)
                        {
                            if (WebServerMemberAttribute.IsServerMethod(ret[i]))
                            {
                                lst.Add(ret[i]);
                            }
                            continue;
                        }
                        if (isJs)
                        {
                            if (WebClientMemberAttribute.IsClientMethod(ret[i]))
                            {
                                lst.Add(ret[i]);
                            }
                            continue;
                        }
                        if (includeClient)
                        {
                            object[] objs = ret[i].GetCustomAttributes(typeof(WebClientMemberAttribute), true);
                            if (objs != null && objs.Length > 0)
                            {
                                include = true;
                            }
                        }
                        if (!include)
                        {
                            if (includeServer)
                            {
                                object[] objs = ret[i].GetCustomAttributes(typeof(WebServerMemberAttribute), true);
                                if (objs != null && objs.Length > 0)
                                {
                                    include = true;
                                }
                            }
                        }
                        if (include)
                        {
                            lst.Add(ret[i]);
                        }
                    }
                }
            }
            ret = lst.ToArray();
            return(ret);
        }
        public override void LoadNextLevel(TreeViewObjectExplorer tv, TreeNodeObject parentNode)
        {
            if (tv != null && tv.RootId != null && parentNode != null && parentNode.OwnerPointer != null && parentNode.OwnerPointer.RootPointer != null)
            {
                if (tv.Project != null && (tv.Project.ProjectType == EnumProjectType.WebAppPhp || tv.Project.ProjectType == EnumProjectType.WebAppAspx))
                {
                    if (tv.RootId.ClassId != parentNode.OwnerPointer.RootPointer.ClassId)
                    {
                        return;
                    }
                }
            }
            IObjectPointer    objRef   = parentNode.OwnerPointer;
            TreeNodeClassRoot topClass = parentNode.TopLevelRootClassNode;
            bool forPhp = false;

            if (tv.Project != null)
            {
                forPhp = (tv.Project.ProjectType == EnumProjectType.WebAppPhp);
            }
            Dictionary <UInt32, IAction> actions = null;

            if (topClass != null)
            {
                if (!topClass.StaticScope)
                {
                    actions = topClass.GetActions();
                }
            }
            else
            {
                TreeNodeClassType rootType = parentNode.TopLevelNode as TreeNodeClassType;
                if (rootType != null)
                {
                    actions = rootType.GetActions();
                }
            }
            SortedList <string, TreeNode> newNodes = new SortedList <string, TreeNode>();
            HtmlElement_BodyBase          heb      = (HtmlElement_BodyBase)parentNode.OwnerIdentity;

            MethodInfo[] mifs = heb.GetType().GetMethods();
            if (mifs != null)
            {
                for (int i = 0; i < mifs.Length; i++)
                {
                    if (parentNode.SelectionTarget == EnumObjectSelectType.Object)
                    {
                        if (mifs[i].ReturnType.Equals(typeof(void)))
                        {
                            continue;
                        }
                        ParameterInfo[] ps = mifs[i].GetParameters();
                        if (ps != null && ps.Length > 0)
                        {
                            continue;
                        }
                    }
                    if (VPLUtil.IsNotForProgramming(mifs[i]))
                    {
                        continue;
                    }
                    if (!WebClientMemberAttribute.IsClientMethod(mifs[i]) && !WebServerMemberAttribute.IsServerMethod(mifs[i]))
                    {
                        continue;
                    }
                    MethodInfoPointer mp = new MethodInfoPointer();
                    mp.Owner = objRef;
                    mp.SetMethodInfo(mifs[i]);
                    int            c;
                    TreeNodeMethod nodeMethod = new TreeNodeMethod(ForStatic, mp);
                    string         key        = mp.GetMethodSignature(out c);
                    TreeNode       nodeExist;
                    if (newNodes.TryGetValue(key, out nodeExist))
                    {
                        TreeNodeMethod mnd = (TreeNodeMethod)nodeExist;
                        if (mnd.MethodInformation.DeclaringType.Equals(mnd.MethodInformation.ReflectedType))
                        {
                            key = key + " - " + mifs[i].DeclaringType.Name;
                            newNodes.Add(key, nodeMethod);
                        }
                        else
                        {
                            if (mifs[i].DeclaringType.Equals(mifs[i].ReflectedType))
                            {
                                newNodes[key] = nodeMethod;
                                key           = key + " - " + mnd.MethodInformation.DeclaringType.Name;
                                newNodes.Add(key, mnd);
                            }
                            else
                            {
                                key = key + " - " + mifs[i].DeclaringType.Name;
                                newNodes.Add(key, nodeMethod);
                            }
                        }
                    }
                    else
                    {
                        newNodes.Add(key, nodeMethod);
                    }
                    //load actions
                    if (actions != null)
                    {
                        bool bHasActions = false;
                        foreach (IAction a in actions.Values)
                        {
                            ActionClass ac = a as ActionClass;
                            if (ac != null)
                            {
                                MethodPointer mp0 = ac.ActionMethod as MethodPointer;
                                if (mp0 != null)
                                {
                                    if (mp0.IsSameObjectRef(mp))
                                    {
                                        bHasActions = true;
                                        break;
                                    }
                                }
                            }
                        }
                        if (bHasActions)
                        {
                            nodeMethod.ShowActionIcon();
                        }
                    }
                }
                parentNode.AddSortedNodes(newNodes);
            }
        }
        public override void LoadNextLevel(TreeViewObjectExplorer tv, TreeNodeObject parentNode)
        {
            UInt32 scopeId = parentNode.ScopeMethodId;
            SortedList <string, TreeNode> newNodes = new SortedList <string, TreeNode>();
            HtmlElement_BodyBase          heb      = (HtmlElement_BodyBase)parentNode.OwnerIdentity;
            PropertyDescriptorCollection  pifs     = TypeDescriptor.GetProperties(heb.GetType());
            TreeNodeClassRoot             topClass = parentNode.TopLevelRootClassNode;
            Dictionary <UInt32, IAction>  actions  = null;

            if (topClass != null)
            {
                if (!topClass.StaticScope)
                {
                    actions = topClass.GetActions();
                }
            }
            else
            {
                if (tv != null)
                {
                    if (tv.RootClassNode != null)
                    {
                        actions = tv.RootClassNode.GetActions();
                    }
                }
                if (actions == null)
                {
                    TreeNodeClassType rootType = parentNode.TopLevelNode as TreeNodeClassType;
                    if (rootType != null)
                    {
                        actions = rootType.GetActions();
                    }
                }
            }
            for (int i = 0; i < pifs.Count; i++)
            {
                if (NotForProgrammingAttribute.IsNotForProgramming(pifs[i]))
                {
                    continue;
                }
                if (!WebClientMemberAttribute.IsClientProperty(pifs[i]) && !WebServerMemberAttribute.IsServerProperty(pifs[i]))
                {
                    continue;
                }
                TreeNodeProperty nodeProperty;
                PropertyPointer  pp;
                pp       = new PropertyPointer();
                pp.Owner = new HtmlElementPointer(heb);
                pp.SetPropertyInfo(pifs[i]);
                if (!newNodes.ContainsKey(pp.Name))
                {
                    nodeProperty = new TreeNodeProperty(ForStatic, pp);
                    try
                    {
                        newNodes.Add(pp.Name, nodeProperty);
                    }
                    catch (Exception err)
                    {
                        MathNode.Log(tv != null ? tv.FindForm() : null, err);
                    }
                    //load actions
                    bool bHasActions = false;
                    if (string.CompareOrdinal(pp.Name, "Cursor") == 0)
                    {
                        bHasActions = false;
                    }
                    if (actions != null)
                    {
                        foreach (IAction a in actions.Values)
                        {
                            if (a != null && a.IsStatic == parentNode.IsStatic)
                            {
                                if (nodeProperty.IncludeAction(a, tv, scopeId, false))
                                {
                                    bHasActions = true;
                                    break;
                                }
                            }
                        }
                        if (bHasActions)
                        {
                            nodeProperty.OnShowActionIcon();
                        }
                    }
                }
            }
            parentNode.AddSortedNodes(newNodes);
        }