static object LoadSreCore(string xaml, Assembly localAssembly, object rootInstance, Uri uri, bool isDesignMode)
        {
            InitializeSre();
            var asm = localAssembly == null ? null : _sreTypeSystem.GetAssembly(localAssembly);
            var tb  = _sreBuilder.DefineType("Builder_" + Guid.NewGuid().ToString("N") + "_" + uri);
            var clrPropertyBuilder = tb.DefineNestedType("ClrProperties_" + Guid.NewGuid().ToString("N"));
            var indexerClosureType = _sreBuilder.DefineType("IndexerClosure_" + Guid.NewGuid().ToString("N"));

            var compiler = new AvaloniaXamlIlCompiler(new AvaloniaXamlIlCompilerConfiguration(_sreTypeSystem, asm,
                                                                                              _sreMappings, _sreXmlns, AvaloniaXamlIlLanguage.CustomValueConverter,
                                                                                              new XamlIlClrPropertyInfoEmitter(_sreTypeSystem.CreateTypeBuilder(clrPropertyBuilder)),
                                                                                              new XamlIlPropertyInfoAccessorFactoryEmitter(_sreTypeSystem.CreateTypeBuilder(indexerClosureType))),
                                                      _sreEmitMappings,
                                                      _sreContextType)
            {
                EnableIlVerification = true
            };


            IXamlType overrideType = null;

            if (rootInstance != null)
            {
                overrideType = _sreTypeSystem.GetType(rootInstance.GetType());
            }

            compiler.IsDesignMode = isDesignMode;
            compiler.ParseAndCompile(xaml, uri?.ToString(), null, _sreTypeSystem.CreateTypeBuilder(tb), overrideType);
            var created = tb.CreateTypeInfo();

            clrPropertyBuilder.CreateTypeInfo();

            return(LoadOrPopulate(created, rootInstance));
        }
Ejemplo n.º 2
0
        static object LoadSreCore(string xaml, Assembly localAssembly, object rootInstance, Uri uri, bool isDesignMode)
        {
            InitializeSre();
            var asm = localAssembly == null ? null : _sreTypeSystem.GetAssembly(localAssembly);

            var compiler = new AvaloniaXamlIlCompiler(new XamlIlTransformerConfiguration(_sreTypeSystem, asm,
                                                                                         _sreMappings, _sreXmlns, AvaloniaXamlIlLanguage.CustomValueConverter),
                                                      _sreContextType);
            var tb = _sreBuilder.DefineType("Builder_" + Guid.NewGuid().ToString("N") + "_" + uri);

            IXamlIlType overrideType = null;

            if (rootInstance != null)
            {
                overrideType = _sreTypeSystem.GetType(rootInstance.GetType());
            }

            compiler.IsDesignMode = isDesignMode;
            compiler.ParseAndCompile(xaml, uri?.ToString(), null, _sreTypeSystem.CreateTypeBuilder(tb), overrideType);
            var created = tb.CreateTypeInfo();

            return(LoadOrPopulate(created, rootInstance));
        }