public static IPlate GetPlate(string plateJsonString) { var jsonDocument = JsonDocument.Parse(plateJsonString); var rootElement = jsonDocument.RootElement; var name = rootElement.GetProperty("name").GetString(); var properties = ( UdfsHelper.SubjectJsonElementToSubjectPropertyDictionary(rootElement) ) .Concat ( UdfsHelper.UdfsJsonElementToPropertyDictionary(jsonDocument.RootElement.GetProperty("udfs")) ) .ToDictionary(x => x.Key, x => x.Value); if (!properties.ContainsKey("Plate Type")) { throw new InvalidSubjectTypeException(name, "Plate", properties["subject_type:name"]); } var plateType = properties["Plate Type"]; IPlate plate = plateType switch { "Viral Prep Plate" => new Plate96(name, properties), "RNA Plate" => new Plate96(name, properties), "PCR Plate" => new Plate384(name, properties), _ => throw new Exception($"Unhandled {nameof(plateType)}: {plateType}"), }; return(plate); }
static void Main(string[] args) { var plates = new List <IPlateNG>(); plates.Add(new HugePlate()); plates.Add(new SmallPlate()); IPlateNG aPlate = plates[0]; IWaffle aWaffle = aPlate.GetWaffle(); Console.WriteLine(aWaffle.Eat()); IPlate <FalafelWaffle> aSmallPlate = (SmallPlate)plates[1]; FalafelWaffle aFalafel = aSmallPlate.GetMyWaffle(); Console.WriteLine(aFalafel.Dinner()); Console.ReadKey(); }
static void Main(string[] args) { // The list cannot work with the IPlate<IWaffle> anymore. So here comes IPlateNG to the rescue var plates = new List <IPlateNG>(); plates.Add(new HugePlate()); plates.Add(new SmallPlate()); IPlateNG aPlate = plates[0]; // And instead of calling to the GetMyWaffle method we can call to the GetWaffle in this case IWaffle aWaffle = aPlate.GetWaffle(); Console.WriteLine(aWaffle.Eat()); IPlate <FalafelWaffle> aSmallPlate = (SmallPlate)plates[1]; FalafelWaffle aFalafel = aSmallPlate.GetMyWaffle(); Console.WriteLine(aFalafel.Dinner()); }
static void Main(string[] args) { var plates = new List <IPlate <IWaffle> >(); plates.Add(new HugePlate()); plates.Add(new SmallPlate()); IPlate <IWaffle> aPlate = plates[0]; // Anyway, when you get a member of the collection you'll get the interface, not a concrete class (obviously). IWaffle aWaffle = aPlate.GetMyWaffle(); // So you cannot invoke any specifics (like Breakfast or Dinner) Console.WriteLine(aWaffle.Eat()); // But if you cast the member of the collection to the specific class (or interface) IPlate <FalafelWaffle> aSmallPlate = (SmallPlate)plates[1]; // Then you'll get the concrete class without casting again FalafelWaffle aFalafel = aSmallPlate.GetMyWaffle(); Console.WriteLine(aFalafel.Dinner()); }
public void PlateShoulderObject_ShouldNotBeEquippedByNONPlateClass_WhenEquipped() { IMageHero hero = ClassFactory.CreateMage("hero"); int agility = hero.Agility; int straight = hero.Straight; int intellect = hero.Intellect; double armor = hero.Armor; IPlate shoulder = PlateArmorFactory.CreateShoulder("shoulder", 1, 1); shoulder.Value = 1; shoulder.Agility = 1; shoulder.Stragiht = 1; shoulder.Intellect = 1; hero.Equip(shoulder); Assert.IsTrue( agility == hero.Agility && straight == hero.Straight && intellect == hero.Intellect && armor == hero.Armor); }
public void PlateShoulderObject_ShouldIncreaseStats_WhenEquipped() { IWarriorHero hero = ClassFactory.CreateWarrior("Hero"); int agility = hero.Agility; int straight = hero.Straight; int intellect = hero.Intellect; double armor = hero.Armor; IPlate shoulder = PlateArmorFactory.CreateShoulder("shoulder", 1, 1); shoulder.Value = 1; shoulder.Agility = 1; shoulder.Stragiht = 1; shoulder.Intellect = 1; hero.Equip(shoulder); Assert.IsFalse( agility == hero.Agility && straight == hero.Straight && intellect == hero.Intellect && armor == hero.Armor); }
public void Move(IEnumerable <StringMovement> movements, IPlate plate) { foreach (var movement in movements) { switch (movement) { case StringMovement.L: MoveLeft(); break; case StringMovement.M: var nextPosition = Move(); SetRoverPosition(plate, nextPosition); break; case StringMovement.R: MoveRight(); break; default: throw new ArgumentOutOfRangeException(); } } }
internal StepMove(Position from, Position to, IPlate plate) { this.From = from; this.To = to; this.Plate = plate; }
public RotateAndMoveOperation(IPlate plate) { _plate = plate; }
private void SetRoverPosition(IPlate plateau, CoordinatesPoint nextPosition) { _coordinatesPoint = nextPosition; }
public void AddPlate(Position p, IPlate plate) { form[p].AddPlate((Plate)plate); }