/// <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); }
internal void Initialize(ArmatureData data) { FrameRate = data.FrameRate; if (data.Bones.Any()) { Bones.Add(new DbBone(this, data.Bones[0])); for (var i = 1; i < data.Bones.Length; i++) { var bone = data.Bones[i]; var parentBone = Bones[bone.Parent]; parentBone.AddBone(new DbBone(this, bone)); } } foreach (var slot in data.Slots) { var parentBone = Bones[slot.Parent]; parentBone.AddSlot(new DbSlot(this, slot)); } foreach (var fill in data.Skins[0].SlotFills) { var slot = Slots[fill.SlotName]; foreach (var display in fill.Displays) { slot.AddDisplay(display); } } foreach (var animation in data.Animations) { Animations.Add(new DbAnimation(this, animation)); } foreach (var ik in data.InverseKinematics) { IkConstraints.Add(new DbIkConstraint(ik)); // TODO } SortSlots(); ResetBones(); // load DefaultActions into Dictionary DefaultActions = data.DefaultActions[0]; if (DefaultActions.ContainsKey("gotoAndPlay") && Animations.Contains(DefaultActions["gotoAndPlay"])) { GotoAndPlay(DefaultActions["gotoAndPlay"]); } }
/// <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; }
/// <summary> /// Add a slot to this armature. /// </summary> /// <param name="slot"></param> public void AddSlot(DbSlot slot) { Slots.Add(slot); }