コード例 #1
0
        public object SkipDuplicatePropertyCheck_Loader(string xaml)
        {
            XamlObjectWriterSettings settings = new XamlObjectWriterSettings
            {
                SkipDuplicatePropertyCheck = true
            };
            XamlXmlReader    reader = new XamlXmlReader(XmlReader.Create(new StringReader(xaml)));
            XamlObjectWriter writer = new XamlObjectWriter(reader.SchemaContext, settings);

            XamlServices.Transform(reader, writer);
            return(writer.Result);
        }
コード例 #2
0
ファイル: XamlObjectWriter.cs プロジェクト: nuxleus/mono
        public XamlObjectWriter(XamlSchemaContext schemaContext, XamlObjectWriterSettings settings)
        {
            if (schemaContext == null)
            {
                throw new ArgumentNullException("schemaContext");
            }
            this.sctx     = schemaContext;
            this.settings = settings ?? new XamlObjectWriterSettings();
            var manager = new XamlWriterStateManager <XamlObjectWriterException, XamlObjectWriterException> (false);

            intl = new XamlObjectWriterInternal(this, sctx, manager);
        }
コード例 #3
0
        public ObjectWriterContext(XamlSavedContext savedContext,
                                   XamlObjectWriterSettings settings, XAML3.INameScope rootNameScope, XamlRuntime runtime)
            : base(savedContext.SchemaContext)
        {
            _stack = new XamlContextStack <ObjectWriterFrame>(savedContext.Stack, false);
            if (settings != null)
            {
                _settings = settings.StripDelegates();
            }
            _runtime = runtime;
            BaseUri  = savedContext.BaseUri;
            // If the bottom of the stack is a (no XamlType) Value (reparse) then back-up onto it.
            // Otherwise add a blank frame to isolate template use from the saved context.
            switch (savedContext.SaveContextType)
            {
            case SavedContextType.Template:
                // Templates always need a root namescope, to isolate them from the rest of the doc
                XAML3.INameScopeDictionary rootNameScopeDictionary = null;
                if (rootNameScope == null)
                {
#if TARGETTING35SP1
                    rootNameScopeDictionary = new NameScopeDictionary(new NameScope());
#else
                    rootNameScopeDictionary = new NameScope();
#endif
                }
                else
                {
                    rootNameScopeDictionary = rootNameScope as XAML3.INameScopeDictionary;

                    if (rootNameScopeDictionary == null)
                    {
                        rootNameScopeDictionary = new NameScopeDictionary(rootNameScope);
                    }
                }

                // Push an extra frame to ensure that the template NameScope is
                // not part of the saved context.  Otherwise, the namescope
                // will hold things alive as long as the template is alive
                _stack.PushScope();
                _savedDepth = _stack.Depth;
                _stack.CurrentFrame.NameScopeDictionary = rootNameScopeDictionary;
                _stack.PushScope();
                break;

            case SavedContextType.ReparseValue:
            case SavedContextType.ReparseMarkupExtension:
                Debug.Assert(rootNameScope == null, "Cannot pass a new namescope in to a reparse context");
                _savedDepth = _stack.Depth - 1;
                break;
            }
        }
コード例 #4
0
ファイル: XamlReader.cs プロジェクト: dox0/DotNet471RS3
        internal static XamlObjectWriterSettings CreateObjectWriterSettings(XamlObjectWriterSettings parentSettings)
        {
            XamlObjectWriterSettings owSettings = CreateObjectWriterSettings();

            if (parentSettings != null)
            {
                owSettings.SkipDuplicatePropertyCheck = parentSettings.SkipDuplicatePropertyCheck;
                owSettings.AccessLevel            = parentSettings.AccessLevel;
                owSettings.SkipProvideValueOnRoot = parentSettings.SkipProvideValueOnRoot;
                owSettings.SourceBamlUri          = parentSettings.SourceBamlUri;
            }
            return(owSettings);
        }
コード例 #5
0
        private static void InitializeComponentFromXamlResource(Type componentType, string resource, object componentInstance, XamlSchemaContext schemaContext)
        {
            Stream           initializeXaml = componentType.Assembly.GetManifestResourceStream(resource);
            XmlReader        xmlReader      = null;
            XamlReader       reader         = null;
            XamlObjectWriter objectWriter   = null;

            try
            {
                xmlReader = XmlReader.Create(initializeXaml);
                XamlXmlReaderSettings readerSettings = new XamlXmlReaderSettings
                {
                    LocalAssembly = componentType.Assembly,
                    AllowProtectedMembersOnRoot = true
                };
                reader = new XamlXmlReader(xmlReader, schemaContext, readerSettings);
                XamlObjectWriterSettings writerSettings = new XamlObjectWriterSettings
                {
                    RootObjectInstance = componentInstance
                };
                //writerSettings.AccessLevel = XamlAccessLevel.PrivateAccessTo(componentType);
                objectWriter = new XamlObjectWriter(schemaContext, writerSettings);

                // We need the XamlLoadPermission for the assembly we are dealing with.
                //XamlLoadPermission perm = new XamlLoadPermission(XamlAccessLevel.PrivateAccessTo(componentType));
                //perm.Assert();
                try
                {
                    XamlServices.Transform(reader, objectWriter);
                }
                finally
                {
                    //CodeAccessPermission.RevertAssert();
                }
            }
            finally
            {
                if ((xmlReader != null))
                {
                    ((IDisposable)(xmlReader)).Dispose();
                }
                if ((reader != null))
                {
                    ((IDisposable)(reader)).Dispose();
                }
                if ((objectWriter != null))
                {
                    ((IDisposable)(objectWriter)).Dispose();
                }
            }
        }
コード例 #6
0
ファイル: XamlReader.cs プロジェクト: zzlvff/Eto
        static T Load <T>(XamlXmlReader reader, T instance)
        {
            var writerSettings = new XamlObjectWriterSettings();

            writerSettings.ExternalNameScope = new EtoNameScope {
                Instance = instance
            };
            writerSettings.RegisterNamesOnExternalNamescope = true;
            writerSettings.RootObjectInstance = instance;
            var writer = new XamlObjectWriter(context, writerSettings);

            XamlServices.Transform(reader, writer);
            return((T)writer.Result);
        }
コード例 #7
0
ファイル: NameReferenceTests.cs プロジェクト: ay2015/wpf
        object LoadWithInjectedName(string xaml, string name, object value)
        {
            XamlObjectWriterSettings settings = new XamlObjectWriterSettings()
            {
                ExternalNameScope = new ElementHolderWithNameScope()
            };

            settings.ExternalNameScope.RegisterName(name, value);
            XamlXmlReader    reader = new XamlXmlReader(XmlReader.Create(new StringReader(xaml)));
            XamlObjectWriter writer = new XamlObjectWriter(reader.SchemaContext, settings);

            XamlServices.Transform(reader, writer);
            return(writer.Result);
        }
コード例 #8
0
    // AfterSerializing event doesn't seem to be easily possible, see below
    public object LoadXaml(TextReader textReader)
    {
        var settings = new XamlObjectWriterSettings
        {
            BeforePropertiesHandler = (s, e) => BeforeDeserializing?.Invoke(this, e),
            AfterPropertiesHandler  = (s, e) => AfterDeserializing?.Invoke(this, e)
        };

        using (var xmlReader = XmlReader.Create(textReader))
            using (var xamlReader = new XamlXmlReader(xmlReader))
                using (var xamlWriter = new XamlObjectWriter(xamlReader.SchemaContext, settings))
                {
                    XamlServices.Transform(xamlReader, xamlWriter);
                    return(xamlWriter.Result);
                }
    }
コード例 #9
0
		public void DefaultValues ()
		{
			var s = new XamlObjectWriterSettings ();
			// TODO: Assert.IsNull (s.AccessLevel, "#1");
			Assert.IsNull (s.AfterBeginInitHandler, "#2");
			Assert.IsNull (s.AfterEndInitHandler, "#3");
			Assert.IsNull (s.AfterPropertiesHandler, "#4");
			Assert.IsNull (s.BeforePropertiesHandler, "#5");
			Assert.IsNull (s.ExternalNameScope, "#6");
			Assert.IsFalse (s.IgnoreCanConvert, "#7");
			Assert.IsFalse (s.PreferUnconvertedDictionaryKeys, "#8");
			Assert.IsFalse (s.RegisterNamesOnExternalNamescope, "#9");
			Assert.IsNull (s.RootObjectInstance, "#10");
			Assert.IsFalse (s.SkipDuplicatePropertyCheck, "#11");
			Assert.IsFalse (s.SkipProvideValueOnRoot, "#12");
			Assert.IsNull (s.XamlSetValueHandler, "#13");
		}
コード例 #10
0
        public void DefaultValues()
        {
            var s = new XamlObjectWriterSettings();

            Assert.IsNull(s.AccessLevel, "#1");
            Assert.IsNull(s.AfterBeginInitHandler, "#2");
            Assert.IsNull(s.AfterEndInitHandler, "#3");
            Assert.IsNull(s.AfterPropertiesHandler, "#4");
            Assert.IsNull(s.BeforePropertiesHandler, "#5");
            Assert.IsNull(s.ExternalNameScope, "#6");
            Assert.IsFalse(s.IgnoreCanConvert, "#7");
            Assert.IsFalse(s.PreferUnconvertedDictionaryKeys, "#8");
            Assert.IsFalse(s.RegisterNamesOnExternalNamescope, "#9");
            Assert.IsNull(s.RootObjectInstance, "#10");
            Assert.IsFalse(s.SkipDuplicatePropertyCheck, "#11");
            Assert.IsFalse(s.SkipProvideValueOnRoot, "#12");
            Assert.IsNull(s.XamlSetValueHandler, "#13");
        }
コード例 #11
0
        public static AvaloniaXamlObjectWriter Create(
            XamlSchemaContext schemaContext,
            AvaloniaXamlContext context,
            IAmbientProvider parentAmbientProvider = null)
        {
            var nameScope = new AvaloniaNameScope { Instance = context?.RootInstance };

            var writerSettings = new XamlObjectWriterSettings()
            {
                ExternalNameScope = nameScope,
                RegisterNamesOnExternalNamescope = true,
                RootObjectInstance = context?.RootInstance
            };

            return new AvaloniaXamlObjectWriter(schemaContext,
                writerSettings.WithContext(context),
                nameScope,
                parentAmbientProvider);
        }
コード例 #12
0
		public void RootObjectInstance ()
		{
			// bug #689548
			var obj = new RootObjectInstanceTestClass ();
			RootObjectInstanceTestClass result;
			
			var rsettings = new XamlXmlReaderSettings ();
			
			var xml = String.Format (@"<RootObjectInstanceTestClass Property=""Test"" xmlns=""clr-namespace:MonoTests.Portable.Xaml;assembly={0}""></RootObjectInstanceTestClass>", GetType ().Assembly.GetName ().Name);
			using (var reader = new XamlXmlReader (new StringReader (xml), rsettings)) {
				var wsettings = new XamlObjectWriterSettings ();
				wsettings.RootObjectInstance = obj;
				using (var writer = new XamlObjectWriter (reader.SchemaContext, wsettings)) {
					XamlServices.Transform (reader, writer, false);
					result = (RootObjectInstanceTestClass) writer.Result;
				}
			}
			
			Assert.AreEqual (obj, result, "#1");
			Assert.AreEqual ("Test", obj.Property, "#2");
		}
コード例 #13
0
        public ObjectWriterContext(XamlSavedContext savedContext, XamlObjectWriterSettings settings, INameScope rootNameScope, XamlRuntime runtime) : base(savedContext.SchemaContext)
        {
            INameScopeDictionary dictionary;

            this._stack = new XamlContextStack <ObjectWriterFrame>(savedContext.Stack, false);
            if (settings != null)
            {
                this._settings = settings.StripDelegates();
            }
            this._runtime = runtime;
            this.BaseUri  = savedContext.BaseUri;
            switch (savedContext.SaveContextType)
            {
            case SavedContextType.Template:
                dictionary = null;
                if (rootNameScope != null)
                {
                    dictionary = rootNameScope as INameScopeDictionary;
                    if (dictionary == null)
                    {
                        dictionary = new NameScopeDictionary(rootNameScope);
                    }
                    break;
                }
                dictionary = new NameScope();
                break;

            case SavedContextType.ReparseValue:
            case SavedContextType.ReparseMarkupExtension:
                this._savedDepth = this._stack.Depth - 1;
                return;

            default:
                return;
            }
            this._stack.PushScope();
            this._savedDepth = this._stack.Depth;
            this._stack.CurrentFrame.NameScopeDictionary = dictionary;
            this._stack.PushScope();
        }
コード例 #14
0
        public void RootObjectInstance()
        {
            // bug #689548
            var obj = new RootObjectInstanceTestClass();
            RootObjectInstanceTestClass result;

            var rsettings = new XamlXmlReaderSettings();

            var xml = String.Format(@"<RootObjectInstanceTestClass Property=""Test"" xmlns=""clr-namespace:MonoTests.Uno.Xaml;assembly={0}""></RootObjectInstanceTestClass>", GetType().Assembly.GetName().Name);

            using (var reader = new XamlXmlReader(new StringReader(xml), rsettings)) {
                var wsettings = new XamlObjectWriterSettings();
                wsettings.RootObjectInstance = obj;
                using (var writer = new XamlObjectWriter(reader.SchemaContext, wsettings)) {
                    XamlServices.Transform(reader, writer, false);
                    result = (RootObjectInstanceTestClass)writer.Result;
                }
            }

            Assert.AreEqual(obj, result, "#1");
            Assert.AreEqual("Test", obj.Property, "#2");
        }
コード例 #15
0
        public static void InitializeFromStream(Activity a, Assembly localAssembly, Stream xamlStream,
                                                XamlSchemaContext schemaContext)
        {
            XmlReader        xmlReader    = null;
            XamlReader       reader       = null;
            XamlObjectWriter objectWriter = null;

            try
            {
                xmlReader = XmlReader.Create(xamlStream);

                XamlXmlReaderSettings readerSettings = new XamlXmlReaderSettings();
                readerSettings.LocalAssembly = localAssembly;
                readerSettings.AllowProtectedMembersOnRoot = true;
                reader = new XamlXmlReader(xmlReader, schemaContext, readerSettings);

                XamlObjectWriterSettings writerSettings = new XamlObjectWriterSettings();
                writerSettings.RootObjectInstance = a;
                writerSettings.AccessLevel        = XamlAccessLevel.PrivateAccessTo(a.GetType());
                objectWriter = new XamlObjectWriter(schemaContext, writerSettings);

                XamlServices.Transform(reader, objectWriter);
            }
            finally
            {
                if (xmlReader != null)
                {
                    ((IDisposable)xmlReader).Dispose();
                }
                if (reader != null)
                {
                    ((IDisposable)reader).Dispose();
                }
                if (objectWriter != null)
                {
                    ((IDisposable)objectWriter).Dispose();
                }
            }
        }
コード例 #16
0
ファイル: XamlReader.cs プロジェクト: CheckTech/Eto
        /// <summary>
        /// Loads the specified type from the specified xaml stream
        /// </summary>
        /// <typeparam name="T">Type of object to load from the specified xaml</typeparam>
        /// <param name="stream">Xaml content to load (e.g. from resources)</param>
        /// <param name="instance">Instance to use as the starting object</param>
        /// <returns>A new or existing instance of the specified type with the contents loaded from the xaml stream</returns>
        public static T Load <T>(Stream stream, T instance)
            where T : Widget
        {
            var type           = typeof(T);
            var context        = new EtoXamlSchemaContext(new Assembly[] { typeof(XamlReader).Assembly });
            var reader         = new XamlXmlReader(stream, context);
            var writerSettings = new XamlObjectWriterSettings
            {
                RootObjectInstance = instance
            };

            writerSettings.AfterPropertiesHandler += delegate(object sender, XamlObjectEventArgs e)
            {
                var obj = e.Instance as Widget;
                if (obj != null && !string.IsNullOrEmpty(obj.ID))
                {
                    var property = type.GetProperty(obj.ID, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                    if (property != null)
                    {
                        property.SetValue(instance, obj, null);
                    }
                    else
                    {
                        var field = type.GetField(obj.ID, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);
                        if (field != null)
                        {
                            field.SetValue(instance, obj);
                        }
                    }
                }
            };

            var writer = new XamlObjectWriter(context, writerSettings);

            XamlServices.Transform(reader, writer);
            return(writer.Result as T);
        }
コード例 #17
0
ファイル: DynamicXamlReader.cs プロジェクト: kerwon/dlr
        /// <summary>
        /// Loads XAML from the specified XamlXmlReader and returns the deserialized object.  Any event handlers
        /// are bound to methods defined in the provided Scope and converted using the provided DynamicOperations
        /// object.
        /// </summary>
        public static object LoadComponent(dynamic scope, DynamicOperations operations, XamlXmlReader reader)
        {
            var settings = new XamlObjectWriterSettings();

            settings.RootObjectInstance = scope;

            var myWriter = new DynamicWriter((object)scope, operations, reader.SchemaContext, settings);

            while (reader.Read())
            {
                myWriter.WriteNode(reader);
            }

            foreach (string name in myWriter.Names)
            {
                object value = myWriter.RootNameScope.FindName(name);
                if (value != null)
                {
                    operations.SetMember((object)scope, name, value);
                }
            }

            return(myWriter.Result);
        }
コード例 #18
0
        public override object StandardXamlLoader(string xamlString)
        {
            eventHandled = false;
            var          xamlXmlReader = new XamlXmlReader(XmlReader.Create(new StringReader(xamlString)));
            XamlNodeList xamlNodeList  = new XamlNodeList(xamlXmlReader.SchemaContext);

            XamlServices.Transform(xamlXmlReader, xamlNodeList.Writer);

            XamlReader reader = xamlNodeList.GetReader();
            XamlObjectWriterSettings settings = new XamlObjectWriterSettings()
            {
                RootObjectInstance = null, AfterBeginInitHandler = ObjectCreated
            };
            XamlObjectWriter objWriter = new XamlObjectWriter(reader.SchemaContext, settings);

            XamlServices.Transform(reader, objWriter);
            object root = objWriter.Result;

            if (root == null)
            {
                throw new NullReferenceException("Load returned null Root");
            }
            return(root);
        }
コード例 #19
0
        private static object Load(System.Xaml.XamlReader xamlReader, IXamlObjectWriterFactory writerFactory,
                                   bool skipJournaledProperties, Object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
        {
            XamlObjectWriter xamlWriter           = null;
            XamlContextStack <WpfXamlFrame> stack = new XamlContextStack <WpfXamlFrame>(() => new WpfXamlFrame());
            int persistId = 1;

            settings.AfterBeginInitHandler = delegate(object sender, System.Xaml.XamlObjectEventArgs args)
            {
                if (EventTrace.IsEnabled(EventTrace.Keyword.KeywordXamlBaml | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose))
                {
                    IXamlLineInfo ixli = xamlReader as IXamlLineInfo;

                    int lineNumber   = -1;
                    int linePosition = -1;

                    if (ixli != null && ixli.HasLineInfo)
                    {
                        lineNumber   = ixli.LineNumber;
                        linePosition = ixli.LinePosition;
                    }

                    EventTrace.EventProvider.TraceEvent(
                        EventTrace.Event.WClientParseXamlBamlInfo,
                        EventTrace.Keyword.KeywordXamlBaml | EventTrace.Keyword.KeywordPerf, EventTrace.Level.Verbose,
                        args.Instance == null ? 0 : PerfService.GetPerfElementID(args.Instance),
                        lineNumber,
                        linePosition);
                }

                UIElement uiElement = args.Instance as UIElement;
                if (uiElement != null)
                {
                    uiElement.SetPersistId(persistId++);
                }

                XamlSourceInfoHelper.SetXamlSourceInfo(args.Instance, args, baseUri);

                DependencyObject dObject = args.Instance as DependencyObject;
                if (dObject != null && stack.CurrentFrame.XmlnsDictionary != null)
                {
                    XmlnsDictionary dictionary = stack.CurrentFrame.XmlnsDictionary;
                    dictionary.Seal();

                    XmlAttributeProperties.SetXmlnsDictionary(dObject, dictionary);
                }

                stack.CurrentFrame.Instance = args.Instance;
            };
            if (writerFactory != null)
            {
                xamlWriter = writerFactory.GetXamlObjectWriter(settings);
            }
            else
            {
                xamlWriter = new System.Xaml.XamlObjectWriter(xamlReader.SchemaContext, settings);
            }

            IXamlLineInfo xamlLineInfo = null;

            try
            {
                //Handle Line Numbers
                xamlLineInfo = xamlReader as IXamlLineInfo;
                IXamlLineInfoConsumer xamlLineInfoConsumer = xamlWriter as IXamlLineInfoConsumer;
                bool shouldPassLineNumberInfo = false;
                if ((xamlLineInfo != null && xamlLineInfo.HasLineInfo) &&
                    (xamlLineInfoConsumer != null && xamlLineInfoConsumer.ShouldProvideLineInfo))
                {
                    shouldPassLineNumberInfo = true;
                }

                IStyleConnector styleConnector = rootObject as IStyleConnector;
                TransformNodes(xamlReader, xamlWriter,
                               false /*onlyLoadOneNode*/,
                               skipJournaledProperties,
                               shouldPassLineNumberInfo, xamlLineInfo, xamlLineInfoConsumer,
                               stack, styleConnector);
                xamlWriter.Close();
                return(xamlWriter.Result);
            }
            catch (Exception e)
            {
                // Don't wrap critical exceptions or already-wrapped exceptions.
                if (MS.Internal.CriticalExceptions.IsCriticalException(e) || !XamlReader.ShouldReWrapException(e, baseUri))
                {
                    throw;
                }
                XamlReader.RewrapException(e, xamlLineInfo, baseUri);
                return(null);    // this should never be executed
            }
        }
コード例 #20
0
        public static object LoadDeferredContent(System.Xaml.XamlReader xamlReader, IXamlObjectWriterFactory writerFactory,
                                                 bool skipJournaledProperties, Object rootObject, XamlObjectWriterSettings parentSettings, Uri baseUri)
        {
            XamlObjectWriterSettings settings = XamlReader.CreateObjectWriterSettings(parentSettings);

            // Don't set settings.RootObject because this isn't the real root
            return(Load(xamlReader, writerFactory, skipJournaledProperties, rootObject, settings, baseUri));
        }
コード例 #21
0
ファイル: DynamicXamlReader.cs プロジェクト: kerwon/dlr
 public DynamicWriter(object scope, DynamicOperations operations, XamlSchemaContext context, XamlObjectWriterSettings settings)
     : base(context, settings)
 {
     _scope      = scope;
     _operations = operations;
 }
コード例 #22
0
 public static XamlObjectWriterSettings WithContext(this XamlObjectWriterSettings settings, AvaloniaXamlContext context)
 {
     return(new AvaloniaXamlObjectWriterSettings(settings, context));
 }
コード例 #23
0
 public XamlObjectWriter GetXamlObjectWriter(XamlObjectWriterSettings settings)
 {
     return(new XamlObjectWriter(_savedContext, settings));
 }
コード例 #24
0
 XamlObjectWriter IXamlObjectWriterFactory.GetXamlObjectWriter(XamlObjectWriterSettings settings)
 {
     throw new NotImplementedException();
 }
コード例 #25
0
 public AvaloniaXamlObjectWriterSettings(XamlObjectWriterSettings settings, AvaloniaXamlContext context)
     : base(settings)
 {
     Context = context;
 }
コード例 #26
0
        // Token: 0x0600226A RID: 8810 RVA: 0x000AAE10 File Offset: 0x000A9010
        private static object Load(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, bool skipJournaledProperties, object rootObject, XamlObjectWriterSettings settings, Uri baseUri)
        {
            XamlContextStack <WpfXamlFrame> stack = new XamlContextStack <WpfXamlFrame>(() => new WpfXamlFrame());
            int persistId = 1;

            settings.AfterBeginInitHandler = delegate(object sender, XamlObjectEventArgs args)
            {
                if (EventTrace.IsEnabled(EventTrace.Keyword.KeywordPerf | EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose))
                {
                    IXamlLineInfo xamlLineInfo2 = xamlReader as IXamlLineInfo;
                    int           num           = -1;
                    int           num2          = -1;
                    if (xamlLineInfo2 != null && xamlLineInfo2.HasLineInfo)
                    {
                        num  = xamlLineInfo2.LineNumber;
                        num2 = xamlLineInfo2.LinePosition;
                    }
                    EventTrace.EventProvider.TraceEvent(EventTrace.Event.WClientParseXamlBamlInfo, EventTrace.Keyword.KeywordPerf | EventTrace.Keyword.KeywordXamlBaml, EventTrace.Level.Verbose, new object[]
                    {
                        (args.Instance == null) ? 0L : PerfService.GetPerfElementID(args.Instance),
                        num,
                        num2
                    });
                }
                UIElement uielement = args.Instance as UIElement;
                if (uielement != null)
                {
                    UIElement uielement2 = uielement;
                    int       persistId  = persistId;
                    persistId++;
                    uielement2.SetPersistId(persistId);
                }
                XamlSourceInfoHelper.SetXamlSourceInfo(args.Instance, args, baseUri);
                DependencyObject dependencyObject = args.Instance as DependencyObject;
                if (dependencyObject != null && stack.CurrentFrame.XmlnsDictionary != null)
                {
                    XmlnsDictionary xmlnsDictionary = stack.CurrentFrame.XmlnsDictionary;
                    xmlnsDictionary.Seal();
                    XmlAttributeProperties.SetXmlnsDictionary(dependencyObject, xmlnsDictionary);
                }
                stack.CurrentFrame.Instance = args.Instance;
            };
            XamlObjectWriter xamlObjectWriter;

            if (writerFactory != null)
            {
                xamlObjectWriter = writerFactory.GetXamlObjectWriter(settings);
            }
            else
            {
                xamlObjectWriter = new XamlObjectWriter(xamlReader.SchemaContext, settings);
            }
            IXamlLineInfo xamlLineInfo = null;
            object        result;

            try
            {
                xamlLineInfo = (xamlReader as IXamlLineInfo);
                IXamlLineInfoConsumer xamlLineInfoConsumer = xamlObjectWriter;
                bool shouldPassLineNumberInfo = false;
                if (xamlLineInfo != null && xamlLineInfo.HasLineInfo && xamlLineInfoConsumer != null && xamlLineInfoConsumer.ShouldProvideLineInfo)
                {
                    shouldPassLineNumberInfo = true;
                }
                IStyleConnector styleConnector = rootObject as IStyleConnector;
                WpfXamlLoader.TransformNodes(xamlReader, xamlObjectWriter, false, skipJournaledProperties, shouldPassLineNumberInfo, xamlLineInfo, xamlLineInfoConsumer, stack, styleConnector);
                xamlObjectWriter.Close();
                result = xamlObjectWriter.Result;
            }
            catch (Exception ex)
            {
                if (CriticalExceptions.IsCriticalException(ex) || !XamlReader.ShouldReWrapException(ex, baseUri))
                {
                    throw;
                }
                XamlReader.RewrapException(ex, xamlLineInfo, baseUri);
                result = null;
            }
            return(result);
        }
コード例 #27
0
        /// <summary>
        /// Gets a <see cref="FrameworkTemplate"/> based on the specified parameters.
        /// </summary>
        /// <param name="xmlElement">The xml element to get template xaml from.</param>
        /// <param name="parentObject">The <see cref="XamlObject"/> to use as source for resources and contextual information.</param>
        /// <returns>A <see cref="FrameworkTemplate"/> based on the specified parameters.</returns>
        public static FrameworkTemplate GetFrameworkTemplate(XmlElement xmlElement, XamlObject parentObject)
        {
            var nav = xmlElement.CreateNavigator();

            var ns = new Dictionary <string, string>();

            while (true)
            {
                var nsInScope = nav.GetNamespacesInScope(XmlNamespaceScope.ExcludeXml);
                foreach (var ak in nsInScope)
                {
                    if (!ns.ContainsKey(ak.Key) && ak.Key != "")
                    {
                        ns.Add(ak.Key, ak.Value);
                    }
                }
                if (!nav.MoveToParent())
                {
                    break;
                }
            }

            xmlElement = (XmlElement)xmlElement.CloneNode(true);

            foreach (var dictentry in ns.ToList())
            {
                xmlElement.SetAttribute("xmlns:" + dictentry.Key, dictentry.Value);
            }

            var keyAttrib = xmlElement.GetAttribute("Key", XamlConstants.XamlNamespace);

            if (string.IsNullOrEmpty(keyAttrib))
            {
                xmlElement.SetAttribute("Key", XamlConstants.XamlNamespace, "$$temp&&§§%%__");
            }

            var xaml = xmlElement.OuterXml;

            xaml = "<ResourceDictionary xmlns=\"http://schemas.microsoft.com/netfx/2007/xaml/presentation\" xmlns:x=\"http://schemas.microsoft.com/winfx/2006/xaml\">" + xaml + "</ResourceDictionary>";
            StringReader stringReader = new StringReader(xaml);
            XmlReader    xmlReader    = XmlReader.Create(stringReader);
            var          xamlReader   = new XamlXmlReader(xmlReader, parentObject.ServiceProvider.SchemaContext);

            var seti = new XamlObjectWriterSettings();

            var resourceDictionary = new ResourceDictionary();
            var obj = parentObject;

            while (obj != null)
            {
                if (obj.Instance is ResourceDictionary)
                {
                    var r = obj.Instance as ResourceDictionary;
                    foreach (var k in r.Keys)
                    {
                        if (!resourceDictionary.Contains(k))
                        {
                            resourceDictionary.Add(k, r[k]);
                        }
                    }
                }
                else if (obj.Instance is FrameworkElement)
                {
                    var r = ((FrameworkElement)obj.Instance).Resources;
                    foreach (var k in r.Keys)
                    {
                        if (!resourceDictionary.Contains(k))
                        {
                            resourceDictionary.Add(k, r[k]);
                        }
                    }
                }

                obj = obj.ParentObject;
            }

            seti.BeforePropertiesHandler = (s, e) =>
            {
                if (seti.BeforePropertiesHandler != null)
                {
                    var rr = e.Instance as ResourceDictionary;
                    rr.MergedDictionaries.Add(resourceDictionary);
                    seti.BeforePropertiesHandler = null;
                }
            };

            var writer = new XamlObjectWriter(parentObject.ServiceProvider.SchemaContext, seti);

            XamlServices.Transform(xamlReader, writer);

            var result = (ResourceDictionary)writer.Result;

            var enr = result.Keys.GetEnumerator();

            enr.MoveNext();
            var rdKey = enr.Current;

            var template = result[rdKey] as FrameworkTemplate;

            result.Remove(rdKey);
            return(template);
        }
コード例 #28
0
        // Token: 0x0600238A RID: 9098 RVA: 0x000AD808 File Offset: 0x000ABA08
        private object LoadAsync(XmlReader reader, ParserContext parserContext)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }
            if (parserContext == null)
            {
                parserContext = new ParserContext();
            }
            this._xmlReader = reader;
            object rootObject = null;

            if (parserContext.BaseUri == null || string.IsNullOrEmpty(parserContext.BaseUri.ToString()))
            {
                if (reader.BaseURI == null || string.IsNullOrEmpty(reader.BaseURI.ToString()))
                {
                    parserContext.BaseUri = BaseUriHelper.PackAppBaseUri;
                }
                else
                {
                    parserContext.BaseUri = new Uri(reader.BaseURI);
                }
            }
            this._baseUri = parserContext.BaseUri;
            XamlXmlReaderSettings xamlXmlReaderSettings = new XamlXmlReaderSettings();

            xamlXmlReaderSettings.IgnoreUidsOnPropertyElements = true;
            xamlXmlReaderSettings.BaseUri         = parserContext.BaseUri;
            xamlXmlReaderSettings.ProvideLineInfo = true;
            XamlSchemaContext schemaContext = (parserContext.XamlTypeMapper != null) ? parserContext.XamlTypeMapper.SchemaContext : XamlReader.GetWpfSchemaContext();

            try
            {
                this._textReader = new XamlXmlReader(reader, schemaContext, xamlXmlReaderSettings);
                this._stack      = new XamlContextStack <WpfXamlFrame>(() => new WpfXamlFrame());
                XamlObjectWriterSettings xamlObjectWriterSettings = XamlReader.CreateObjectWriterSettings();
                xamlObjectWriterSettings.AfterBeginInitHandler = delegate(object sender, XamlObjectEventArgs args)
                {
                    if (rootObject == null)
                    {
                        rootObject           = args.Instance;
                        this._styleConnector = (rootObject as IStyleConnector);
                    }
                    UIElement uielement = args.Instance as UIElement;
                    if (uielement != null)
                    {
                        UIElement uielement2 = uielement;
                        XamlReader < > 4__this = this;
                        int persistId = this._persistId;
                        < > 4__this._persistId = persistId + 1;
                        uielement2.SetPersistId(persistId);
                    }
                    DependencyObject dependencyObject = args.Instance as DependencyObject;
                    if (dependencyObject != null && this._stack.CurrentFrame.XmlnsDictionary != null)
                    {
                        XmlnsDictionary xmlnsDictionary = this._stack.CurrentFrame.XmlnsDictionary;
                        xmlnsDictionary.Seal();
                        XmlAttributeProperties.SetXmlnsDictionary(dependencyObject, xmlnsDictionary);
                    }
                };
コード例 #29
0
 public XamlObjectWriter GetXamlObjectWriter(XamlObjectWriterSettings settings)
 {
     return(new XamlObjectWriter(sctx, settings));
 }
コード例 #30
0
 public XamlObjectWriterFactory(ObjectWriterContext context)
 {
     _savedContext   = context.GetSavedContext(SavedContextType.Template);
     _parentSettings = context.ServiceProvider_GetSettings();
 }
コード例 #31
0
 public XamlObjectWriter(XamlSchemaContext schemaContext, XamlObjectWriterSettings settings)
     : this(schemaContext, settings, null)
 {
 }
コード例 #32
0
        // Token: 0x06002267 RID: 8807 RVA: 0x000AAD70 File Offset: 0x000A8F70
        public static object LoadDeferredContent(XamlReader xamlReader, IXamlObjectWriterFactory writerFactory, bool skipJournaledProperties, object rootObject, XamlObjectWriterSettings parentSettings, Uri baseUri)
        {
            XamlObjectWriterSettings settings = XamlReader.CreateObjectWriterSettings(parentSettings);

            return(WpfXamlLoader.Load(xamlReader, writerFactory, skipJournaledProperties, rootObject, settings, baseUri));
        }