csharpc-sharpdotnetxamlavaloniauicross-platformcross-platform-xamlavaloniaguimulti-platformuser-interfacedotnetcore
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
55 lines
1.9 KiB
55 lines
1.9 KiB
namespace Perspex.Xaml.Desktop
|
|
{
|
|
using Context;
|
|
using HighLevel;
|
|
using OmniXaml;
|
|
using OmniXaml.ObjectAssembler;
|
|
using OmniXaml.Parsers.ProtoParser;
|
|
using OmniXaml.Parsers.XamlNodes;
|
|
|
|
public class PerspexParserFactory : IXamlParserFactory
|
|
{
|
|
private readonly IWiringContext wiringContext;
|
|
|
|
public PerspexParserFactory(ITypeFactory typeFactory)
|
|
{
|
|
wiringContext = PerspexWiringContextFactory.GetContext(typeFactory);
|
|
}
|
|
|
|
public IXamlParser CreateForReadingFree()
|
|
{
|
|
var objectAssemblerForUndefinedRoot = GetObjectAssemblerForUndefinedRoot();
|
|
|
|
return CreateParser(objectAssemblerForUndefinedRoot);
|
|
}
|
|
|
|
private IXamlParser CreateParser(IObjectAssembler objectAssemblerForUndefinedRoot)
|
|
{
|
|
var xamlInstructionParser = new OrderAwareXamlInstructionParser(new XamlInstructionParser(wiringContext));
|
|
|
|
var phaseParserKit = new PhaseParserKit(
|
|
new XamlProtoInstructionParser(wiringContext),
|
|
xamlInstructionParser,
|
|
objectAssemblerForUndefinedRoot);
|
|
|
|
return new XamlXmlParser(phaseParserKit);
|
|
}
|
|
|
|
private IObjectAssembler GetObjectAssemblerForUndefinedRoot()
|
|
{
|
|
return new ObjectAssembler(wiringContext, new TopDownMemberValueContext());
|
|
}
|
|
|
|
public IXamlParser CreateForReadingSpecificInstance(object rootInstance)
|
|
{
|
|
var objectAssemblerForUndefinedRoot = GetObjectAssemblerForSpecificRoot(rootInstance);
|
|
|
|
return CreateParser(objectAssemblerForUndefinedRoot);
|
|
}
|
|
|
|
private IObjectAssembler GetObjectAssemblerForSpecificRoot(object rootInstance)
|
|
{
|
|
return new PerspexObjectAssembler(wiringContext, new ObjectAssemblerSettings { RootInstance = rootInstance });
|
|
}
|
|
}
|
|
}
|