internal void Internalize(IMetricDefinition metricDefinition) { lock (Lock) { Monitor.MetricDefinition internaldefinition = metricDefinition.WrappedDefinition; m_Externalized[internaldefinition] = metricDefinition; } }
/// <summary> /// Add an existing IMetricDefinition item to this collection. /// </summary> /// <remarks>If the supplied MetricDefinitin item is already in the collection, an exception will be thrown.</remarks> /// <param name="item">The new IMetricDefinition item to add.</param> /// <exception cref="ArgumentNullException">The provided item was null</exception> public void Add(IMetricDefinition item) { //we really don't want to support this method, but we have to for ICollection<T> compatibility. So we're going to ruthlessly //verify that the metric object was created correctly. if (item == null) { throw new ArgumentNullException(nameof(item)); } lock (Lock) { // Set up our mapping of internal to API definition objects for the one we're about to add... Monitor.MetricDefinition internalDefinition = item.WrappedDefinition; m_Externalized[internalDefinition] = item; m_WrappedCollection.Add(internalDefinition); // ...Then add it to the internal collection. } //and fire our event, outside the lock // Note: This is not done by subscribing to the event from the internal collection, which happens inside the lock! OnCollectionChanged(new Monitor.CollectionChangedEventArgs <MetricDefinitionCollection, IMetricDefinition>(this, item, Monitor.CollectionAction.Added)); }