示例#1
0
        public void Compile(XamlIlDocument doc, IXamlIlType contextType,
                            IXamlIlMethodBuilder populateMethod, IXamlIlMethodBuilder buildMethod,
                            IXamlIlTypeBuilder namespaceInfoBuilder,
                            Func <string, IXamlIlType, IXamlIlTypeBuilder> createClosure,
                            string baseUri, IFileSource fileSource)
        {
            var rootGrp         = (XamlIlValueWithManipulationNode)doc.Root;
            var staticProviders = new List <IXamlIlField>();

            if (namespaceInfoBuilder != null)
            {
                staticProviders.Add(
                    XamlIlNamespaceInfoHelper.EmitNamespaceInfoProvider(_configuration, namespaceInfoBuilder, doc));
            }

            var context = new XamlIlContext(contextType, rootGrp.Type.GetClrType(),
                                            _configuration.TypeMappings, baseUri, staticProviders);

            CompilePopulate(fileSource, rootGrp.Manipulation, createClosure, populateMethod.Generator, context);

            if (buildMethod != null)
            {
                CompileBuild(fileSource, rootGrp.Value, null, buildMethod.Generator, context, populateMethod);
            }

            namespaceInfoBuilder?.CreateType();
        }
示例#2
0
        public void Compile(XamlIlDocument doc, IXamlIlTypeBuilder typeBuilder,
                            string populateMethodName, string createMethodName, string contextClassName, string namespaceInfoClassName,
                            string baseUri)
        {
            var rootGrp         = (XamlIlValueWithManipulationNode)doc.Root;
            var staticProviders = new List <IXamlIlField>();

            IXamlIlTypeBuilder namespaceInfoBuilder = null;

            if (_configuration.TypeMappings.XmlNamespaceInfoProvider != null)
            {
                namespaceInfoBuilder = typeBuilder.DefineSubType(_configuration.WellKnownTypes.Object,
                                                                 namespaceInfoClassName, false);
                staticProviders.Add(
                    XamlIlNamespaceInfoHelper.EmitNamespaceInfoProvider(_configuration, namespaceInfoBuilder, doc));
            }

            var contextBuilder = typeBuilder.DefineSubType(_configuration.WellKnownTypes.Object,
                                                           contextClassName, false);

            var contextType = XamlIlContext.GenerateContextClass(contextBuilder, _configuration.TypeSystem,
                                                                 _configuration.TypeMappings, rootGrp.Type.GetClrType(), staticProviders, baseUri);

            var populateMethod = typeBuilder.DefineMethod(_configuration.WellKnownTypes.Void,
                                                          new[] { _configuration.TypeMappings.ServiceProvider, rootGrp.Type.GetClrType() },
                                                          populateMethodName, true, true, false);

            IXamlIlTypeBuilder CreateSubType(string name, IXamlIlType baseType)
            => typeBuilder.DefineSubType(baseType, name, false);

            CompilePopulate(rootGrp.Manipulation, CreateSubType, populateMethod.Generator, contextType);

            var createMethod = typeBuilder.DefineMethod(rootGrp.Type.GetClrType(),
                                                        new[] { _configuration.TypeMappings.ServiceProvider }, createMethodName, true, true, false);

            CompileBuild(rootGrp.Value, CreateSubType, createMethod.Generator, contextType, populateMethod);
            namespaceInfoBuilder?.CreateType();
            contextType.CreateAllTypes();
        }