コード例 #1
0
ファイル: XamlCompiler.cs プロジェクト: space-wizards/XamlX
 public XamlCompiler(TransformerConfiguration configuration,
                     XamlLanguageEmitMappings <TBackendEmitter, TEmitResult> emitMappings,
                     bool fillWithDefaults)
 {
     _configuration = configuration;
     _emitMappings  = emitMappings;
     if (fillWithDefaults)
     {
         Transformers = new List <IXamlAstTransformer>
         {
             new KnownDirectivesTransformer(),
             new XamlIntrinsicsTransformer(),
             new XArgumentsTransformer(),
             new TypeReferenceResolver(),
             new MarkupExtensionTransformer(),
             new PropertyReferenceResolver(),
             new ContentConvertTransformer(),
             new ResolveContentPropertyTransformer(),
             new ResolvePropertyValueAddersTransformer(),
             new ConvertPropertyValuesToAssignmentsTransformer(),
             new ConstructableObjectTransformer()
         };
         SimplificationTransformers = new List <IXamlAstTransformer>
         {
             new FlattenAstTransformer()
         };
     }
 }
コード例 #2
0
            public AvaloniaAttachedInstanceProperty(XamlAstNamePropertyReference prop,
                                                    TransformerConfiguration config,
                                                    IXamlType declaringType,
                                                    IXamlType type,
                                                    IXamlType avaloniaPropertyType,
                                                    IXamlType avaloniaObject,
                                                    IXamlField field) : base(prop, prop.Name,
                                                                             declaringType, null)


            {
                _config               = config;
                _declaringType        = declaringType;
                _avaloniaPropertyType = avaloniaPropertyType;

                // XamlIl doesn't support generic methods yet
                if (_avaloniaPropertyType.GenericArguments?.Count > 0)
                {
                    _avaloniaPropertyType = _avaloniaPropertyType.BaseType;
                }

                _avaloniaObject = avaloniaObject;
                _field          = field;
                PropertyType    = type;
                Setters.Add(new SetterMethod(this));
                Getter = new GetterMethod(this);
            }
コード例 #3
0
        public RXamlWellKnownTypes(TransformerConfiguration cfg)
        {
            var ts = cfg.TypeSystem;

            XamlIlTypes = cfg.WellKnownTypes;
            Single      = ts.GetType("System.Single");
            Int32       = ts.GetType("System.Int32");

            (Vector2, Vector2ConstructorFull)     = GetNumericTypeInfo("Robust.Shared.Maths.Vector2", Single, 2);
            (Vector2i, Vector2iConstructorFull)   = GetNumericTypeInfo("Robust.Shared.Maths.Vector2i", Int32, 2);
            (Thickness, ThicknessConstructorFull) = GetNumericTypeInfo("Robust.Shared.Maths.Thickness", Single, 4);

            (IXamlType, IXamlConstructor) GetNumericTypeInfo(string name, IXamlType componentType, int componentCount)
            {
                var type = cfg.TypeSystem.GetType(name);
                var ctor = type.GetConstructor(Enumerable.Repeat(componentType, componentCount).ToList());

                return(type, ctor);
            }

            Color         = cfg.TypeSystem.GetType("Robust.Shared.Maths.Color");
            ColorFromXaml = Color.GetMethod(new FindMethodMethodSignature("FromXaml", Color, XamlIlTypes.String)
            {
                IsStatic = true
            });
        }
コード例 #4
0
        /// <summary>
        /// Create a copy of a transformer.
        /// </summary>
        /// <param name="id">New id of the transformer, must be unique</param>
        /// <param name="transformer">The transformer to copy.</param>
        /// <returns>A new transformer</returns>
        public static ITransformer CloneTransformer(string id, ITransformer transformer)
        {
            try
            {
                var newConfig = new TransformerConfiguration()
                {
                    Id       = id,
                    ReaderId = transformer.Config.ReaderId,
                    Mappers  = transformer.Config.Mappers,
                    Type     = transformer.Config.Type,
                };
                var mappers = new List <IMapper>();
                foreach (var mapperConfig in newConfig.Mappers)
                {
                    var mapper = CollectorFactory.CreateMapper(mapperConfig);
                    if (mapper == null)
                    {
                        throw new NullReferenceException("Unable to create Collector.  Invalid Mapper defined.");
                    }

                    mappers.Add(mapper);
                }
                var newTransformer = ComponentRegistration.CreateInstance <ITransformer>(newConfig.Type);
                newTransformer.Configure(newConfig, transformer.Handler);
                return(transformer);
            }
            catch (Exception e)
            {
                _logger.Error(e);
            }
            return(null);
        }
コード例 #5
0
        public XamlAstClrProperty(IXamlLineInfo lineInfo, IXamlProperty property,
                                  TransformerConfiguration cfg) : base(lineInfo)
        {
            Name   = property.Name;
            Getter = property.Getter;
            if (property.Setter != null)
            {
                Setters.Add(new XamlDirectCallPropertySetter(property.Setter));
            }
            CustomAttributes = property.CustomAttributes.ToList();
            DeclaringType    = (property.Getter ?? property.Setter)?.DeclaringType;
            var typeConverterAttributes = cfg.GetCustomAttribute(property, cfg.TypeMappings.TypeConverterAttributes);

            if (typeConverterAttributes != null)
            {
                foreach (var attr in typeConverterAttributes)
                {
                    var typeConverter =
                        XamlTransformHelpers.TryGetTypeConverterFromCustomAttribute(cfg, attr);
                    if (typeConverter != null)
                    {
                        TypeConverters[property.PropertyType] = typeConverter;
                        break;
                    }
                }
            }
        }
コード例 #6
0
 public AvaloniaXamlIlCompiler(TransformerConfiguration configuration,
                               XamlLanguageEmitMappings <IXamlILEmitter, XamlILNodeEmitResult> emitMappings,
                               IXamlTypeBuilder <IXamlILEmitter> contextTypeBuilder)
     : this(configuration, emitMappings)
 {
     _contextType = CreateContextType(contextTypeBuilder);
 }
コード例 #7
0
 public XamlCompiler(TransformerConfiguration configuration,
                     XamlLanguageEmitMappings <TBackendEmitter, TEmitResult> emitMappings,
                     bool fillWithDefaults)
 {
     _configuration = configuration;
     _emitMappings  = emitMappings;
     if (fillWithDefaults)
     {
         Transformers = new List <IXamlAstTransformer>
         {
             new KnownDirectivesTransformer(),
             new XamlIntrinsicsTransformer(),
             new XArgumentsTransformer(),
             new TypeReferenceResolver(),
             new MarkupExtensionTransformer(),
             new TextNodeMerger(),
             new PropertyReferenceResolver(),
             new ContentConvertTransformer(),
             // This should come before actual content property processing
             new RemoveWhitespaceBetweenPropertyValuesTransformer(),
             new ResolveContentPropertyTransformer(),
             new ResolvePropertyValueAddersTransformer(),
             new ApplyWhitespaceNormalization(),
             new ConvertPropertyValuesToAssignmentsTransformer(),
             new ConstructableObjectTransformer()
         };
         SimplificationTransformers = new List <IXamlAstTransformer>
         {
             new FlattenAstTransformer()
         };
     }
 }
コード例 #8
0
 private CompilerTestBase(IXamlTypeSystem typeSystem)
 {
     _typeSystem   = typeSystem;
     Configuration = new TransformerConfiguration(typeSystem,
                                                  typeSystem.FindAssembly("XamlParserTests"),
                                                  new XamlLanguageTypeMappings(typeSystem)
     {
         XmlnsAttributes =
         {
             typeSystem.GetType("XamlParserTests.XmlnsDefinitionAttribute"),
         },
         ContentAttributes =
         {
             typeSystem.GetType("XamlParserTests.ContentAttribute")
         },
         UsableDuringInitializationAttributes =
         {
             typeSystem.GetType("XamlParserTests.UsableDuringInitializationAttribute")
         },
         DeferredContentPropertyAttributes =
         {
             typeSystem.GetType("XamlParserTests.DeferredContentAttribute")
         },
         RootObjectProvider       = typeSystem.GetType("XamlParserTests.ITestRootObjectProvider"),
         UriContextProvider       = typeSystem.GetType("XamlParserTests.ITestUriContext"),
         ProvideValueTarget       = typeSystem.GetType("XamlParserTests.ITestProvideValueTarget"),
         ParentStackProvider      = typeSystem.GetType("XamlX.Runtime.IXamlParentStackProviderV1"),
         XmlNamespaceInfoProvider = typeSystem.GetType("XamlX.Runtime.IXamlXmlNamespaceInfoProviderV1")
     }
                                                  );
 }
コード例 #9
0
 public AvaloniaXamlIlWellKnownTypes(TransformerConfiguration cfg)
 {
     XamlIlTypes              = cfg.WellKnownTypes;
     AvaloniaObject           = cfg.TypeSystem.GetType("Avalonia.AvaloniaObject");
     IAvaloniaObject          = cfg.TypeSystem.GetType("Avalonia.IAvaloniaObject");
     AvaloniaObjectExtensions = cfg.TypeSystem.GetType("Avalonia.AvaloniaObjectExtensions");
     AvaloniaProperty         = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty");
     AvaloniaPropertyT        = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty`1");
     BindingPriority          = cfg.TypeSystem.GetType("Avalonia.Data.BindingPriority");
     IBinding                 = cfg.TypeSystem.GetType("Avalonia.Data.IBinding");
     IDisposable              = cfg.TypeSystem.GetType("System.IDisposable");
     Transitions              = cfg.TypeSystem.GetType("Avalonia.Animation.Transitions");
     AssignBindingAttribute   = cfg.TypeSystem.GetType("Avalonia.Data.AssignBindingAttribute");
     AvaloniaObjectBindMethod = AvaloniaObjectExtensions.FindMethod("Bind", IDisposable, false, IAvaloniaObject,
                                                                    AvaloniaProperty,
                                                                    IBinding, cfg.WellKnownTypes.Object);
     UnsetValueType     = cfg.TypeSystem.GetType("Avalonia.UnsetValueType");
     StyledElement      = cfg.TypeSystem.GetType("Avalonia.StyledElement");
     INameScope         = cfg.TypeSystem.GetType("Avalonia.Controls.INameScope");
     INameScopeRegister = INameScope.GetMethod(
         new FindMethodMethodSignature("Register", XamlIlTypes.Void,
                                       XamlIlTypes.String, XamlIlTypes.Object)
     {
         IsStatic      = false,
         DeclaringOnly = true,
         IsExactMatch  = true
     });
     INameScopeComplete = INameScope.GetMethod(
         new FindMethodMethodSignature("Complete", XamlIlTypes.Void)
     {
         IsStatic      = false,
         DeclaringOnly = true,
         IsExactMatch  = true
     });
     NameScope             = cfg.TypeSystem.GetType("Avalonia.Controls.NameScope");
     NameScopeSetNameScope = NameScope.GetMethod(new FindMethodMethodSignature("SetNameScope",
                                                                               XamlIlTypes.Void, StyledElement, INameScope)
     {
         IsStatic = true
     });
     AvaloniaObjectSetValueMethod = AvaloniaObject.FindMethod("SetValue", XamlIlTypes.Void,
                                                              false, AvaloniaProperty, XamlIlTypes.Object, BindingPriority);
     IPropertyInfo               = cfg.TypeSystem.GetType("Avalonia.Data.Core.IPropertyInfo");
     ClrPropertyInfo             = cfg.TypeSystem.GetType("Avalonia.Data.Core.ClrPropertyInfo");
     PropertyPath                = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPath");
     PropertyPathBuilder         = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPathBuilder");
     IPropertyAccessor           = cfg.TypeSystem.GetType("Avalonia.Data.Core.Plugins.IPropertyAccessor");
     PropertyInfoAccessorFactory = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.PropertyInfoAccessorFactory");
     CompiledBindingPathBuilder  = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPathBuilder");
     CompiledBindingPath         = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPath");
     CompiledBindingExtension    = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindingExtension");
     ResolveByNameExtension      = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ResolveByNameExtension");
     DataTemplate                = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.Templates.DataTemplate");
     IDataTemplate               = cfg.TypeSystem.GetType("Avalonia.Controls.Templates.IDataTemplate");
     IItemsPresenterHost         = cfg.TypeSystem.GetType("Avalonia.Controls.Presenters.IItemsPresenterHost");
     ItemsRepeater               = cfg.TypeSystem.GetType("Avalonia.Controls.ItemsRepeater");
     ReflectionBindingExtension  = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ReflectionBindingExtension");
     RelativeSource              = cfg.TypeSystem.GetType("Avalonia.Data.RelativeSource");
 }
コード例 #10
0
        public RobustXamlILCompiler(TransformerConfiguration configuration, XamlLanguageEmitMappings <IXamlILEmitter, XamlILNodeEmitResult> emitMappings, bool fillWithDefaults) : base(configuration, emitMappings, fillWithDefaults)
        {
            Transformers.Add(new AddNameScopeRegistration());
            Transformers.Add(new RobustMarkRootObjectScopeNode());

            Emitters.Add(new AddNameScopeRegistration.Emitter());
            Emitters.Add(new RobustMarkRootObjectScopeNode.Emitter());
        }
コード例 #11
0
        public WinUIXamlILCompiler(TransformerConfiguration configuration, XamlLanguageEmitMappings <IXamlILEmitter, XamlILNodeEmitResult> emitMappings) : base(configuration, emitMappings, true)
        {
            this.AddWinUIPhases();

            Emitters.Add(new XamlDirectConversionEmitter());
            Emitters.Add(new XamlDirectNewObjectEmitter());
            Emitters.Add(new XamlDirectSetterEmitter());
            Emitters.Add(new XamlDirectAdderSetterEmitter());
            Emitters.Add(new XamlDirectEventSetterEmitter());
        }
コード例 #12
0
 public ILEmitContext(IXamlILEmitter emitter, TransformerConfiguration configuration,
                      XamlLanguageEmitMappings <IXamlILEmitter, XamlILNodeEmitResult> emitMappings,
                      XamlRuntimeContext <IXamlILEmitter, XamlILNodeEmitResult> runtimeContext,
                      IXamlLocal contextLocal,
                      Func <string, IXamlType, IXamlTypeBuilder <IXamlILEmitter> > createSubType, IFileSource file, IEnumerable <object> emitters)
     : base(emitter, configuration, emitMappings, runtimeContext,
            contextLocal, createSubType, file, emitters)
 {
     EnableIlVerification = configuration.GetOrCreateExtra <ILEmitContextSettings>().EnableILVerification;
 }
コード例 #13
0
 private MiniCompiler(TransformerConfiguration configuration)
     : base(configuration, new XamlLanguageEmitMappings <object, IXamlEmitResult>(), false)
 {
     Transformers.Add(new NameDirectiveTransformer());
     Transformers.Add(new DataTemplateTransformer());
     Transformers.Add(new KnownDirectivesTransformer());
     Transformers.Add(new XamlIntrinsicsTransformer());
     Transformers.Add(new XArgumentsTransformer());
     Transformers.Add(new TypeReferenceResolver());
 }
コード例 #14
0
        private AvaloniaXamlIlCompiler(TransformerConfiguration configuration, XamlLanguageEmitMappings <IXamlILEmitter, XamlILNodeEmitResult> emitMappings)
            : base(configuration, emitMappings, true)
        {
            _configuration = configuration;

            void InsertAfter <T>(params IXamlAstTransformer[] t)
            => Transformers.InsertRange(Transformers.FindIndex(x => x is T) + 1, t);

            void InsertBefore <T>(params IXamlAstTransformer[] t)
            => Transformers.InsertRange(Transformers.FindIndex(x => x is T), t);


            // Before everything else

            Transformers.Insert(0, new XNameTransformer());
            Transformers.Insert(1, new IgnoredDirectivesTransformer());
            Transformers.Insert(2, _designTransformer  = new AvaloniaXamlIlDesignPropertiesTransformer());
            Transformers.Insert(3, _bindingTransformer = new AvaloniaBindingExtensionTransformer());


            // Targeted
            InsertBefore <PropertyReferenceResolver>(
                new AvaloniaXamlIlResolveClassesPropertiesTransformer(),
                new AvaloniaXamlIlTransformInstanceAttachedProperties(),
                new AvaloniaXamlIlTransformSyntheticCompiledBindingMembers());
            InsertAfter <PropertyReferenceResolver>(
                new AvaloniaXamlIlAvaloniaPropertyResolver(),
                new AvaloniaXamlIlReorderClassesPropertiesTransformer()
                );

            InsertBefore <ContentConvertTransformer>(
                new AvaloniaXamlIlBindingPathParser(),
                new AvaloniaXamlIlSelectorTransformer(),
                new AvaloniaXamlIlControlTemplateTargetTypeMetadataTransformer(),
                new AvaloniaXamlIlPropertyPathTransformer(),
                new AvaloniaXamlIlSetterTransformer(),
                new AvaloniaXamlIlConstructorServiceProviderTransformer(),
                new AvaloniaXamlIlTransitionsTypeMetadataTransformer(),
                new AvaloniaXamlIlResolveByNameMarkupExtensionReplacer()
                );

            // After everything else
            InsertBefore <NewObjectTransformer>(
                new AddNameScopeRegistration(),
                new AvaloniaXamlIlDataContextTypeTransformer(),
                new AvaloniaXamlIlBindingPathTransformer(),
                new AvaloniaXamlIlCompiledBindingsMetadataRemover()
                );

            Transformers.Add(new AvaloniaXamlIlMetadataRemover());
            Transformers.Add(new AvaloniaXamlIlRootObjectScope());

            Emitters.Add(new AvaloniaNameScopeRegistrationXamlIlNodeEmitter());
            Emitters.Add(new AvaloniaXamlIlRootObjectScope.Emitter());
        }
コード例 #15
0
        public XamlDeferredContentNode(IXamlAstValueNode value,
                                       IXamlType deferredContentCustomizationTypeParameter,
                                       TransformerConfiguration config) : base(value)
        {
            _deferredContentCustomizationTypeParameter = deferredContentCustomizationTypeParameter;
            Value = value;
            var funcType = config.TypeSystem.GetType("System.Func`2")
                           .MakeGenericType(config.TypeMappings.ServiceProvider, config.WellKnownTypes.Object);

            Type = new XamlAstClrTypeReference(value, funcType, false);
        }
コード例 #16
0
 public XamlEmitContextWithLocals(TBackendEmitter emitter,
                                  TransformerConfiguration configuration,
                                  XamlLanguageEmitMappings <TBackendEmitter, TEmitResult> emitMappings,
                                  XamlRuntimeContext <TBackendEmitter, TEmitResult> runtimeContext,
                                  IXamlLocal contextLocal,
                                  Func <string, IXamlType, IXamlTypeBuilder <TBackendEmitter> > createSubType,
                                  IFileSource file,
                                  IEnumerable <object> emitters)
     : base(emitter, configuration, emitMappings, runtimeContext, contextLocal, createSubType, file, emitters)
 {
 }
コード例 #17
0
ファイル: WinUITypes.cs プロジェクト: stevenbrix/xamlx-winui
 public WellKnownWinUITypes(TransformerConfiguration cfg)
 {
     WinUIControlsAssembly = cfg.TypeSystem.FindAssembly("Microsoft.WinUI"); // TODO: Make configurable for C++
     XamlDirect            = cfg.TypeSystem.FindType("Microsoft.UI.Xaml.Core.Direct.XamlDirect");
     IXamlDirectObject     = cfg.TypeSystem.FindType("Microsoft.UI.Xaml.Core.Direct.IXamlDirectObject");
     XamlTypeIndex         = cfg.TypeSystem.FindType("Microsoft.UI.Xaml.Core.Direct.XamlTypeIndex");
     XamlPropertyIndex     = cfg.TypeSystem.FindType("Microsoft.UI.Xaml.Core.Direct.XamlPropertyIndex");
     XamlEventIndex        = cfg.TypeSystem.FindType("Microsoft.UI.Xaml.Core.Direct.XamlEventIndex");
     BindingBase           = cfg.TypeSystem.FindType("Microsoft.UI.Xaml.Data.BindingBase");
     DependencyProperty    = cfg.TypeSystem.FindType("Microsoft.UI.Xaml.DependencyProperty");
     DependencyObject      = cfg.TypeSystem.FindType("Microsoft.UI.Xaml.DependencyObject");
 }
コード例 #18
0
 public XamlImperativeCompiler(TransformerConfiguration configuration,
                               XamlLanguageEmitMappings <TBackendEmitter, TEmitResult> emitMappings, bool fillWithDefaults)
     : base(configuration, emitMappings, fillWithDefaults)
 {
     if (fillWithDefaults)
     {
         Transformers.AddRange(new IXamlAstTransformer[]
         {
             new NewObjectTransformer(),
             new DeferredContentTransformer(),
             new TopDownInitializationTransformer(),
         });
     }
 }
コード例 #19
0
 public XamlEmitContext(TBackendEmitter emitter, TransformerConfiguration configuration,
                        XamlLanguageEmitMappings <TBackendEmitter, TEmitResult> emitMappings,
                        XamlRuntimeContext <TBackendEmitter, TEmitResult> runtimeContext,
                        IXamlLocal contextLocal,
                        Func <string, IXamlType, IXamlTypeBuilder <TBackendEmitter> > createSubType, IFileSource file,
                        IEnumerable <object> emitters)
 {
     File           = file;
     Emitter        = emitter;
     Emitters       = emitters.ToList();
     Configuration  = configuration;
     RuntimeContext = runtimeContext;
     ContextLocal   = contextLocal;
     CreateSubType  = createSubType;
     EmitMappings   = emitMappings;
 }
コード例 #20
0
        public static MiniCompiler CreateDefault(RoslynTypeSystem typeSystem, params string[] additionalTypes)
        {
            var mappings = new XamlLanguageTypeMappings(typeSystem);

            foreach (var additionalType in additionalTypes)
            {
                mappings.XmlnsAttributes.Add(typeSystem.GetType(additionalType));
            }

            var configuration = new TransformerConfiguration(
                typeSystem,
                typeSystem.Assemblies[0],
                mappings);

            return(new MiniCompiler(configuration));
        }
コード例 #21
0
        /// <summary>
        /// Configure the transformer.
        /// </summary>
        /// <param name="config">The configuration to use.</param>
        /// <param name="handler">The handler to invoke once the data has been transformed.</param>
        public virtual void Configure(TransformerConfiguration config, ITransformedDataHandler handler)
        {
            _config  = config;
            _mappers = new List <IMapper>();
            _data    = new List <object>();

            foreach (var mapperConfig in _config.Mappers)
            {
                var mapper = CollectorFactory.CreateMapper(mapperConfig);
                if (mapper == null)
                {
                    throw new NullReferenceException("Unable to create Mapper.  Invalid Mapper defined.");
                }

                _mappers.Add(mapper);
            }
            _handler = handler;
        }
コード例 #22
0
        /// <summary>
        /// Create a Transformer.
        /// </summary>
        /// <param name="type">The name of the class to create.</param>
        /// <param name="id">The id of the transformer.</param>
        /// <param name="publishers">The publishers to use to publish the JSON data to a repository.</param>
        /// <param name="mappers">The mappers to use to transform/map the data.</param>
        /// <returns>A new handler.</returns>
        public static ITransformer CreateTransformer(TransformerConfiguration config, ITransformedDataHandler handler)
        {
            var mappers = new List <IMapper>();

            foreach (var mapperConfig in config.Mappers)
            {
                var mapper = CollectorFactory.CreateMapper(mapperConfig);
                if (mapper == null)
                {
                    throw new NullReferenceException("Unable to create Collector.  Invalid Mapper defined.");
                }

                mappers.Add(mapper);
            }
            var transformer = ComponentRegistration.CreateInstance <ITransformer>(config.Type);

            transformer.Configure(config, handler);
            return(transformer);
        }
コード例 #23
0
        public void CollectorFactory_CreateTransformer_Succeeds()
        {
            var mapperConfigs = new List <MapperConfiguration>();

            var config = new TransformerConfiguration()
            {
                Id       = "4",
                Type     = TYPE_TRANSFORMER,
                Mappers  = mapperConfigs,
                ReaderId = "2"
            };

            mapperConfigs.Add(CreateMapperConfig("3", config.Id));

            var handler     = new MockTransformationHandler();
            var transformer = CollectorFactory.CreateTransformer(config, handler);

            transformer.Should().NotBeNull();
        }
コード例 #24
0
        public RXamlWellKnownTypes(TransformerConfiguration cfg)
        {
            var ts = cfg.TypeSystem;

            XamlIlTypes = cfg.WellKnownTypes;
            Single      = ts.GetType("System.Single");
            Int32       = ts.GetType("System.Int32");

            (Vector2, Vector2ConstructorFull)   = GetNumericTypeInfo("Robust.Shared.Maths.Vector2", Single, 2);
            (Vector2i, Vector2iConstructorFull) = GetNumericTypeInfo("Robust.Shared.Maths.Vector2i", Int32, 2);

            (IXamlType, IXamlConstructor) GetNumericTypeInfo(string name, IXamlType componentType, int componentCount)
            {
                var type = cfg.TypeSystem.GetType(name);
                var ctor = type.GetConstructor(Enumerable.Repeat(componentType, componentCount).ToList());

                return(type, ctor);
            }
        }
コード例 #25
0
        private bool WantsWhitespaceOnlyElements(TransformerConfiguration config,
                                                 XamlAstClrProperty property)
        {
            var wellKnownTypes = config.WellKnownTypes;

            var acceptsMultipleElements = false;

            foreach (var setter in property.Setters)
            {
                // Skip any dictionary-like setters
                if (setter.Parameters.Count != 1)
                {
                    continue;
                }

                var parameterType = setter.Parameters[0];
                if (!setter.BinderParameters.AllowMultiple)
                {
                    // If the property can accept a scalar string, it'll get whitespace nodes by default
                    if (parameterType.Equals(wellKnownTypes.String) || parameterType.Equals(wellKnownTypes.Object))
                    {
                        return(true);
                    }
                }
                else
                {
                    acceptsMultipleElements = true;
                }
            }

            // A collection-like property will only receive whitespace-only nodes if the
            // property type can be deduced, and that type is annotated as whitespace significant
            if (acceptsMultipleElements &&
                property.Getter != null &&
                config.IsWhitespaceSignificantCollection(property.Getter.ReturnType))
            {
                return(true);
            }

            return(false);
        }
コード例 #26
0
        static bool?CompileCore(IBuildEngine engine, CecilTypeSystem typeSystem)
        {
            var asm    = typeSystem.TargetAssemblyDefinition;
            var embrsc = new EmbeddedResources(asm);

            if (embrsc.Resources.Count(CheckXamlName) == 0)
            {
                // Nothing to do
                return(null);
            }

            var xamlLanguage = new XamlLanguageTypeMappings(typeSystem)
            {
                XmlnsAttributes =
                {
                    typeSystem.GetType("Avalonia.Metadata.XmlnsDefinitionAttribute"),
                },
                ContentAttributes =
                {
                    typeSystem.GetType("Robust.Client.UserInterface.XAML.ContentAttribute")
                },
                UsableDuringInitializationAttributes =
                {
                    typeSystem.GetType("Robust.Client.UserInterface.XAML.UsableDuringInitializationAttribute")
                },
                DeferredContentPropertyAttributes =
                {
                    typeSystem.GetType("Robust.Client.UserInterface.XAML.DeferredContentAttribute")
                },
                RootObjectProvider = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestRootObjectProvider"),
                UriContextProvider = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestUriContext"),
                ProvideValueTarget = typeSystem.GetType("Robust.Client.UserInterface.XAML.ITestProvideValueTarget"),
            };
            var emitConfig = new XamlLanguageEmitMappings <IXamlILEmitter, XamlILNodeEmitResult>
            {
                ContextTypeBuilderCallback = (b, c) => EmitNameScopeField(xamlLanguage, typeSystem, b, c)
            };

            var transformerconfig = new TransformerConfiguration(
                typeSystem,
                typeSystem.TargetAssembly,
                xamlLanguage,
                XamlXmlnsMappings.Resolve(typeSystem, xamlLanguage), CustomValueConverter);

            var contextDef = new TypeDefinition("CompiledRobustXaml", "XamlIlContext",
                                                TypeAttributes.Class, asm.MainModule.TypeSystem.Object);

            asm.MainModule.Types.Add(contextDef);
            var contextClass = XamlILContextDefinition.GenerateContextClass(typeSystem.CreateTypeBuilder(contextDef), typeSystem,
                                                                            xamlLanguage, emitConfig);

            var compiler =
                new RobustXamlILCompiler(transformerconfig, emitConfig, true);

            var loaderDispatcherDef = new TypeDefinition("CompiledRobustXaml", "!XamlLoader",
                                                         TypeAttributes.Class, asm.MainModule.TypeSystem.Object);

            var loaderDispatcherMethod = new MethodDefinition("TryLoad",
                                                              MethodAttributes.Static | MethodAttributes.Public,
                                                              asm.MainModule.TypeSystem.Object)
            {
                Parameters = { new ParameterDefinition(asm.MainModule.TypeSystem.String) }
            };

            loaderDispatcherDef.Methods.Add(loaderDispatcherMethod);
            asm.MainModule.Types.Add(loaderDispatcherDef);

            var stringEquals = asm.MainModule.ImportReference(asm.MainModule.TypeSystem.String.Resolve().Methods.First(
                                                                  m =>
                                                                  m.IsStatic && m.Name == "Equals" && m.Parameters.Count == 2 &&
                                                                  m.ReturnType.FullName == "System.Boolean" &&
                                                                  m.Parameters[0].ParameterType.FullName == "System.String" &&
                                                                  m.Parameters[1].ParameterType.FullName == "System.String"));

            bool CompileGroup(IResourceGroup group)
            {
                var typeDef = new TypeDefinition("CompiledRobustXaml", "!" + group.Name, TypeAttributes.Class,
                                                 asm.MainModule.TypeSystem.Object);

                //typeDef.CustomAttributes.Add(new CustomAttribute(ed));
                asm.MainModule.Types.Add(typeDef);
                var builder = typeSystem.CreateTypeBuilder(typeDef);

                foreach (var res in group.Resources.Where(CheckXamlName))
                {
                    try
                    {
                        engine.LogMessage($"XAMLIL: {res.Name} -> {res.Uri}", MessageImportance.Low);

                        var xaml   = new StreamReader(new MemoryStream(res.FileContents)).ReadToEnd();
                        var parsed = XDocumentXamlParser.Parse(xaml);

                        var initialRoot = (XamlAstObjectNode)parsed.Root;

                        var classDirective = initialRoot.Children.OfType <XamlAstXmlDirective>()
                                             .FirstOrDefault(d => d.Namespace == XamlNamespaces.Xaml2006 && d.Name == "Class");
                        string classname;
                        if (classDirective != null && classDirective.Values[0] is XamlAstTextNode tn)
                        {
                            classname = tn.Text;
                        }
                        else
                        {
                            classname = res.Name.Replace(".xaml", "");
                        }

                        var classType = typeSystem.TargetAssembly.FindType(classname);
                        if (classType == null)
                        {
                            throw new Exception($"Unable to find type '{classname}'");
                        }

                        compiler.Transform(parsed);

                        var populateName = $"Populate:{res.Name}";
                        var buildName    = $"Build:{res.Name}";

                        var classTypeDefinition = typeSystem.GetTypeReference(classType).Resolve();

                        var populateBuilder = typeSystem.CreateTypeBuilder(classTypeDefinition);

                        compiler.Compile(parsed, contextClass,
                                         compiler.DefinePopulateMethod(populateBuilder, parsed, populateName,
                                                                       classTypeDefinition == null),
                                         compiler.DefineBuildMethod(builder, parsed, buildName, true),
                                         null,
                                         (closureName, closureBaseType) =>
                                         populateBuilder.DefineSubType(closureBaseType, closureName, false),
                                         res.Uri, res
                                         );

                        //add compiled populate method
                        var compiledPopulateMethod = typeSystem.GetTypeReference(populateBuilder).Resolve().Methods
                                                     .First(m => m.Name == populateName);

                        const string TrampolineName = "!XamlIlPopulateTrampoline";
                        var          trampoline     = new MethodDefinition(TrampolineName,
                                                                           MethodAttributes.Static | MethodAttributes.Private, asm.MainModule.TypeSystem.Void);
                        trampoline.Parameters.Add(new ParameterDefinition(classTypeDefinition));
                        classTypeDefinition.Methods.Add(trampoline);

                        trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ldnull));
                        trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ldarg_0));
                        trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Call, compiledPopulateMethod));
                        trampoline.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));

                        var foundXamlLoader = false;
                        // Find RobustXamlLoader.Load(this) and replace it with !XamlIlPopulateTrampoline(this)
                        foreach (var method in classTypeDefinition.Methods
                                 .Where(m => !m.Attributes.HasFlag(MethodAttributes.Static)))
                        {
                            var i = method.Body.Instructions;
                            for (var c = 1; c < i.Count; c++)
                            {
                                if (i[c].OpCode == OpCodes.Call)
                                {
                                    var op = i[c].Operand as MethodReference;

                                    if (op != null &&
                                        op.Name == TrampolineName)
                                    {
                                        foundXamlLoader = true;
                                        break;
                                    }

                                    if (op != null &&
                                        op.Name == "Load" &&
                                        op.Parameters.Count == 1 &&
                                        op.Parameters[0].ParameterType.FullName == "System.Object" &&
                                        op.DeclaringType.FullName == "Robust.Client.UserInterface.XAML.RobustXamlLoader")
                                    {
                                        if (MatchThisCall(i, c - 1))
                                        {
                                            i[c].Operand    = trampoline;
                                            foundXamlLoader = true;
                                        }
                                    }
                                }
                            }
                        }

                        if (!foundXamlLoader)
                        {
                            var ctors = classTypeDefinition.GetConstructors()
                                        .Where(c => !c.IsStatic).ToList();
                            // We can inject xaml loader into default constructor
                            if (ctors.Count == 1 && ctors[0].Body.Instructions.Count(o => o.OpCode != OpCodes.Nop) == 3)
                            {
                                var i      = ctors[0].Body.Instructions;
                                var retIdx = i.IndexOf(i.Last(x => x.OpCode == OpCodes.Ret));
                                i.Insert(retIdx, Instruction.Create(OpCodes.Call, trampoline));
                                i.Insert(retIdx, Instruction.Create(OpCodes.Ldarg_0));
                            }
                            else
                            {
                                throw new InvalidProgramException(
                                          $"No call to RobustXamlLoader.Load(this) call found anywhere in the type {classType.FullName} and type seems to have custom constructors.");
                            }
                        }

                        //add compiled build method
                        var compiledBuildMethod = typeSystem.GetTypeReference(builder).Resolve().Methods
                                                  .First(m => m.Name == buildName);
                        var parameterlessCtor = classTypeDefinition.GetConstructors()
                                                .FirstOrDefault(c => c.IsPublic && !c.IsStatic && !c.HasParameters);

                        if (compiledBuildMethod != null && parameterlessCtor != null)
                        {
                            var i   = loaderDispatcherMethod.Body.Instructions;
                            var nop = Instruction.Create(OpCodes.Nop);
                            i.Add(Instruction.Create(OpCodes.Ldarg_0));
                            i.Add(Instruction.Create(OpCodes.Ldstr, res.Uri));
                            i.Add(Instruction.Create(OpCodes.Call, stringEquals));
                            i.Add(Instruction.Create(OpCodes.Brfalse, nop));
                            if (parameterlessCtor != null)
                            {
                                i.Add(Instruction.Create(OpCodes.Newobj, parameterlessCtor));
                            }
                            else
                            {
                                i.Add(Instruction.Create(OpCodes.Call, compiledBuildMethod));
                            }

                            i.Add(Instruction.Create(OpCodes.Ret));
                            i.Add(nop);
                        }
                    }
                    catch (Exception e)
                    {
                        engine.LogErrorEvent(new BuildErrorEventArgs("XAMLIL", "", res.FilePath, 0, 0, 0, 0,
                                                                     $"{res.FilePath}: {e.Message}", "", "CompileRobustXaml"));
                    }
                }
                return(true);
            }

            if (embrsc.Resources.Count(CheckXamlName) != 0)
            {
                if (!CompileGroup(embrsc))
                {
                    return(false);
                }
            }

            loaderDispatcherMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ldnull));
            loaderDispatcherMethod.Body.Instructions.Add(Instruction.Create(OpCodes.Ret));
            return(true);
        }
コード例 #27
0
 public AvaloniaXamlIlCompiler(TransformerConfiguration configuration,
                               XamlLanguageEmitMappings <IXamlILEmitter, XamlILNodeEmitResult> emitMappings,
                               IXamlType contextType) : this(configuration, emitMappings)
 {
     _contextType = contextType;
 }
コード例 #28
0
        /// <summary>
        /// Create an entire stack.
        /// </summary>
        /// <param name="readerId"></param>
        /// <param name="config"></param>
        /// <returns></returns>
        public static IStack CreateStack(string readerId, CollectorConfiguration config)
        {
            var stack = ComponentRegistration.CreateInstance <IStack>(config.StackType);

            foreach (var readerConfig in config.Readers)
            {
                if (readerConfig.Id == readerId)
                {
                    var newReaderId = Guid.NewGuid().ToString();

                    List <IPublisher>   publishers   = new List <IPublisher>();
                    List <ITransformer> transformers = new List <ITransformer>();
                    foreach (var transformerConfig in config.Transformers)
                    {
                        if (transformerConfig.ReaderId == readerId)
                        {
                            var newTransformerId = Guid.NewGuid().ToString();
                            foreach (var publisherConfig in config.Publishers)
                            {
                                if (publisherConfig.TransformerId == transformerConfig.Id)
                                {
                                    foreach (var endpoint in config.EndPoints)
                                    {
                                        if (endpoint.Id == publisherConfig.EndpointId)
                                        {
                                            var newEndpoint = new EndPointConfiguration()
                                            {
                                                Id       = Guid.NewGuid().ToString(),
                                                Password = endpoint.Password,
                                                User     = endpoint.User
                                            };
                                            foreach (var key in endpoint.Properties.Keys)
                                            {
                                                newEndpoint.Properties.Add(key, endpoint.Properties[key]);
                                            }

                                            var newPublisherConfig = new PublisherConfiguration()
                                            {
                                                Id            = Guid.NewGuid().ToString(),
                                                EndpointId    = newEndpoint.Id,
                                                TransformerId = newTransformerId,
                                                Type          = publisherConfig.Type
                                            };
                                            var publisher = CreatePublisher(newPublisherConfig, endpoint);
                                            publishers.Add(publisher);
                                        }
                                    }
                                }
                            }
                            var newTransformerConfig = new TransformerConfiguration()
                            {
                                Id       = newTransformerId,
                                Type     = transformerConfig.Type,
                                ReaderId = newReaderId,
                            };
                            foreach (var mapper in transformerConfig.Mappers)
                            {
                                var newMapperConfig = new MapperConfiguration()
                                {
                                    Id                   = mapper.Id,
                                    DataType             = mapper.DataType,
                                    TransformerId        = newTransformerId,
                                    Type                 = mapper.Type,
                                    SourceTargetMappings = mapper.SourceTargetMappings
                                };
                                foreach (var converter in mapper.PipedConverters)
                                {
                                    var newConverter = CopyConfig(converter);
                                    newMapperConfig.PipedConverters.Add(converter);
                                }
                                foreach (var converter in mapper.Converters)
                                {
                                    var newConverter = CopyConfig(converter);
                                    newMapperConfig.Converters.Add(converter);
                                }
                                newTransformerConfig.Mappers.Add(newMapperConfig);
                            }
                            var transformer = CreateTransformer(newTransformerConfig, stack);
                            transformers.Add(transformer);
                        }
                    }
                    foreach (var endpoint in config.EndPoints)
                    {
                        if (readerConfig.EndpointId.Equals(endpoint.Id))
                        {
                            var newEndpoint = new EndPointConfiguration()
                            {
                                Id       = Guid.NewGuid().ToString(),
                                Password = endpoint.Password,
                                User     = endpoint.User
                            };
                            foreach (var key in endpoint.Properties.Keys)
                            {
                                newEndpoint.Properties.Add(key, endpoint.Properties[key]);
                            }
                            var reader = CreateReader(readerConfig.Type, newReaderId, newEndpoint, stack);
                            stack.Configure(reader, transformers, publishers);
                            break;
                        }
                    }
                    break;
                }
            }
            return(stack);
        }
コード例 #29
0
        public AvaloniaXamlIlWellKnownTypes(TransformerConfiguration cfg)
        {
            XamlIlTypes              = cfg.WellKnownTypes;
            AvaloniaObject           = cfg.TypeSystem.GetType("Avalonia.AvaloniaObject");
            IAvaloniaObject          = cfg.TypeSystem.GetType("Avalonia.IAvaloniaObject");
            AvaloniaObjectExtensions = cfg.TypeSystem.GetType("Avalonia.AvaloniaObjectExtensions");
            AvaloniaProperty         = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty");
            AvaloniaPropertyT        = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty`1");
            BindingPriority          = cfg.TypeSystem.GetType("Avalonia.Data.BindingPriority");
            IBinding                 = cfg.TypeSystem.GetType("Avalonia.Data.IBinding");
            IDisposable              = cfg.TypeSystem.GetType("System.IDisposable");
            Transitions              = cfg.TypeSystem.GetType("Avalonia.Animation.Transitions");
            AssignBindingAttribute   = cfg.TypeSystem.GetType("Avalonia.Data.AssignBindingAttribute");
            AvaloniaObjectBindMethod = AvaloniaObjectExtensions.FindMethod("Bind", IDisposable, false, IAvaloniaObject,
                                                                           AvaloniaProperty,
                                                                           IBinding, cfg.WellKnownTypes.Object);
            UnsetValueType     = cfg.TypeSystem.GetType("Avalonia.UnsetValueType");
            StyledElement      = cfg.TypeSystem.GetType("Avalonia.StyledElement");
            INameScope         = cfg.TypeSystem.GetType("Avalonia.Controls.INameScope");
            INameScopeRegister = INameScope.GetMethod(
                new FindMethodMethodSignature("Register", XamlIlTypes.Void,
                                              XamlIlTypes.String, XamlIlTypes.Object)
            {
                IsStatic      = false,
                DeclaringOnly = true,
                IsExactMatch  = true
            });
            INameScopeComplete = INameScope.GetMethod(
                new FindMethodMethodSignature("Complete", XamlIlTypes.Void)
            {
                IsStatic      = false,
                DeclaringOnly = true,
                IsExactMatch  = true
            });
            NameScope             = cfg.TypeSystem.GetType("Avalonia.Controls.NameScope");
            NameScopeSetNameScope = NameScope.GetMethod(new FindMethodMethodSignature("SetNameScope",
                                                                                      XamlIlTypes.Void, StyledElement, INameScope)
            {
                IsStatic = true
            });
            AvaloniaObjectSetValueMethod = AvaloniaObject.FindMethod("SetValue", XamlIlTypes.Void,
                                                                     false, AvaloniaProperty, XamlIlTypes.Object, BindingPriority);
            IPropertyInfo               = cfg.TypeSystem.GetType("Avalonia.Data.Core.IPropertyInfo");
            ClrPropertyInfo             = cfg.TypeSystem.GetType("Avalonia.Data.Core.ClrPropertyInfo");
            PropertyPath                = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPath");
            PropertyPathBuilder         = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPathBuilder");
            IPropertyAccessor           = cfg.TypeSystem.GetType("Avalonia.Data.Core.Plugins.IPropertyAccessor");
            PropertyInfoAccessorFactory = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.PropertyInfoAccessorFactory");
            CompiledBindingPathBuilder  = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPathBuilder");
            CompiledBindingPath         = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPath");
            CompiledBindingExtension    = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindingExtension");
            ResolveByNameExtension      = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ResolveByNameExtension");
            DataTemplate                = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.Templates.DataTemplate");
            IDataTemplate               = cfg.TypeSystem.GetType("Avalonia.Controls.Templates.IDataTemplate");
            IItemsPresenterHost         = cfg.TypeSystem.GetType("Avalonia.Controls.Presenters.IItemsPresenterHost");
            ItemsRepeater               = cfg.TypeSystem.GetType("Avalonia.Controls.ItemsRepeater");
            ReflectionBindingExtension  = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ReflectionBindingExtension");
            RelativeSource              = cfg.TypeSystem.GetType("Avalonia.Data.RelativeSource");
            UInt       = cfg.TypeSystem.GetType("System.UInt32");
            Long       = cfg.TypeSystem.GetType("System.Int64");
            Uri        = cfg.TypeSystem.GetType("System.Uri");
            FontFamily = cfg.TypeSystem.GetType("Avalonia.Media.FontFamily");
            FontFamilyConstructorUriName = FontFamily.GetConstructor(new List <IXamlType> {
                Uri, XamlIlTypes.String
            });

            (IXamlType, IXamlConstructor) GetNumericTypeInfo(string name, IXamlType componentType, int componentCount)
            {
                var type = cfg.TypeSystem.GetType(name);
                var ctor = type.GetConstructor(Enumerable.Range(0, componentCount).Select(_ => componentType).ToList());

                return(type, ctor);
            }

            (Thickness, ThicknessFullConstructor)       = GetNumericTypeInfo("Avalonia.Thickness", XamlIlTypes.Double, 4);
            (Point, PointFullConstructor)               = GetNumericTypeInfo("Avalonia.Point", XamlIlTypes.Double, 2);
            (Vector, VectorFullConstructor)             = GetNumericTypeInfo("Avalonia.Vector", XamlIlTypes.Double, 2);
            (Size, SizeFullConstructor)                 = GetNumericTypeInfo("Avalonia.Size", XamlIlTypes.Double, 2);
            (Matrix, MatrixFullConstructor)             = GetNumericTypeInfo("Avalonia.Matrix", XamlIlTypes.Double, 6);
            (CornerRadius, CornerRadiusFullConstructor) = GetNumericTypeInfo("Avalonia.CornerRadius", XamlIlTypes.Double, 4);

            GridLength = cfg.TypeSystem.GetType("Avalonia.Controls.GridLength");
            GridLengthConstructorValueType = GridLength.GetConstructor(new List <IXamlType> {
                XamlIlTypes.Double, cfg.TypeSystem.GetType("Avalonia.Controls.GridUnitType")
            });
            Color = cfg.TypeSystem.GetType("Avalonia.Media.Color");
            StandardCursorType    = cfg.TypeSystem.GetType("Avalonia.Input.StandardCursorType");
            Cursor                = cfg.TypeSystem.GetType("Avalonia.Input.Cursor");
            CursorTypeConstructor = Cursor.GetConstructor(new List <IXamlType> {
                StandardCursorType
            });
        }
コード例 #30
0
        public AvaloniaXamlIlWellKnownTypes(TransformerConfiguration cfg)
        {
            XamlIlTypes                          = cfg.WellKnownTypes;
            AvaloniaObject                       = cfg.TypeSystem.GetType("Avalonia.AvaloniaObject");
            IAvaloniaObject                      = cfg.TypeSystem.GetType("Avalonia.IAvaloniaObject");
            AvaloniaObjectExtensions             = cfg.TypeSystem.GetType("Avalonia.AvaloniaObjectExtensions");
            AvaloniaProperty                     = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty");
            AvaloniaPropertyT                    = cfg.TypeSystem.GetType("Avalonia.AvaloniaProperty`1");
            StyledPropertyT                      = cfg.TypeSystem.GetType("Avalonia.StyledProperty`1");
            AvaloniaAttachedPropertyT            = cfg.TypeSystem.GetType("Avalonia.AttachedProperty`1");
            BindingPriority                      = cfg.TypeSystem.GetType("Avalonia.Data.BindingPriority");
            AvaloniaObjectSetStyledPropertyValue = AvaloniaObject
                                                   .FindMethod(m => m.IsPublic && !m.IsStatic && m.Name == "SetValue" &&
                                                               m.Parameters.Count == 3 &&
                                                               m.Parameters[0].Name == "StyledPropertyBase`1" &&
                                                               m.Parameters[2].Equals(BindingPriority));
            IBinding                 = cfg.TypeSystem.GetType("Avalonia.Data.IBinding");
            IDisposable              = cfg.TypeSystem.GetType("System.IDisposable");
            ICommand                 = cfg.TypeSystem.GetType("System.Windows.Input.ICommand");
            Transitions              = cfg.TypeSystem.GetType("Avalonia.Animation.Transitions");
            AssignBindingAttribute   = cfg.TypeSystem.GetType("Avalonia.Data.AssignBindingAttribute");
            DependsOnAttribute       = cfg.TypeSystem.GetType("Avalonia.Metadata.DependsOnAttribute");
            DataTypeAttribute        = cfg.TypeSystem.GetType("Avalonia.Metadata.DataTypeAttribute");
            AvaloniaObjectBindMethod = AvaloniaObjectExtensions.FindMethod("Bind", IDisposable, false, IAvaloniaObject,
                                                                           AvaloniaProperty,
                                                                           IBinding, cfg.WellKnownTypes.Object);
            UnsetValueType     = cfg.TypeSystem.GetType("Avalonia.UnsetValueType");
            StyledElement      = cfg.TypeSystem.GetType("Avalonia.StyledElement");
            IStyledElement     = cfg.TypeSystem.GetType("Avalonia.IStyledElement");
            INameScope         = cfg.TypeSystem.GetType("Avalonia.Controls.INameScope");
            INameScopeRegister = INameScope.GetMethod(
                new FindMethodMethodSignature("Register", XamlIlTypes.Void,
                                              XamlIlTypes.String, XamlIlTypes.Object)
            {
                IsStatic      = false,
                DeclaringOnly = true,
                IsExactMatch  = true
            });
            INameScopeComplete = INameScope.GetMethod(
                new FindMethodMethodSignature("Complete", XamlIlTypes.Void)
            {
                IsStatic      = false,
                DeclaringOnly = true,
                IsExactMatch  = true
            });
            NameScope             = cfg.TypeSystem.GetType("Avalonia.Controls.NameScope");
            NameScopeSetNameScope = NameScope.GetMethod(new FindMethodMethodSignature("SetNameScope",
                                                                                      XamlIlTypes.Void, StyledElement, INameScope)
            {
                IsStatic = true
            });
            AvaloniaObjectSetValueMethod = AvaloniaObject.FindMethod("SetValue", IDisposable,
                                                                     false, AvaloniaProperty, XamlIlTypes.Object, BindingPriority);
            IPropertyInfo               = cfg.TypeSystem.GetType("Avalonia.Data.Core.IPropertyInfo");
            ClrPropertyInfo             = cfg.TypeSystem.GetType("Avalonia.Data.Core.ClrPropertyInfo");
            PropertyPath                = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPath");
            PropertyPathBuilder         = cfg.TypeSystem.GetType("Avalonia.Data.Core.PropertyPathBuilder");
            IPropertyAccessor           = cfg.TypeSystem.GetType("Avalonia.Data.Core.Plugins.IPropertyAccessor");
            PropertyInfoAccessorFactory = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.PropertyInfoAccessorFactory");
            CompiledBindingPathBuilder  = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPathBuilder");
            CompiledBindingPath         = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindings.CompiledBindingPath");
            CompiledBindingExtension    = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.CompiledBindingExtension");
            ResolveByNameExtension      = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ResolveByNameExtension");
            DataTemplate                = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.Templates.DataTemplate");
            IDataTemplate               = cfg.TypeSystem.GetType("Avalonia.Controls.Templates.IDataTemplate");
            IItemsPresenterHost         = cfg.TypeSystem.GetType("Avalonia.Controls.Presenters.IItemsPresenterHost");
            ItemsRepeater               = cfg.TypeSystem.GetType("Avalonia.Controls.ItemsRepeater");
            ReflectionBindingExtension  = cfg.TypeSystem.GetType("Avalonia.Markup.Xaml.MarkupExtensions.ReflectionBindingExtension");
            RelativeSource              = cfg.TypeSystem.GetType("Avalonia.Data.RelativeSource");
            UInt       = cfg.TypeSystem.GetType("System.UInt32");
            Int        = cfg.TypeSystem.GetType("System.Int32");
            Long       = cfg.TypeSystem.GetType("System.Int64");
            Uri        = cfg.TypeSystem.GetType("System.Uri");
            FontFamily = cfg.TypeSystem.GetType("Avalonia.Media.FontFamily");
            FontFamilyConstructorUriName = FontFamily.GetConstructor(new List <IXamlType> {
                Uri, XamlIlTypes.String
            });

            (IXamlType, IXamlConstructor) GetNumericTypeInfo(string name, IXamlType componentType, int componentCount)
            {
                var type = cfg.TypeSystem.GetType(name);
                var ctor = type.GetConstructor(Enumerable.Range(0, componentCount).Select(_ => componentType).ToList());

                return(type, ctor);
            }

            (Thickness, ThicknessFullConstructor)       = GetNumericTypeInfo("Avalonia.Thickness", XamlIlTypes.Double, 4);
            (Point, PointFullConstructor)               = GetNumericTypeInfo("Avalonia.Point", XamlIlTypes.Double, 2);
            (Vector, VectorFullConstructor)             = GetNumericTypeInfo("Avalonia.Vector", XamlIlTypes.Double, 2);
            (Size, SizeFullConstructor)                 = GetNumericTypeInfo("Avalonia.Size", XamlIlTypes.Double, 2);
            (Matrix, MatrixFullConstructor)             = GetNumericTypeInfo("Avalonia.Matrix", XamlIlTypes.Double, 6);
            (CornerRadius, CornerRadiusFullConstructor) = GetNumericTypeInfo("Avalonia.CornerRadius", XamlIlTypes.Double, 4);

            RelativeUnit  = cfg.TypeSystem.GetType("Avalonia.RelativeUnit");
            RelativePoint = cfg.TypeSystem.GetType("Avalonia.RelativePoint");
            RelativePointFullConstructor = RelativePoint.GetConstructor(new List <IXamlType> {
                XamlIlTypes.Double, XamlIlTypes.Double, RelativeUnit
            });

            GridLength = cfg.TypeSystem.GetType("Avalonia.Controls.GridLength");
            GridLengthConstructorValueType = GridLength.GetConstructor(new List <IXamlType> {
                XamlIlTypes.Double, cfg.TypeSystem.GetType("Avalonia.Controls.GridUnitType")
            });
            Color = cfg.TypeSystem.GetType("Avalonia.Media.Color");
            StandardCursorType    = cfg.TypeSystem.GetType("Avalonia.Input.StandardCursorType");
            Cursor                = cfg.TypeSystem.GetType("Avalonia.Input.Cursor");
            CursorTypeConstructor = Cursor.GetConstructor(new List <IXamlType> {
                StandardCursorType
            });
            ColumnDefinition             = cfg.TypeSystem.GetType("Avalonia.Controls.ColumnDefinition");
            ColumnDefinitions            = cfg.TypeSystem.GetType("Avalonia.Controls.ColumnDefinitions");
            RowDefinition                = cfg.TypeSystem.GetType("Avalonia.Controls.RowDefinition");
            RowDefinitions               = cfg.TypeSystem.GetType("Avalonia.Controls.RowDefinitions");
            Classes                      = cfg.TypeSystem.GetType("Avalonia.Controls.Classes");
            StyledElementClassesProperty =
                StyledElement.Properties.First(x => x.Name == "Classes" && x.PropertyType.Equals(Classes));
            ClassesBindMethod = cfg.TypeSystem.GetType("Avalonia.StyledElementExtensions")
                                .FindMethod("BindClass", IDisposable, false, IStyledElement,
                                            cfg.WellKnownTypes.String,
                                            IBinding, cfg.WellKnownTypes.Object);

            IBrush = cfg.TypeSystem.GetType("Avalonia.Media.IBrush");
            ImmutableSolidColorBrush = cfg.TypeSystem.GetType("Avalonia.Media.Immutable.ImmutableSolidColorBrush");
            ImmutableSolidColorBrushConstructorColor = ImmutableSolidColorBrush.GetConstructor(new List <IXamlType> {
                UInt
            });
            TypeUtilities            = cfg.TypeSystem.GetType("Avalonia.Utilities.TypeUtilities");
            TextDecorationCollection = cfg.TypeSystem.GetType("Avalonia.Media.TextDecorationCollection");
            TextDecorations          = cfg.TypeSystem.GetType("Avalonia.Media.TextDecorations");
            TextTrimming             = cfg.TypeSystem.GetType("Avalonia.Media.TextTrimming");
            ISetter                       = cfg.TypeSystem.GetType("Avalonia.Styling.ISetter");
            IResourceDictionary           = cfg.TypeSystem.GetType("Avalonia.Controls.IResourceDictionary");
            ResourceDictionary            = cfg.TypeSystem.GetType("Avalonia.Controls.ResourceDictionary");
            ResourceDictionaryDeferredAdd = ResourceDictionary.FindMethod("AddDeferred", XamlIlTypes.Void, true, XamlIlTypes.Object,
                                                                          cfg.TypeSystem.GetType("System.Func`2").MakeGenericType(
                                                                              cfg.TypeSystem.GetType("System.IServiceProvider"),
                                                                              XamlIlTypes.Object));
        }