Exemplo n.º 1
0
        //public static IEnumerable<ReadOnlyGrandparent> SomeAlgorithm(IEnumerable<ReadOnlyGrandparent> input,
        //    Func<ReadOnlyGrandparent, string> parentSelector, Func<ReadOnlyParent, bool> parentSelector,
        //    Func<ReadOnlyParent, bool> removeParentSelector, ImmutableSupport support) {
        //    foreach (var p in input) {
        //        string markerToAdd = parentSelector(p);
        //        if (markerToAdd != null) {
        //            //p.Variable++;
        //            p.GetOrCreateMutable(support).Variable++;
        //        }
        //        if (parentSelector(p.Parent)) {
        //            p.Parent.GetOrCreateMutable(support).Variable++;
        //        }
        //        foreach (var c in p.Parentren.Where(c => parentSelector(c))) {
        //            c.GetOrCreateMutable(support).Variable++;
        //        }
        //        p.GetOrCreateMutable(support).Parentren.RemoveAll(c => removeParentSelector(c));
        //    }
        //
        //    return input.Immutify<ReadOnlyGrandparent, ReadWriteGrandparent>(support);
        //}

        protected override ReadOnlyGrandparent Immutify(ReadWriteGrandparent mutable, ImmutableSupport support)
        {
            IGrandparent   source   = mutable ?? (IGrandparent)this;
            int            variable = source.Variable;
            ReadOnlyParent parent   = support.Immutify <ReadOnlyParent, ReadWriteParent>(Parent);

            return(Equals(variable, Variable) && Equals(parent, Parent)
                ? this
                : new ReadOnlyGrandparent(FixedName, variable, parent));
        }
Exemplo n.º 2
0
        public void SetupReciprocatedRelationship(ISpecificationModel relatedModel, IRelationship reciprocatedRelationship)
        {
            if (reciprocatedRelationship is IAdmire)
            {
                IEnemy enemy = this.testingFactory.GenerateEnemy(this, relatedModel, reciprocatedRelationship.ReferencingProperty);

                this.associates.Add(enemy);
                this.enemies.Add(enemy);
                this.relationships.Add(enemy);
            }
            else if (reciprocatedRelationship is IGodchild)
            {
                IGodfather godfather = this.testingFactory.GenerateGodfather(this, relatedModel, reciprocatedRelationship.ReferencingProperty);

                this.godfathers.Add(godfather);
                this.parents.Add(godfather);
                this.relationships.Add(godfather);
            }
            else if (reciprocatedRelationship is IGrandchild)
            {
                IGrandparent grandparent = this.testingFactory.GenerateGrandparent(this, relatedModel, reciprocatedRelationship.ReferencingProperty);

                this.grandparents.Add(grandparent);
                this.parents.Add(grandparent);
                this.relationships.Add(grandparent);
            }
            else if (reciprocatedRelationship is IUnfitParent)
            {
                ICustodiedChild custodiedChild = this.testingFactory.GenerateCustodiedChild(this, relatedModel, reciprocatedRelationship.ReferencingProperty);

                this.children.Add(custodiedChild);
                this.custodiedChildren.Add(custodiedChild);
                this.relationships.Add(custodiedChild);
            }
            else
            {
                throw new NotImplementedException(new StringBuilder("Setup ").Append(relatedModel.Variable.VariableType.Name).Append("'s reciprocated relationship for property ").Append(reciprocatedRelationship.ReferencingProperty.Name).ToString());
            }
        }