This commit is contained in:
José Manuel Nieto Sánchez 2016-01-11 23:02:48 +01:00
Родитель fc72f86aa4
Коммит 947d25842f
10 изменённых файлов: 37 добавлений и 34 удалений

Просмотреть файл

@ -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;
}
}

Просмотреть файл

@ -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<XamlType> 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)

Просмотреть файл

@ -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<StateCommuter> setResult;
public EndObjectCommand(StateCommuter stateCommuter, Action<StateCommuter> 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();
}

Просмотреть файл

@ -4,7 +4,7 @@ namespace OmniXaml.ObjectAssembler.Commands
public class GetObjectCommand : Command
{
public GetObjectCommand(ObjectAssembler objectAssembler) : base(objectAssembler)
public GetObjectCommand(StateCommuter stateCommuter) : base(stateCommuter)
{
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}

Просмотреть файл

@ -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;
}
}

Просмотреть файл

@ -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:

Просмотреть файл

@ -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;
}
}

Просмотреть файл

@ -11,7 +11,7 @@
[TestClass]
public class LookaheadBufferTests : GivenARuntimeTypeSourceWithNodeBuildersNetCore
{
private InstructionResources resources;
private readonly InstructionResources resources;
public LookaheadBufferTests()
{