static void Main(string[] args) { try { Gym gym = new Gym(); gym.Add(new Tennis()); gym.Add(new Basketball()); //gym.Remove(4); //index 1 СontrollerGym contr_gym = new СontrollerGym(1000); contr_gym.Add(new Shells(50)); //contr_gym.Add(new Shells(40)); //budget 2 Shells sh = new Shells(32); //sh.Amount = 2000; //max 3 Gym gym2 = null; //gym2.Add(new Beams(1)); Debug.Assert(gym2 != null, "Ссылка на объект не указывает на экземпляр объекта"); int b, a = 2, c = 0; //b = a / c; } catch (IndexException e) { Console.WriteLine(e.Message); } catch (BudgetException e) { Console.WriteLine(e.Message); } catch (MaxException e) { Console.WriteLine(e.Message); } catch (Exception e) { Console.WriteLine(e.Message); } finally { Console.WriteLine("Переход к finally."); } Console.ReadLine(); }
public void Remove(IPsbPlugin plugin) { if (plugin is IPsbImageFormatter f) { f.Extensions.ForEach(ext => ImageFormatters.Remove(ext)); } if (plugin is IPsbShell s) { Shells.Remove(s.Name); } if (plugin is IPsbKeyProvider) { _keyProvider = null; } _plugins.Remove(plugin); }
/// <summary>Returns a string that represents the current object.</summary> /// <returns>A string that represents the current object.</returns> public override string ToString() { var sb = new StringBuilder(); for (var i = 0; i < Shells.Count; i++) { Shell current = Shells.ToArray()[i]; if (i < Shells.Count - 1) { sb.Append(current + " "); continue; } sb.Append(current); } return(sb.ToString()); }
/// <summary> /// Converts the current <see cref="ShellConfiguration"/> instance to a dictionary. /// </summary> public Dictionary <char, int> ToDictionary() { return(Shells.ToDictionary(x => x.Symbol, y => y.Electrons)); }
/// <summary> /// Populates the current <see cref="ShellConfiguration"/> instance. /// </summary> public void Populate() { int left = Element.Electrons; for (var i = 0; i < ChemistryUtils.EnergyLevelConfiguration.Count; i++) { if (left == 0) { break; } KeyValuePair <char, char[]> pair = ChemistryUtils.EnergyLevelConfiguration.ToList()[i]; Shell shell = this[pair.Key]; for (int x = 0; x < pair.Value.Length; x++) { if (left == 0) { break; } Subshell subshell = shell[pair.Value[x]]; if (subshell.Electrons > 0) { continue; } if (left - subshell.Capacity < 0) { subshell.Populate(left); left = 0; } else { subshell.Populate(subshell.Capacity); left -= subshell.Capacity; } int stepsDown = x; for (int z = 0; z < stepsDown; z++) { if (left == 0) { break; } Subshell diagonal = Shells.ToList()[i + z + 1].Subshells[x - (z + 1)]; if (left - diagonal.Capacity < 0) { diagonal.Populate(left); left = 0; } else { diagonal.Populate(diagonal.Capacity); left -= diagonal.Capacity; } } } } foreach (var shell in Shells.ToArray()) { foreach (var subshell in shell.Subshells.ToArray()) { if (subshell.Electrons == 0) { shell.Subshells.Remove(subshell); } } if (shell.Electrons == 0) { Shells.Remove(shell); } } }
public bool Compute() { bool enable_thin_check = false; double thin_check_offset = ToolWidth * 0.45; double thin_check_thresh_sqr = ToolWidth * 0.3; thin_check_thresh_sqr *= thin_check_thresh_sqr; // first shell is either polygon, or inset from that polygon List <GeneralPolygon2d> current = null; if (InsetFromInputPolygonX != 0) { current = ComputeInitialInsetPolygon(PreserveInputInsetTopology); } else { current = new List <GeneralPolygon2d>() { Polygon }; } List <GeneralPolygon2d> current_prev = null; if (current.Count == 0) { HandleTinyPolygon(); return(true); } // convert previous layer to shell, and then compute next layer List <GeneralPolygon2d> failedShells = new List <GeneralPolygon2d>(); List <GeneralPolygon2d> nextShellTooThin = new List <GeneralPolygon2d>(); for (int i = 0; i < Layers; ++i) { FillCurveSet2d paths = ShellPolysToPaths(current, i); Shells.Add(paths); List <GeneralPolygon2d> all_next = new List <GeneralPolygon2d>(); foreach (GeneralPolygon2d gpoly in current) { List <GeneralPolygon2d> offsets = ClipperUtil.ComputeOffsetPolygon(gpoly, -PathSpacing, true); List <GeneralPolygon2d> filtered = new List <GeneralPolygon2d>(); foreach (var v in offsets) { bool bTooSmall = (v.Perimeter < DiscardTinyPerimterLengthMM || v.Area < DiscardTinyPolygonAreaMM2); if (bTooSmall) { continue; } if (enable_thin_check && is_too_thin(v, thin_check_offset, thin_check_thresh_sqr)) { nextShellTooThin.Add(v); } else { filtered.Add(v); } } if (filtered.Count == 0) { failedShells.Add(gpoly); } else { all_next.AddRange(filtered); } } current_prev = current; current = all_next; } // failedShells have no space for internal contours. But // we might be able to fit a single line... //foreach (GeneralPolygon2d gpoly in failedShells) { // if (gpoly.Perimeter < DiscardTinyPerimterLengthMM || // gpoly.Area < DiscardTinyPolygonAreaMM2) // continue; // List<FillPolyline2d> thin_shells = thin_offset(gpoly); // Shells[Shells.Count - 1].Append(thin_shells); //} // remaining inner polygons if (InsetInnerPolygons) { InnerPolygons = current; InnerPolygons.AddRange(nextShellTooThin); } else { InnerPolygons = current_prev; InnerPolygons.AddRange(nextShellTooThin); } return(true); }
/// <summary> /// 親子づけの設定 /// </summary> public void Parent(T item, T parent) { if (item == null) { throw new ArgumentNullException(nameof(item)); } if (!Shells.TryGetValue(item, out var property)) { throw new ArgumentException(string.Format(Properties.Resources.MESSAGE_EXCEPTION_ARGUMENT_TARGET_UNCONTAINED_ITEM_FORMAT, nameof(item))); } var currentParent = property.Core.Value; if (parent == currentParent) { return; } if (EvaluateDescendant(parent, item)) { throw new ArgumentException(string.Format(Properties.Resources.MESSAGE_EXCEPTION_ARGUMENT_PARENT_TO_DESCENDANT_FORMAT, nameof(parent), nameof(item))); } const int SearchIndex = 0x00000001 << 0; const int SearchCount = 0x00000001 << 1; const int SearchParent = 0x00000001 << 2; const int SearchTargetIndex = 0x00000001 << 3; var index = -1; var count = 0; var targetIndex = -1; var searchMode = SearchIndex; if (parent != null) { if (parent == item) { throw new ArgumentException(string.Format(Properties.Resources.MESSAGE_EXCEPTION_ARGUMENT_SAME_TARGET_FORMAT, nameof(parent), nameof(item))); } searchMode |= SearchParent; for (var sampleIndex = 0; sampleIndex < Count; ++sampleIndex) { var sample = Shells[sampleIndex]; if ((searchMode & SearchCount) == SearchCount) { if (!EvaluateDescendant(sample.Key, item)) { count = sampleIndex - index; searchMode ^= SearchCount; } } else if ((searchMode & SearchIndex) == SearchIndex) { if (Equals(sample.Key, item)) { index = sampleIndex; count = 1; searchMode ^= SearchIndex; searchMode |= SearchCount; } } if ((searchMode & SearchTargetIndex) == SearchTargetIndex) { if (!EvaluateDescendant(sample.Key, parent)) { searchMode ^= SearchTargetIndex; } else { targetIndex = sampleIndex; } } else if ((searchMode & SearchParent) == SearchParent) { if (Equals(sample.Key, parent)) { targetIndex = sampleIndex; searchMode ^= SearchParent; searchMode |= SearchTargetIndex; } } if (searchMode == 0x00000000) { break; } } if (targetIndex == -1) { throw new ArgumentException(string.Format(Properties.Resources.MESSAGE_EXCEPTION_ARGUMENT_TARGET_UNCONTAINED_ITEM_FORMAT, nameof(parent))); } } else { searchMode |= SearchParent; for (var sampleIndex = 0; sampleIndex < Count; ++sampleIndex) { var sample = Shells[sampleIndex]; if ((searchMode & SearchCount) == SearchCount) { if (!EvaluateDescendant(sample.Key, item)) { count = sampleIndex - index; searchMode ^= SearchCount; } } else if ((searchMode & SearchIndex) == SearchIndex) { if (Equals(sample.Key, item)) { index = sampleIndex; count = 1; searchMode ^= SearchIndex; searchMode |= SearchCount; } } if ((searchMode & SearchTargetIndex) == SearchTargetIndex) { if (!EvaluateDescendant(sample.Key, currentParent)) { searchMode ^= SearchTargetIndex; } else { targetIndex = sampleIndex; } } else if ((searchMode & SearchParent) == SearchParent) { if (Equals(sample.Key, currentParent)) { targetIndex = sampleIndex; searchMode ^= SearchParent; searchMode |= SearchTargetIndex; } } if (searchMode == 0x00000000) { break; } } } SetItem(index, Shells[index].Key, parent); if (targetIndex < index) { var movingIndex = targetIndex + 1; for (var i = 0; i < count; ++i) { MoveItem(index + i, movingIndex + i); } } else { var movingIndex = targetIndex; for (var i = 0; i < count; ++i) { MoveItem(index, movingIndex); } } }
/// <summary> /// 包含判定 /// </summary> public bool Contains(T item) => Shells.Contains(item);
/// <summary> /// キーの包含判定 /// </summary> public bool ContainsKey(TKey key) => Shells.Contains(key);
bool IDictionary.Contains(object key) => Shells.Contains((TKey)key);
void ICollection.CopyTo(Array array, int arrayIndex) { if (array == null) { throw new ArgumentNullException(nameof(array)); } if (array.Rank != 1) { throw new ArgumentException(Echo.Properties.Resources.MESSAGE_EXCEPTION_ARGUMENT_MULTI_DIMENSION_ARRAY); } if (array.GetLowerBound(0) != 0) { throw new ArgumentException(Echo.Properties.Resources.MESSAGE_EXCEPTION_ARGUMENT_NON_ZERO_LOWER_BOUND_OF_ARRAY); } if (arrayIndex < 0 || arrayIndex > array.Length) { throw new ArgumentOutOfRangeException(nameof(arrayIndex), Echo.Properties.Resources.MESSAGE_EXCEPTION_ARGUMENT_OUT_OF_RANGE_NEGATIVE_NUMBER); } if (array.Length - arrayIndex < Count) { throw new ArgumentException(Echo.Properties.Resources.MESSAGE_EXCEPTION_ARGUMENT_SHORT_LENGTH_ARRAY); } if (array is TValue[] values) { CopyTo(values, arrayIndex); } else if (array is DataProperty <TValue>[] items) { CopyTo(items, arrayIndex); } else if (array is DictionaryEntry[] dictionaryEntries) { foreach (var shell in this) { dictionaryEntries[arrayIndex++] = new DictionaryEntry(shell.Key, shell.Core); } } else if (array is KeyValuePair <TKey, DataProperty <TValue> >[] keyValuePairs) { foreach (var shell in this) { keyValuePairs[arrayIndex++] = shell.KeyValuePair; } } else if (array is DataPropertyShell <TKey, TValue>[] shells) { Shells.CopyTo(shells, arrayIndex); } else { var objects = array as object[]; if (objects == null) { throw new ArgumentException(Echo.Properties.Resources.MESSAGE_EXCEPTION_ARGUMENT_INVALID_TYPED_ARRAY); } try { foreach (var shell in this) { objects[arrayIndex++] = shell; } } catch (ArrayTypeMismatchException) { throw new ArgumentException(Echo.Properties.Resources.MESSAGE_EXCEPTION_ARGUMENT_INVALID_TYPED_ARRAY); } } }
static void Main(string[] args) { /*Созд. необобщ. коллекцию ArrayList * а) заполн. 5 целыми числами * б) добав. строку * в) добав объект Student * г) удал задан эл-т * д) вывод кол-во эл и коллекцию на консоль * е) поиск значения в коллекции */ ArrayList arrayList = new ArrayList(); arrayList.AddRange(new int[] { 1, 2, 3, 4, 5 }); arrayList.Add("Строка"); arrayList.Add(new Tennis()); arrayList.Remove(5); ShowArrList(arrayList); Console.WriteLine($"Индекс '1' - {arrayList.IndexOf(1)}"); Console.WriteLine($"Индекс 'Строка' - {arrayList.IndexOf("Строка")}"); Console.WriteLine($"Индекс '4' - {arrayList.IndexOf(4)}\n\n\n"); /*Созд. обобщ. коллекцию Stack<T> * заполн. д-мы типа double * а) вывести * б) удал эл-ты */ Stack <double> stack = new Stack <double>(); double[] arrDb = new double[] { 1.1, 2.2, 3.3, 4.4, 5.5, 6.6, 7.7 }; for (int i = arrDb.Length - 1; i > -1; i--) { stack.Push(arrDb[i]); } ShowStack(stack); StackRemove(ref stack, 2.2); StackRemove(ref stack, 1); ShowStack(stack); Console.WriteLine("\n\n\n"); /*Cозд. коллекцию LinkedList<T> * заполн. ее д-ми из первой коллекции * д) вывести * е) поиск задан значения */ LinkedList <double> linkedList = new LinkedList <double>(); for (; stack.Count != 0;) { linkedList.AddLast(stack.Pop()); } ShowLinkedList(linkedList); Console.WriteLine("linkedList Find '3.3'"); Console.WriteLine(linkedList.Find(3.3).Value); Console.WriteLine("linkedList Find '1.1'"); Console.WriteLine(linkedList.Find(1.1).Value + "\n\n\n"); /*аналогично для своего тд*/ Stack <Shells> sh_stack = new Stack <Shells>(); for (int i = 0; i < 5; i++) { sh_stack.Push(new Shells(i)); } foreach (Shells item in sh_stack) { Console.Write(item.Price + " "); } Console.WriteLine(); LinkedList <Shells> sh_list = new LinkedList <Shells>(); for (; sh_stack.Count != 0;) { sh_list.AddLast(sh_stack.Pop()); } foreach (Shells item in sh_list) { Console.Write(item.Price + " "); } Console.WriteLine(); /*Cозд. объект наблюдаемой кол ObservableCollection<T> * созд. метод и зарег его на событие CollectionChange * демонстр с удалением эл-тов * Т - мой класс */ ObservableCollection <Shells> obs = new ObservableCollection <Shells>(); obs.CollectionChanged += Obs_CollectionChanged;///метод справа рег. на событие слева Shells sh = new Shells(30); obs.Add(new Shells(10)); obs.Add(sh); obs.Add(new Shells(20)); obs.Remove(sh); foreach (Shells i in obs) { Console.WriteLine(i.Price); } Console.ReadLine(); }
public void HybridizeOrbits(int hybridizedCount) { var lShell = Shells.FirstOrDefault(s => s is LShell) as LShell; lShell?.HybridizeOrbits(hybridizedCount); }
/// <summary> /// 値の包含判定 /// </summary> public void ContainsValue(TValue value) => Shells.Any(_ => Equals(_.Core.Value, value));
/// <summary> /// Gets a <see cref="Shell"/> with the specified symbol. /// </summary> /// <param name="symbol">The symbol.</param> /// <returns></returns> public Shell this[char symbol] => Shells.FirstOrDefault(x => x.Symbol == symbol);
public IEnumerator <DataPropertyShell <TKey, TValue> > GetEnumerator() => Shells.GetEnumerator();
bool IReadOnlyDictionary <TKey, DataProperty <TValue> > .ContainsKey(TKey key) => Shells.Contains(key);