public virtual IPolicy AddDependency(IPolicy dependency) { if (dependency.Parent == this || dependency == this) { return(this); } if (dependency.IsDependency(this)) { throw new InvalidOperationException("Cyclic dependency detected"); } dependency.Parent?.RemoveDependency(dependency); if (!_dependencies.Contains(dependency)) { _dependencies.Add(dependency); } dependency.Parent = this; return(this); }