Exemple #1
0
 public static void SaveConfig(object config, string path)
 {
     if (string.IsNullOrEmpty(path))
     {
         path = ConfigurationManager.AppSettings["ConfigPath"];
     }
     SPCoderUtils.Serialize(config, GetFullPathToConfigFile(path));
 }
Exemple #2
0
        public static object GetConfig(string path, Type type)
        {
            if (string.IsNullOrEmpty(path))
            {
                path = ConfigurationManager.AppSettings["ConfigPath"];
            }
            object config = SPCoderUtils.Deserialize(type, GetFullPathToConfigFile(path));

            return(config);
        }
Exemple #3
0
        public IEnumerator <AutocompleteItem> GetEnumerator()
        {
            foreach (var item in snippets)
            {
                yield return(new SnippetAutocompleteItem(item));
            }
            foreach (var item in declarationSnippets)
            {
                yield return(new DeclarationSnippet(item));
            }

            foreach (var item in keywords)
            {
                yield return(new AutocompleteItem(item));
            }

            //get the variables from context also
            var variables = SPCoderForm.ScriptStateCSharp.Variables.Select(m => m.Name).ToList();

            foreach (var item in variables)
            {
                yield return(new AutocompleteItem(item));
            }

            //IList<AutocompleteItem> items = new List<AutocompleteItem>();
            //get current fragment of the text
            var text = menu.Fragment.Text;

            if (text.Contains(' '))
            {
                text = text.Substring(text.LastIndexOf(' ')).Trim();
            }

            //get the parameter from the function call
            if (text.Contains('('))
            {
                text = text.Substring(text.LastIndexOf('(') + 1).Trim();
            }

            //extract class name (part before dot)
            var parts = text.Split('.');

            if (parts.Length < 2)
            {
                yield break;
            }
            var myVar = parts[parts.Length - 2];

            //Samo prvi se gleda da li je u context-u!!!
            if (parts.Length <= 2)
            {
                var contextVariable = SPCoderForm.ScriptStateCSharp.GetVariable(myVar);

                if (contextVariable != null)
                {
                    object         variable = ((Microsoft.CodeAnalysis.Scripting.ScriptVariable)contextVariable).Value;
                    IList <string> all      = SPCoderUtils.GetPropertiesAndMethods(variable, myVar, SPCoderForm.MainForm.PutExtensionMethodsToAutocomplete);

                    foreach (string propMeth in all)
                    {
                        yield return(new SPCoderMethodAutocompleteItem(propMeth)
                        {
                            ToolTipTitle = propMeth
                        });
                    }
                }
                else
                {
                    //check if it was class
                    var type = FindTypeByName(myVar);
                    if (type == null)
                    {
                        yield break;
                    }

                    if (type.IsEnum)
                    {
                        var enumValues = type.GetEnumValues();
                        foreach (var pi in enumValues)
                        {
                            yield return new SPCoderMethodAutocompleteItem(pi.ToString())
                                   {
                                       ToolTipTitle = pi.ToString()
                                   }
                        }
                        ;
                    }

                    //return static methods of the class
                    foreach (var meth in type.GetMethods().AsEnumerable().Select(mi => new { Name = mi.Name, Params = mi.GetParameters(), ReturnType = mi.ReturnType.Name }).Distinct())
                    {
                        yield return new SPCoderMethodAutocompleteItem(meth.Name + SPCoderUtils.GetSignature(meth.Params))
                               {
                                   ToolTipTitle = meth.ReturnType + " " + meth.Name + SPCoderUtils.GetSignature(meth.Params)
                               }
                    }
                    ;

                    //return static properties of the class
                    foreach (var pi in type.GetProperties())
                    {
                        yield return new SPCoderMethodAutocompleteItem(pi.Name)
                               {
                                   ToolTipTitle = pi.PropertyType.Name + " " + pi.Name
                               }
                    }
                    ;
                }
            }
            else
            {
                //Here try to find properties/methods from expression
                IList <string> all = SPCoderUtils.GetPropertiesAndMethods(parts, SPCoderForm.MainForm.PutExtensionMethodsToAutocomplete);
                if (all.Count > 0)
                {
                    foreach (string propMeth in all)
                    {
                        yield return(new SPCoderMethodAutocompleteItem(propMeth)
                        {
                            ToolTipTitle = propMeth
                        });
                    }
                }
                else
                {
                    foreach (var variable in SPCoderForm.MainForm.MyContext.GetContext.Keys)
                    {
                        yield return(new SPCoderMethodAutocompleteItem(variable)
                        {
                            ToolTipTitle = variable
                        });
                    }
                }
            }
        }

        Type FindTypeByName(string name)
        {
            Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
            //Type type = null;
            foreach (var a in assemblies)
            {
                try
                {
                    foreach (var t in a.GetTypes())
                    {
                        if (t.Name == name)
                        {
                            return(t);
                        }
                    }
                }
                catch (Exception)
                {
                    //throw;
                }
            }

            return(null);
        }

        System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator()
        {
            return(GetEnumerator());
        }
    }