/// <inheritdoc/> public virtual bool TryGetBehaviors(string name, out IBehaviorContainer ebd) { _lock.EnterUpgradeableReadLock(); try { if (_dictionary.TryGetValue(name, out ebd)) return true; // Try asking our event var args = new BehaviorsNotFoundEventArgs(name); OnBehaviorsNotFound(args); if (args.Behaviors != null) { ebd = args.Behaviors; return true; } // Nothing found ebd = null; return false; } finally { _lock.ExitUpgradeableReadLock(); } }
/// <inheritdoc/> public virtual IBehaviorContainer this[string name] { get { name.ThrowIfNull(nameof(name)); _lock.EnterUpgradeableReadLock(); try { if (_dictionary.TryGetValue(name, out var result)) { return(result); } var args = new BehaviorsNotFoundEventArgs(name); OnBehaviorsNotFound(args); if (args.Behaviors != null) { return(args.Behaviors); } // The behaviors could not be found... throw new BehaviorsNotFoundException(name, Properties.Resources.Behaviors_NoBehaviorFor.FormatString(name)); } finally { _lock.ExitUpgradeableReadLock(); } } }
/// <summary> /// Raises the <see cref="BehaviorsNotFound" /> event. /// </summary> /// <param name="args">The <see cref="BehaviorsNotFoundEventArgs"/> instance containing the event data.</param> protected virtual void OnBehaviorsNotFound(BehaviorsNotFoundEventArgs args) => BehaviorsNotFound?.Invoke(this, args);