/// <summary> /// Configures the Default handler. /// </summary> /// <typeparam name="TSub">The new type</typeparam> /// <typeparam name="TParent">the current parent type</typeparam> /// <param name="accessor">Lambda expression that access the property message lookup.</param> /// <param name="configure">Lambda expression that configures the mapping</param> public void ConfigureDefault <TSub>(Action <IConfigureChain <TSub> > configure, LookupStrategyEnum lookupStrategy = LookupStrategyEnum.ConcreteOnly) { SelectorMapper <TSub> mapper = new SelectorMapper <TSub>(lookupStrategy); DefaultItem = mapper; configure(mapper); }
/// <summary> /// Helper method used to add a conditional configuration from /// the relay object. /// </summary> /// <param name="condition">Lambda expression to use to test if the condition is true.</param> /// <param name="item">Item to map to the condition.</param> public void AddConditionItem(Func <T, bool> condition, IMappedItem item) { Items.Add(new ConditionalItem <T>() { ConditionTest = condition, Item = item }); }
/// <summary> /// Configures the Default handler. /// </summary> /// <typeparam name="TSub">The new type</typeparam> /// <typeparam name="TParent">the current parent type</typeparam> /// <param name="accessor">Lambda expression that access the property message lookup.</param> /// <param name="configure">Lambda expression that configures the mapping</param> public void ConfigureDefault <TSub, TParent>(Func <TParent, TSub> accessor, Action <IConfigureChain <TSub> > configure, LookupStrategyEnum lookupStrategy = LookupStrategyEnum.ConcreteOnly) { SelectorMapper <TSub> mapper = new SelectorMapperSub <TParent, TSub>(accessor, lookupStrategy); DefaultItem = mapper; configure(mapper); }
/// <summary> /// Gets the messages that's mapped to the specified type. /// </summary> /// <param name="type">The type to get the message for.</param> /// <returns>string</returns> protected override string GetMessageFromMapping(Type type) { IMappedItem item = FindItem(type); if (item != null) { return(item.GetMessage(type)); } return(string.Empty); }
/// <summary> /// Find the items to use for getting the message. If the object /// is not mapped, then it will return the default item. If the /// default item is not set, then it will retrun null; /// </summary> /// <param name="obj">Object/value to find</param> /// <returns>IMappedItem or null</returns> protected IMappedItem FindItem(object obj) { IMappedItem item = Mapper.Find(obj); if (item != null) { return(item); } return(DefaultItem); }
/// <summary> /// Gets the messages that's mapped to the specified object. /// </summary> /// <param name="obj">The object to get the message for.</param> /// <returns>string</returns> protected override string GetMessageFromMapping(object obj) { IMappedItem item = FindItem(obj); if (item != null) { return(item.GetMessage(obj)); } return(string.Empty); }
/// <summary> /// Find the items to use for getting the message. If the object /// is not mapped, then it will return the default item. If the /// default item is not set, then it will retrun null; /// </summary> /// <param name="type">Object type to find</param> /// <returns>IMappedItem or null</returns> protected IMappedItem FindItem(Type type) { IMappedItem item = Mapper.Find(type); if (item != null) { return(item); } return(DefaultItem); }
protected override string GetMessageFromMapping(object obj) { TSub subItem = SubItemAccessor((T)obj); IMappedItem item = FindItem(subItem); if (item != null) { return(item.GetMessage(subItem)); } return(string.Empty); }
/// <summary> /// Private helper method for adding an item to the selector's mapper. /// It check if the item is Type based or Value based and calls /// the appropriate add method. /// </summary> /// <param name="item"></param> private void AddToSelectorMap(IMappedItem item) { if (ValueBased) { Selector.Mapper.Add(Value, item); } else { Selector.Mapper.Add <T>(item); } }
public void AddObject(IMappedItem o, string mapName, SectorCoordinates coordinates) { //ISectorMap sectorMap = _sectorMaps.SingleOrDefault(map => map.Name == mapName); //if (sectorMap != null) //{ // Sector sector = sectorMap.GetSector(coordinates); // if (sector != null) // { // lock (_itemLocations) // { // //_itemLocations.Add(o.Id, sector); // sector.AddItem(o); // //o.Location = sector.Location; // } // } //} }
public void MoveObject(IMappedItem o, SectorCoordinates toCoordinates) { //Sector sector = new Sector("", SectorCoordinates.None);//_itemLocations[o.Id]; //ISectorMap sectorMap = _sectorMaps.SingleOrDefault(map => map.Name == sector.Location.MapName); //Debug.Assert(sectorMap != null); //Sector toSector = sectorMap.GetSector(toCoordinates); //// check toSector is a valid destination //if (toSector != null) //{ // lock (_itemLocations) // { // sector.RemoveItem(o); // //_itemLocations[o.Id] = toSector; // toSector.AddItem(o); // //o.Location = sector.Location; // } //} }
/// <summary> /// This should not be valid in this context. A value /// mapper should only be value Add and not the Type /// Add. /// </summary> /// <exception cref="InvalidOperationException">Always throws.</exception> public void Add <TKey>(IMappedItem mappedItem) { throw new InvalidOperationException("Mapping Types are not supported on value type mappings."); }
/// <summary> /// Helper Method that sets the default /// </summary> /// <param name="mappedItem"></param> public void SetDefaultMappedItem(IMappedItem mappedItem) { DefaultItem = mappedItem; }
public void MoveObject(IMappedItem o, string toMapName, SectorCoordinates toCoordinates) { throw new NotImplementedException(); }
public void AddObject(IMappedItem item, SectorCoordinates coordinates) { Sector sector = Sectors.SingleOrDefault(x => x.Coordinates == coordinates); if (sector != null) { lock (_trackedItems) // later check if locking is necessary. could be handled at a higher level. { _trackedItems.Add(item.Id, item); _itemLocations.Add(item.Id, sector.Id); } } }
public void MoveObject(IMappedItem item, SectorCoordinates toCoordinates) { Sector sector = Sectors.SingleOrDefault(x => x.Coordinates == toCoordinates); if (sector != null && _trackedItems.ContainsKey(item.Id)) // && toCoordinates are not same as current? { lock (_trackedItems) // later check if locking is necessary. could be handled at a higher level. { _itemLocations[item.Id] = sector.Id; } } }
public void RemoveItem(IMappedItem item) { if (_trackedItems.ContainsKey(item.Id)) { lock (_trackedItems) { _trackedItems.Remove(item.Id); _itemLocations.Remove(item.Id); } } }
/// <summary> /// Adds an item to the map and maps it to the given object's type. /// </summary> /// <param name="value">The object to get the type from.</param> /// <param name="mappedItem">The item to map.</param> public void Add(object value, IMappedItem mappedItem) { Map.Add(value.GetType(), mappedItem); }
/// <summary> /// Adds the item to the map and maps it to the given type. /// </summary> /// <typeparam name="TKey">The type to map the item to.</typeparam> /// <param name="mappedItem">The item that's mapped.</param> public void Add <TKey>(IMappedItem mappedItem) { Map.Add(typeof(TKey), mappedItem); }
/// <summary> /// Adds an item to the map and maps it to the value given. /// </summary> /// <param name="value">The value.</param> /// <param name="mappedItem">The item to map.</param> public void Add(object value, IMappedItem mappedItem) { Map.Add((T)value, mappedItem); }
public Location2 GetLocation(IMappedItem o) { return Location2.None;//_itemLocations[o.Id].Location; }