Пример #1
0
        IXamlIlType EmitTypeDescriptorContextStub(IXamlIlTypeSystem typeSystem, IXamlIlTypeBuilder builder,
                                                  XamlIlLanguageTypeMappings mappings)
        {
            if (mappings.TypeDescriptorContext == null)
            {
                return(null);
            }
            var tdc       = mappings.TypeDescriptorContext;
            var tdcPrefix = tdc.Namespace + "." + tdc.Name + ".";

            builder.AddInterfaceImplementation(mappings.TypeDescriptorContext);
            void PropertyStub(string name) => ImplementInterfacePropertyGetter(builder, tdc, name).Generator.Ldnull().Ret();

            PropertyStub("Container");
            PropertyStub("Instance");
            PropertyStub("PropertyDescriptor");

            void MethodStub(string name)
            {
                var original = tdc.FindMethod(m => m.Name == name);

                builder.DefineMethod(original.ReturnType, original.Parameters, tdcPrefix + name,
                                     false, false, true,
                                     original)
                .Generator
                .Emit(OpCodes.Newobj,
                      typeSystem.FindType("System.NotSupportedException").FindConstructor(new List <IXamlIlType>()))
                .Emit(OpCodes.Throw);
            }

            MethodStub("OnComponentChanging");
            MethodStub("OnComponentChanged");

            return(mappings.TypeDescriptorContext);
        }
Пример #2
0
        public static IXamlIlType GetType(this IXamlIlTypeSystem sys, string type)
        {
            var f = sys.FindType(type);

            if (f == null)
            {
                throw new XamlIlTypeSystemException("Unable to resolve type " + type);
            }
            return(f);
        }
Пример #3
0
 public CompilerTestBase(IXamlIlTypeSystem typeSystem)
 {
     _typeSystem   = typeSystem;
     Configuration = new XamlIlTransformerConfiguration(typeSystem,
                                                        typeSystem.FindAssembly("XamlParserTests"),
                                                        new XamlIlLanguageTypeMappings(typeSystem)
     {
         XmlnsAttributes =
         {
             typeSystem.FindType("XamlParserTests.XmlnsDefinitionAttribute"),
         },
         ContentAttributes =
         {
             typeSystem.FindType("XamlParserTests.ContentAttribute")
         },
         RootObjectProvider = typeSystem.FindType("XamlParserTests.ITestRootObjectProvider"),
         ApplyNonMatchingMarkupExtension = typeSystem.GetType("XamlParserTests.CompilerTestBase")
                                           .Methods.First(m => m.Name == "ApplyNonMatchingMarkupExtension")
     }
                                                        );
 }
Пример #4
0
        private static void EmitNameScopeField(XamlIlLanguageTypeMappings mappings,
                                               IXamlIlTypeSystem typeSystem,
                                               IXamlIlTypeBuilder typebuilder, IXamlIlEmitter constructor)
        {
            var nameScopeType = typeSystem.FindType("Avalonia.Controls.INameScope");
            var field         = typebuilder.DefineField(nameScopeType,
                                                        ContextNameScopeFieldName, true, false);

            constructor
            .Ldarg_0()
            .Ldarg(1)
            .Ldtype(nameScopeType)
            .EmitCall(mappings.ServiceProvider.GetMethod(new FindMethodMethodSignature("GetService",
                                                                                       typeSystem.FindType("System.Object"), typeSystem.FindType("System.Type"))))
            .Stfld(field);
        }
Пример #5
0
        public static XamlIlLanguageTypeMappings Configure(IXamlIlTypeSystem typeSystem)
        {
            var runtimeHelpers         = typeSystem.GetType("Avalonia.Markup.Xaml.XamlIl.Runtime.XamlIlRuntimeHelpers");
            var assignBindingAttribute = typeSystem.GetType("Avalonia.Data.AssignBindingAttribute");
            var bindingType            = typeSystem.GetType("Avalonia.Data.IBinding");
            var rv = new XamlIlLanguageTypeMappings(typeSystem)
            {
                SupportInitialize = typeSystem.GetType("System.ComponentModel.ISupportInitialize"),
                XmlnsAttributes   =
                {
                    typeSystem.GetType("Avalonia.Metadata.XmlnsDefinitionAttribute"),
                    typeSystem.FindType("Portable.Xaml.Markup.XmlnsDefinitionAttribute")
                },
                ContentAttributes =
                {
                    typeSystem.GetType("Avalonia.Metadata.ContentAttribute")
                },
                ProvideValueTarget  = typeSystem.GetType("Portable.Xaml.Markup.IProvideValueTarget"),
                RootObjectProvider  = typeSystem.GetType("Portable.Xaml.IRootObjectProvider"),
                UriContextProvider  = typeSystem.GetType("Portable.Xaml.Markup.IUriContext"),
                ParentStackProvider =
                    typeSystem.GetType("Avalonia.Markup.Xaml.XamlIl.Runtime.IAvaloniaXamlIlParentStackProvider"),

                XmlNamespaceInfoProvider =
                    typeSystem.GetType("Avalonia.Markup.Xaml.XamlIl.Runtime.IAvaloniaXamlIlXmlNamespaceInfoProvider"),
                DeferredContentPropertyAttributes    = { typeSystem.GetType("Avalonia.Metadata.TemplateContentAttribute") },
                DeferredContentExecutorCustomization =
                    runtimeHelpers.FindMethod(m => m.Name == "DeferredTransformationFactoryV1"),
                UsableDuringInitializationAttributes =
                {
                    typeSystem.GetType("Portable.Xaml.Markup.UsableDuringInitializationAttribute"),
                    typeSystem.GetType("Avalonia.Metadata.UsableDuringInitializationAttribute"),
                },
                InnerServiceProviderFactoryMethod =
                    runtimeHelpers.FindMethod(m => m.Name == "CreateInnerServiceProviderV1"),
                ProvideValueTargetPropertyEmitter = XamlIlAvaloniaPropertyHelper.Emit,
            };

            rv.CustomAttributeResolver = new AttributeResolver(typeSystem, rv);
            return(rv);
        }
Пример #6
0
 public XamlIlLanguageTypeMappings(IXamlIlTypeSystem typeSystem)
 {
     ServiceProvider = typeSystem.FindType("System.IServiceProvider");
 }