Beispiel #1
0
 public bool Remove(TKey key)
 {
     if (super.Contains(key))
     {
         super.Remove(key);
         return(true);
     }
     return(false);
 }
 public void Remove(T item)
 {
     lock (this)
     {
         if (_items.Contains(item))
         {
             _items.Remove(item);
         }
     }
 }
 static void Main(string[] args)
 {
     System.Collections.Specialized.OrderedDictionary orderedDictionary = new System.Collections.Specialized.OrderedDictionary();
     orderedDictionary.Add("Test1", "Test@123");
     orderedDictionary.Add("Admin", "Admin@123");
     orderedDictionary.Add("Temp", "Temp@123");
     orderedDictionary.Add("Demo", "Demo@123");
     orderedDictionary.Add("Test2", "Test2@123");
     orderedDictionary.Remove("Admin");
     if (orderedDictionary.Contains("Admin"))
     {
         Console.WriteLine("UserName already Esists");
     }
     else
     {
         orderedDictionary.Add("Admin", "Admin@123");
         Console.WriteLine("User added succesfully.");
     }
     // Insert a new key to the beginning of the OrderedDictionary
     orderedDictionary.Insert(0, "Test3", "Test3@123");
     // Modify the value of the entry with the key "Test1"
     orderedDictionary["Test1"] = "Test1@333";
     // Get a collection of the keys.
     Console.WriteLine("UserName" + ": " + "Password");
     foreach (DictionaryEntry entry in orderedDictionary)
     {
         Console.WriteLine(entry.Key + ": " + entry.Value);
     }
     String[] myKeys   = new String[orderedDictionary.Count];
     String[] myValues = new String[orderedDictionary.Count];
     orderedDictionary.Keys.CopyTo(myKeys, 0);
     orderedDictionary.Values.CopyTo(myValues, 0);
     Console.WriteLine("");
     // Displays the contents of the OrderedDictionary
     Console.WriteLine(" INDEX KEY  VALUE");
     for (int i = 0; i < orderedDictionary.Count; i++)
     {
         Console.WriteLine("   {0} {1} {2}",
                           i, myKeys[i], myValues[i]);
     }
     Console.WriteLine();
     Console.ReadKey();
 }
Beispiel #4
0
        static List <string> GetAssembliesList()
        {
            DirectoryInfo[] DefaultAssemblyFolders =
            {
                // %ProgramData%\Grasshopper\Libraries-Inside-Revit-20XX
                new DirectoryInfo(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "Grasshopper", $"Libraries-{Rhinoceros.SchemeName}")),

                // %APPDATA%\Grasshopper\Libraries-Inside-Revit-20XX
                new DirectoryInfo(Folders.DefaultAssemblyFolder.Substring(0,                                               Folders.DefaultAssemblyFolder.Length - 1) + '-' + Rhinoceros.SchemeName)
            };

            var map = new System.Collections.Specialized.OrderedDictionary();

            foreach (var folder in DefaultAssemblyFolders)
            {
                IEnumerable <FileInfo> assemblyFiles;
                try { assemblyFiles = folder.EnumerateFiles("*.gha", SearchOption.AllDirectories); }
                catch (System.IO.DirectoryNotFoundException) { continue; }

                foreach (var assemblyFile in assemblyFiles)
                {
                    // https://docs.microsoft.com/en-us/dotnet/api/system.io.directory.enumeratefiles?view=netframework-4.8
                    // If the specified extension is exactly three characters long,
                    // the method returns files with extensions that begin with the specified extension.
                    // For example, "*.xls" returns both "book.xls" and "book.xlsx"
                    if (assemblyFile.Extension.ToLower() != ".gha")
                    {
                        continue;
                    }

                    var key = assemblyFile.FullName.Substring(folder.FullName.Length);
                    if (map.Contains(key))
                    {
                        map.Remove(key);
                    }

                    map.Add(key, assemblyFile);
                }

                IEnumerable <FileInfo> linkFiles;
                try { linkFiles = folder.EnumerateFiles("*.ghlink", SearchOption.TopDirectoryOnly); }
                catch (System.IO.DirectoryNotFoundException) { continue; }

                foreach (var linkFile in linkFiles)
                {
                    var key = linkFile.FullName.Substring(folder.FullName.Length);
                    if (map.Contains(key))
                    {
                        map.Remove(key);
                    }

                    map.Add(key, linkFile);
                }
            }

            var assembliesList = new List <string>();

            foreach (var entry in map.Values.Cast <FileInfo>())
            {
                var extension = entry.Extension.ToLower();
                if (extension == ".gha")
                {
                    assembliesList.Add(entry.FullName);
                }
                else if (extension == ".ghlink")
                {
                    EnumGHLink(entry.FullName, assembliesList);
                }
            }

            return(assembliesList);
        }
 /// <summary>
 /// Удалить фильтр с заданным id
 /// </summary>
 /// <param name="id">id фильтра</param>
 public void DeleteFilter(string id)
 {
     filters.Remove(id);
     Invalidate();
 }