Exemple #1
0
        public static IList <string> GetPropertiesAndMethods(object obj, string objName, bool getExtensionMethods = false)
        {
            /*
             * if (obj is IronPython.Runtime.Types.OldInstance)
             *  return GetPythonObjectMethods(obj, objName);
             */
            if (obj != null)
            {
                var type = obj.GetType();
                if (AutocompleteItems.ContainsKey(type))
                {
                    return(AutocompleteItems[type]);
                }

                IList <string> all = GetProperties(obj, objName);
                ((List <string>)all).AddRange(GetMethods(obj, objName, getExtensionMethods));
                ((List <string>)all).Sort();
                AutocompleteItems[type] = all;
                return(all);
            }
            return(new List <string>());
        }
Exemple #2
0
        public static IList <string> GetPropertiesAndMethods(string[] callTrail, bool getExtensionMethods = false)
        {
            string root = callTrail[0];
            Type   type = typeof(void);

            try
            {
                object variable = SPCoderForm.ScriptStateCSharp.GetVariable(root);
                if (variable != null)
                {
                    variable = ((Microsoft.CodeAnalysis.Scripting.ScriptVariable)variable).Value;
                }

                type = variable.GetType();

                for (int i = 1; i < callTrail.Length; i++)
                {
                    string current = callTrail[i];
                    if (string.IsNullOrEmpty(current))
                    {
                        continue;
                    }

                    if (current.Contains("(")) //Method
                    {
                        try
                        {
                            current = current.Substring(0, current.IndexOf('('));
                            //type = type.GetMethod(current).ReturnType;
                            type     = ((MethodInfo)type.GetMember(current)[0]).ReturnType;
                            variable = null;
                        }
                        catch (Exception)
                        {
                        }
                    }
                    else//Property
                    {
                        try
                        {
                            //type = type.GetProperty(current).PropertyType;
                            variable = type.GetProperty(current).GetValue(variable);
                            if (variable == null)
                            {
                                type = ((PropertyInfo)type.GetMember(current)[0]).PropertyType;
                            }
                            else
                            {
                                type = variable.GetType();
                            }
                        }
                        catch (Exception)
                        {
                            //check for Non static property requires the target
                        }
                    }
                }
            }
            catch (Exception)
            {
                //
            }

            if (AutocompleteItems.ContainsKey(type))
            {
                return(AutocompleteItems[type]);
            }

            IList <string> all = GetProperties(type);

            ((List <string>)all).AddRange(GetMethods(type, getExtensionMethods));
            ((List <string>)all).Sort();
            AutocompleteItems[type] = all;
            return(all);
            //return GetPropertiesAndMethods(obj, objName);
        }