public CollectionOfCollections <Plan> GetPlansInterface(Type t) { if (!t.IsInterface) { throw new ArgumentException("must be an interface."); } CollectionOfCollections <Plan> retval = new CollectionOfCollections <Plan>(); foreach (Type dbType in plansByType.Keys) { if (dbType.Equals(t)) { retval.Add(plansByType[dbType]); } else { foreach (Type interfaceType in dbType.GetInterfaces()) { if (t.Equals(interfaceType)) { retval.Add(plansByType[dbType]); break; } } } } return(retval); }
public void TrackedCollectionOfCollections_DoesNotPopulateInnerCollectionItemChanges() { CollectionOfCollectionsObject = new CollectionOfCollections(); var inner = new ObservableCollection <Person>(); int age = -1; CollectionOfCollectionsObject.DeepCollection.Add(inner); React.To(() => CollectionOfCollectionsObject.DeepCollection .TrackItems().First().FirstOrDefault()) .Where(p => p != null).Set(p => age = p.Age); var person = new Person() { Age = 10 }; inner.Add(person); age.Should().Be(10, "as person has been added to the inner collection, its Count has changed. " + "Expression should be reevaluated."); person.Age = 20; age.Should().Be(10, "person is located in the inner collection and property changes of " + "individual (inner) items should not be tracked."); }
internal Plan RandomPlan(Type typeDesired) { CollectionOfCollections <Plan> plans = GetPlans(typeDesired); // TODO GetPlans should do null or zero-sized list, and you // should only have to check for one. if (plans == null || plans.Size() == 0) { return(null); } return(plans.Get(Common.Enviroment.Random.Next(plans.Size()))); }
internal Plan RandomPlan(Type typeDesired) { CollectionOfCollections <Plan> plans = GetPlans(typeDesired); // TODO GetPlans should do null or zero-sized list, and you // should only have to check for one. if (plans == null || plans.Size() == 0) { return(null); } int randnum = Common.Enviroment.Random.Next(plans.Size()); //[email protected] adds for debug return(plans.Get(randnum)); }
/// <summary> /// Returns a list of plans of type t in the database. /// New: The list returned can be empty if its a valuetype and a default value can't be created /// </summary> /// <param name="t">The type of plan desired.</param> /// <returns></returns> private CollectionOfCollections <Plan> GetPlans(Type t) { if (!plansByType.ContainsKey(t)) { bool success; Plan pl = DefaultPlan(t, out success); if (success) { AddPlan(pl); } else { return(null); } } Util.Assert(plansByType[t] != null); if (t.IsInterface) { return(GetPlansInterface(t)); } CollectionOfCollections <Plan> retval = new CollectionOfCollections <Plan>(); retval.Add(plansByType[t]); if (typeMatchingMode == TypeMatchingMode.SubTypes) { foreach (Type dbType in typeMap.TypesWithPlans(t).Keys) { Util.Assert(ReflectionUtils.IsSubclassOrEqual(dbType, t)); retval.Add(plansByType[dbType]); } } return(retval); }
public void NonTrackedCollectionOfCollections_DoesNotPopulateEvenOuterCollectionItemChanges() { CollectionOfCollectionsObject = new CollectionOfCollections(); var inner = new ObservableCollection <Person>(); int age = -1; CollectionOfCollectionsObject.DeepCollection.Add(inner); React.To(() => CollectionOfCollectionsObject.DeepCollection.First().FirstOrDefault()). Where(p => p != null).Set(p => age = p.Age); var person = new Person() { Age = 10 }; inner.Add(person); age.Should().Be(-1, "item tracking is off. Even items of the outer collection " + "should not be listened to."); person.Age = 20; age.Should().Be(-1, "item tracking is off"); }
public CollectionOfCollections<Plan> GetPlansInterface(Type t) { if (!t.IsInterface) throw new ArgumentException("must be an interface."); CollectionOfCollections<Plan> retval = new CollectionOfCollections<Plan>(); foreach (Type dbType in plansByType.Keys) { if (dbType.Equals(t)) retval.Add(plansByType[dbType]); else { foreach (Type interfaceType in dbType.GetInterfaces()) if (t.Equals(interfaceType)) { retval.Add(plansByType[dbType]); break; } } } return retval; }
/// <summary> /// Returns a list of plans of type t in the database. /// New: The list returned can be empty if its a valuetype and a default value can't be created /// </summary> /// <param name="t">The type of plan desired.</param> /// <returns></returns> private CollectionOfCollections<Plan> GetPlans(Type t) { if (!plansByType.ContainsKey(t)) { bool success; Plan pl = DefaultPlan(t, out success); if (success) { AddPlan(pl); } else return null; } Util.Assert(plansByType[t] != null); if (t.IsInterface) return GetPlansInterface(t); CollectionOfCollections<Plan> retval = new CollectionOfCollections<Plan>(); retval.Add(plansByType[t]); if (typeMatchingMode == TypeMatchingMode.SubTypes) { foreach (Type dbType in typeMap.TypesWithPlans(t).Keys) { Util.Assert(ReflectionUtils.IsSubclassOrEqual(dbType, t)); retval.Add(plansByType[dbType]); } } return retval; }