/// <summary> /// Creates a Dictionary that stores values containing embedded keys. /// </summary> /// <typeparam name="TKey">The type of keys in the collection.</typeparam> /// <typeparam name="TItem">The type of items in the collection.</typeparam> /// <param name="items">The items to populate the dictionary with.</param> /// <param name="keyExtractor">A delegate that extracts the embedded key from each item.</param> /// <param name="comparer">The comparer to use.</param> /// <param name="dictionaryCreationThreshold">The number of elements the collection can hold without creating a lookup dictionary. /// (0 creates the lookup dictionary when the first item is added), or –1 to specify that a lookup dictionary is never created. /// </param> /// <returns>An instance of the Dictionary.</returns> public static KeyedCollection <TKey, TItem> Create <TKey, TItem>(IEnumerable <TItem> items, Func <TItem, TKey> keyExtractor, IEqualityComparer <TKey> comparer, int dictionaryCreationThreshold) { if (items == null) { throw new ArgumentNullException(nameof(items)); } if (keyExtractor == null) { throw new ArgumentNullException(nameof(keyExtractor)); } if (comparer == null) { throw new ArgumentNullException(nameof(comparer)); } if (dictionaryCreationThreshold < -1) { throw new ArgumentOutOfRangeException(nameof(dictionaryCreationThreshold)); } var impl = new KeyedCollectionImpl <TKey, TItem>(keyExtractor, comparer, dictionaryCreationThreshold); foreach (var item in items) { impl.Add(item); } return(impl); }
/// <summary> /// Creates a Dictionary that stores values containing embedded keys. /// </summary> /// <typeparam name="TKey">The type of keys in the collection.</typeparam> /// <typeparam name="TItem">The type of items in the collection.</typeparam> /// <param name="keyExtractor">A delegate that extracts the embedded key from each item.</param> /// </param> /// <returns>An instance of the Dictionary.</returns> public static KeyedCollection <TKey, TItem> Create <TKey, TItem>(Func <TItem, TKey> keyExtractor) { if (keyExtractor == null) { throw new ArgumentNullException(nameof(keyExtractor)); } var impl = new KeyedCollectionImpl <TKey, TItem>(keyExtractor); return(impl); }
internal DbArmature(string name, ITextureSupplier texturer, GraphicsDevice graphics, DragonBones creator) : base(name) { Creator = creator; Texturer = texturer; GraphicsDevice = graphics; Bones = new KeyedCollectionImpl <string, DbBone>(b => b.Name); Slots = new KeyedCollectionImpl <string, DbSlot>(s => s.Name); Animations = new KeyedCollectionImpl <string, DbAnimation>(a => a.Name); IkConstraints = new List <DbIkConstraint>(); }
/// <summary> /// Creates a Dictionary that stores values containing embedded keys. /// </summary> /// <typeparam name="TKey">The type of keys in the collection.</typeparam> /// <typeparam name="TItem">The type of items in the collection.</typeparam> /// <param name="items">The items to populate the dictionary with.</param> /// <param name="keyExtractor">A delegate that extracts the embedded key from each item.</param> /// </param> /// <returns>An instance of the Dictionary.</returns> public static KeyedCollection <TKey, TItem> Create <TKey, TItem>(IEnumerable <TItem> items, Func <TItem, TKey> keyExtractor) { if (keyExtractor == null) { throw new ArgumentNullException(nameof(keyExtractor)); } var impl = new KeyedCollectionImpl <TKey, TItem>(keyExtractor); foreach (var item in items) { impl.Add(item); } return(impl); }
public static ConfigurationPackage CreatePackage(IEnumerable <KeyValuePair <string, string> > configurationParameters) { var package = CreateUninitialized <ConfigurationPackage>(); var settings = CreateUninitialized <ConfigurationSettings>(); var sections = new KeyedCollectionImpl <string, ConfigurationSection>(s => s.Name); var section = CreateUninitialized <ConfigurationSection>(); var parameters = new KeyedCollectionImpl <string, ConfigurationProperty>(p => p.Name); sections.Add(section); foreach (var keyValuePair in configurationParameters) { var parameter = CreateUninitialized <ConfigurationProperty>(); typeof(ConfigurationProperty) .GetProperty("Name") .SetValue(parameter, keyValuePair.Key); typeof(ConfigurationProperty) .GetProperty("Value") .SetValue(parameter, keyValuePair.Value); parameters.Add(parameter); } typeof(ConfigurationPackage) .GetProperty("Settings") .SetValue(package, settings); typeof(ConfigurationSettings) .GetProperty("Sections") .SetValue(settings, sections); typeof(ConfigurationSection) .GetProperty("Parameters") .SetValue(section, parameters); typeof(ConfigurationSection) .GetProperty("Name") .SetValue(section, "Configuration"); return(package); }
private bool mergeDirectoryListing(string path, ArrayList fileArrList) { bool found = false; KeyedCollectionImpl<string, FileInformation> directoryItems = new KeyedCollectionImpl<string, FileInformation>(delegate(FileInformation itemInfo) { return itemInfo.FileName; }); Trace.TraceInformation(String.Format("Creating merged directory listing for " + path)); foreach (Member m in this.members) { if(m.GetFileSystemObjectKind(path) != FileSystemObjectKind.Directory) { continue; } string realPath = m.GetRootedPath(path); found = true; foreach (FileSystemInfo fsInfo in new DirectoryInfo(realPath).GetFileSystemInfos()) { FileInformation fi = new FileInformation(); fi.Attributes = fsInfo.Attributes; fi.CreationTime = fsInfo.CreationTime; fi.FileName = fsInfo.Name; fi.LastAccessTime = fsInfo.LastAccessTime; fi.LastWriteTime = fsInfo.LastWriteTime; if (fsInfo is FileInfo) { fi.Length = (fsInfo as FileInfo).Length; } else { fi.Length = 0; } if (!directoryItems.Contains(fi.FileName)) { directoryItems.Add(fi); Trace.TraceInformation(String.Format("Found object {0}, size {1} bytes", fi.FileName, fi.Length)); } } } foreach (FileInformation fi in directoryItems) { fileArrList.Add(fi); } return found; }