diff --git a/Source/OmniXaml/ObjectAssembler/Command.cs b/Source/OmniXaml/ObjectAssembler/Command.cs index f2b28b1..9deb2a3 100644 --- a/Source/OmniXaml/ObjectAssembler/Command.cs +++ b/Source/OmniXaml/ObjectAssembler/Command.cs @@ -2,14 +2,13 @@ namespace OmniXaml.ObjectAssembler { public abstract class Command { - protected Command(ObjectAssembler assembler) + protected Command(StateCommuter stateCommuter) { - Assembler = assembler; + StateCommuter = stateCommuter; } - protected ObjectAssembler Assembler { get; } + protected StateCommuter StateCommuter { get; } public abstract void Execute(); - protected StateCommuter StateCommuter => Assembler.StateCommuter; } } \ No newline at end of file diff --git a/Source/OmniXaml/ObjectAssembler/Commands/EndMemberCommand.cs b/Source/OmniXaml/ObjectAssembler/Commands/EndMemberCommand.cs index 3a28a66..7a94828 100644 --- a/Source/OmniXaml/ObjectAssembler/Commands/EndMemberCommand.cs +++ b/Source/OmniXaml/ObjectAssembler/Commands/EndMemberCommand.cs @@ -7,13 +7,11 @@ namespace OmniXaml.ObjectAssembler.Commands public class EndMemberCommand : Command { - private readonly ITopDownValueContext topDownValueContext; - private readonly IRuntimeTypeSource typeSource; + private readonly ITypeRepository typeRepository; - public EndMemberCommand(ObjectAssembler assembler, ITopDownValueContext topDownValueContext) : base(assembler) + public EndMemberCommand(ITypeRepository typeRepository, StateCommuter stateCommuter) : base(stateCommuter) { - this.topDownValueContext = topDownValueContext; - typeSource = Assembler.TypeSource; + this.typeRepository = typeRepository; } public override void Execute() @@ -31,7 +29,7 @@ namespace OmniXaml.ObjectAssembler.Commands } } - public bool IsTherePendingInstanceWaitingToBeAssigned => StateCommuter.Current.HasInstance && StateCommuter.Current.Member == null; + private bool IsTherePendingInstanceWaitingToBeAssigned => StateCommuter.Current.HasInstance && StateCommuter.Current.Member == null; private void AdaptCurrentCtorArgumentsToCurrentType() { @@ -51,7 +49,7 @@ namespace OmniXaml.ObjectAssembler.Commands private IList GetTypesOfBestCtorMatch(XamlType xamlType, int count) { var constructor = SelectConstructor(xamlType, count); - return constructor.GetParameters().Select(arg => typeSource.GetByType(arg.ParameterType)).ToList(); + return constructor.GetParameters().Select(arg => typeRepository.GetByType(arg.ParameterType)).ToList(); } private static ConstructorInfo SelectConstructor(XamlType xamlType, int count) diff --git a/Source/OmniXaml/ObjectAssembler/Commands/EndObjectCommand.cs b/Source/OmniXaml/ObjectAssembler/Commands/EndObjectCommand.cs index 7fec07b..1053022 100644 --- a/Source/OmniXaml/ObjectAssembler/Commands/EndObjectCommand.cs +++ b/Source/OmniXaml/ObjectAssembler/Commands/EndObjectCommand.cs @@ -1,11 +1,15 @@ namespace OmniXaml.ObjectAssembler.Commands { + using System; using System.Collections; public class EndObjectCommand : Command { - public EndObjectCommand(ObjectAssembler assembler) : base(assembler) + private readonly Action setResult; + + public EndObjectCommand(StateCommuter stateCommuter, Action setResult) : base(stateCommuter) { + this.setResult = setResult; } public override void Execute() @@ -25,8 +29,8 @@ namespace OmniXaml.ObjectAssembler.Commands StateCommuter.RegisterInstanceNameToNamescope(); StateCommuter.NotifyEnd(); } - - Assembler.Result = StateCommuter.Current.Instance; + + setResult(StateCommuter); StateCommuter.DecreaseLevel(); } diff --git a/Source/OmniXaml/ObjectAssembler/Commands/GetObjectCommand.cs b/Source/OmniXaml/ObjectAssembler/Commands/GetObjectCommand.cs index d4ed328..497a9ec 100644 --- a/Source/OmniXaml/ObjectAssembler/Commands/GetObjectCommand.cs +++ b/Source/OmniXaml/ObjectAssembler/Commands/GetObjectCommand.cs @@ -4,7 +4,7 @@ namespace OmniXaml.ObjectAssembler.Commands public class GetObjectCommand : Command { - public GetObjectCommand(ObjectAssembler objectAssembler) : base(objectAssembler) + public GetObjectCommand(StateCommuter stateCommuter) : base(stateCommuter) { } diff --git a/Source/OmniXaml/ObjectAssembler/Commands/NamespaceDeclarationCommand.cs b/Source/OmniXaml/ObjectAssembler/Commands/NamespaceDeclarationCommand.cs index 30a13f5..2338694 100644 --- a/Source/OmniXaml/ObjectAssembler/Commands/NamespaceDeclarationCommand.cs +++ b/Source/OmniXaml/ObjectAssembler/Commands/NamespaceDeclarationCommand.cs @@ -4,7 +4,7 @@ namespace OmniXaml.ObjectAssembler.Commands { private readonly NamespaceDeclaration namespaceDeclaration; - public NamespaceDeclarationCommand(ObjectAssembler assembler, NamespaceDeclaration namespaceDeclaration) : base(assembler) + public NamespaceDeclarationCommand(NamespaceDeclaration namespaceDeclaration, StateCommuter stateCommuter) : base(stateCommuter) { this.namespaceDeclaration = namespaceDeclaration; } diff --git a/Source/OmniXaml/ObjectAssembler/Commands/StartMemberCommand.cs b/Source/OmniXaml/ObjectAssembler/Commands/StartMemberCommand.cs index ab4ddce..bbed42d 100644 --- a/Source/OmniXaml/ObjectAssembler/Commands/StartMemberCommand.cs +++ b/Source/OmniXaml/ObjectAssembler/Commands/StartMemberCommand.cs @@ -9,7 +9,7 @@ namespace OmniXaml.ObjectAssembler.Commands { private readonly MemberBase member; - public StartMemberCommand(ObjectAssembler assembler, MemberBase member) : base(assembler) + public StartMemberCommand(StateCommuter stateCommuter, MemberBase member) : base(stateCommuter) { this.member = member; } diff --git a/Source/OmniXaml/ObjectAssembler/Commands/StartObjectCommand.cs b/Source/OmniXaml/ObjectAssembler/Commands/StartObjectCommand.cs index 4e53b68..fcfd9ec 100644 --- a/Source/OmniXaml/ObjectAssembler/Commands/StartObjectCommand.cs +++ b/Source/OmniXaml/ObjectAssembler/Commands/StartObjectCommand.cs @@ -5,11 +5,13 @@ namespace OmniXaml.ObjectAssembler.Commands public class StartObjectCommand : Command { + private readonly ITypeRepository typeRepository; private readonly XamlType xamlType; private readonly object rootInstance; - public StartObjectCommand(ObjectAssembler assembler, XamlType xamlType, object rootInstance) : base(assembler) + public StartObjectCommand(StateCommuter stateCommuter, ITypeRepository typeRepository, XamlType xamlType, object rootInstance) : base(stateCommuter) { + this.typeRepository = typeRepository; this.xamlType = xamlType; this.rootInstance = rootInstance; } @@ -44,8 +46,8 @@ namespace OmniXaml.ObjectAssembler.Commands { tempQualifier.Current.Collection = collection; } - var typeSource = Assembler.TypeSource; - var xamlTypeOfInstance = typeSource.GetByType(rootInstance.GetType()); + + var xamlTypeOfInstance = typeRepository.GetByType(rootInstance.GetType()); StateCommuter.Current.XamlType = xamlTypeOfInstance; } } diff --git a/Source/OmniXaml/ObjectAssembler/Commands/ValueCommand.cs b/Source/OmniXaml/ObjectAssembler/Commands/ValueCommand.cs index e2deb9a..eb09809 100644 --- a/Source/OmniXaml/ObjectAssembler/Commands/ValueCommand.cs +++ b/Source/OmniXaml/ObjectAssembler/Commands/ValueCommand.cs @@ -1,13 +1,15 @@ namespace OmniXaml.ObjectAssembler.Commands { + using Typing; + public class ValueCommand : Command { private readonly string value; - public ValueCommand(ObjectAssembler objectAssembler, ITopDownValueContext topDownValueContext, string value) : base(objectAssembler) + public ValueCommand(StateCommuter stateCommuter, ITypeRepository typeSource, ITopDownValueContext topDownValueContext, string value) : base(stateCommuter) { this.value = value; - ValuePipeLine = new ValuePipeline(objectAssembler.TypeSource, topDownValueContext); + ValuePipeLine = new ValuePipeline(typeSource, topDownValueContext); } private ValuePipeline ValuePipeLine { get; } @@ -18,7 +20,6 @@ namespace OmniXaml.ObjectAssembler.Commands { case ValueProcessingMode.InitializationValue: StateCommuter.Current.Instance = ValuePipeLine.ConvertValueIfNecessary(value, StateCommuter.Current.XamlType); - break; case ValueProcessingMode.Key: diff --git a/Source/OmniXaml/ObjectAssembler/ObjectAssembler.cs b/Source/OmniXaml/ObjectAssembler/ObjectAssembler.cs index 62470be..6571585 100644 --- a/Source/OmniXaml/ObjectAssembler/ObjectAssembler.cs +++ b/Source/OmniXaml/ObjectAssembler/ObjectAssembler.cs @@ -54,25 +54,25 @@ namespace OmniXaml.ObjectAssembler switch (instruction.InstructionType) { case InstructionType.NamespaceDeclaration: - command = new NamespaceDeclarationCommand(this, instruction.NamespaceDeclaration); + command = new NamespaceDeclarationCommand(instruction.NamespaceDeclaration, StateCommuter); break; case InstructionType.StartObject: - command = new StartObjectCommand(this, instruction.XamlType, rootInstance); + command = new StartObjectCommand(StateCommuter, TypeSource, instruction.XamlType, rootInstance); break; case InstructionType.StartMember: - command = new StartMemberCommand(this, GetActualMemberFromMemberSpecifiedInInstruction(instruction.Member)); + command = new StartMemberCommand(StateCommuter, GetActualMemberFromMemberSpecifiedInInstruction(instruction.Member)); break; case InstructionType.Value: - command = new ValueCommand(this, TopDownValueContext, (string) instruction.Value); + command = new ValueCommand(StateCommuter, this.TypeSource, TopDownValueContext, (string)instruction.Value); break; case InstructionType.EndObject: - command = new EndObjectCommand(this); + command = new EndObjectCommand(StateCommuter, stateCommuter => Result = stateCommuter.Current.Instance); break; case InstructionType.EndMember: - command = new EndMemberCommand(this, TopDownValueContext); + command = new EndMemberCommand(TypeSource, StateCommuter); break; case InstructionType.GetObject: - command = new GetObjectCommand(this); + command = new GetObjectCommand(StateCommuter); break; default: throw new ParseException($"The XamlInstructionType {instruction.InstructionType} has an unexpected value"); @@ -84,13 +84,12 @@ namespace OmniXaml.ObjectAssembler public void OverrideInstance(object instance) { StateCommuter.RaiseLevel(); - var tempQualifier = StateCommuter; - tempQualifier.Current.Instance = instance; + StateCommuter.Current.Instance = instance; var collection = instance as ICollection; if (collection != null) { - tempQualifier.Current.Collection = collection; + StateCommuter.Current.Collection = collection; } } diff --git a/Source/Tests/OmniXaml.Tests/LookaheadBufferTests.cs b/Source/Tests/OmniXaml.Tests/LookaheadBufferTests.cs index 141f233..b833dcc 100644 --- a/Source/Tests/OmniXaml.Tests/LookaheadBufferTests.cs +++ b/Source/Tests/OmniXaml.Tests/LookaheadBufferTests.cs @@ -11,7 +11,7 @@ [TestClass] public class LookaheadBufferTests : GivenARuntimeTypeSourceWithNodeBuildersNetCore { - private InstructionResources resources; + private readonly InstructionResources resources; public LookaheadBufferTests() {