// This method is a workaround for TFS bug #788190, since XamlReader.ReadSubtree() should (but doesn't) preserve IXamlLineInfo on the subreader
        public static void Transform(XamlReader reader, XamlWriter writer, IXamlLineInfo readerLineInfo, bool closeWriter)
        {
            IXamlLineInfoConsumer consumer = writer as IXamlLineInfoConsumer;
            SharedFx.Assert(consumer != null && consumer.ShouldProvideLineInfo, "Should only call this function to write into a XamlNodeQueue.Writer, which is always IXamlLineInfoConsumer");
            bool shouldPassLineNumberInfo = false;
            if (readerLineInfo != null)
            {
                shouldPassLineNumberInfo = true;
            }

            while (reader.Read())
            {
                if (shouldPassLineNumberInfo)
                {
                    consumer.SetLineInfo(readerLineInfo.LineNumber, readerLineInfo.LinePosition);
                }

                writer.WriteNode(reader);
            }

            if (closeWriter)
            {
                writer.Close();
            }
        }
 public DynamicActivityXamlReader(bool isBuilder, XamlReader innerReader, XamlSchemaContext schemaContext)
 {
     this.isBuilder = isBuilder;
     this.innerReader = innerReader;
     this.schemaContext = schemaContext ?? innerReader.SchemaContext;
     this.xamlTypeXamlType = this.schemaContext.GetXamlType(typeof(XamlType));
     this.typeXamlType = this.schemaContext.GetXamlType(typeof(System.Type));
     this.baseActivityXamlType = this.schemaContext.GetXamlType(typeof(Activity));
     this.activityPropertyXamlType = this.schemaContext.GetXamlType(typeof(DynamicActivityProperty));
     this.activityPropertyType = this.activityPropertyXamlType.GetMember("Type");
     this.activityPropertyName = this.activityPropertyXamlType.GetMember("Name");
     this.activityPropertyValue = this.activityPropertyXamlType.GetMember("Value");
     this.activityPropertyAttributes = this.activityPropertyXamlType.GetMember("Attributes");
     this.namespaceTable = new NamespaceTable();
     this.frontLoadedDirectives = true;
     this.nodeQueue = new XamlNodeQueue(this.schemaContext);
     this.nodeReader = this.nodeQueue.Reader;
     IXamlLineInfo info = innerReader as IXamlLineInfo;
     if ((info != null) && info.HasLineInfo)
     {
         this.innerReaderLineInfo = info;
         this.nodeReaderLineInfo = (IXamlLineInfo) this.nodeQueue.Reader;
         this.hasLineInfo = true;
     }
 }
 public static void PropagateLineInfo(XamlWriter targetWriter, IXamlLineInfo lineInfo)
 {
     if (lineInfo != null)
     {
         (targetWriter as IXamlLineInfoConsumer).SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition);
     }
 }
 private static XamlException CreateXamlException(string message, IXamlLineInfo lineInfo)
 {
     if ((lineInfo != null) && lineInfo.HasLineInfo)
     {
         return new XamlException(message, null, lineInfo.LineNumber, lineInfo.LinePosition);
     }
     return new XamlException(message);
 }
 public XamlSubreader(XamlReader reader)
 {
     this._reader = reader;
     this._lineInfoReader = reader as IXamlLineInfo;
     this._done = false;
     this._depth = 0;
     this._firstRead = true;
     this._rootIsStartMember = reader.NodeType == XamlNodeType.StartMember;
 }
 public static void PropagateLineInfo(XamlWriter targetWriter, IXamlLineInfo lineInfo)
 {
     if (lineInfo != null)
     {
         IXamlLineInfoConsumer consumer = targetWriter as IXamlLineInfoConsumer;            
         Fx.Assert(consumer != null && consumer.ShouldProvideLineInfo, "Should only call this function to write into a XamlNodeQueue.Writer, which is always IXamlLineInfoConsumer");
         consumer.SetLineInfo(lineInfo.LineNumber, lineInfo.LinePosition);                
     }
 }
 internal XamlDebuggerXmlReader(TextReader underlyingTextReader, XamlSchemaContext schemaContext, Assembly localAssembly)
 {
     UnitTestUtility.Assert(underlyingTextReader != null, "underlyingTextReader should not be null and is ensured by caller.");
     this.xmlReaderWithSourceLocation = new XmlReaderWithSourceLocation(underlyingTextReader);
     this.underlyingReader = new XamlXmlReader(this.xmlReaderWithSourceLocation, schemaContext, new XamlXmlReaderSettings { ProvideLineInfo = true, LocalAssembly = localAssembly });
     this.xamlLineInfo = (IXamlLineInfo)this.underlyingReader;
     UnitTestUtility.Assert(this.xamlLineInfo.HasLineInfo, "underlyingReader is constructed with the ProvideLineInfo option above.");
     this.schemaContext = schemaContext;
     this.objectDeclarationRecords = new Stack<XamlNode>();
     this.initializationValueRanges = new Dictionary<XamlNode, DocumentRange>();
     this.bufferedXamlNodes = new Queue<XamlNode>();
     this.current = this.CreateCurrentNode();
     this.SourceLocationFound += XamlDebuggerXmlReader.SetSourceLocation;
 }
 public static void Transform(XamlReader reader, XamlWriter writer, IXamlLineInfo readerLineInfo, bool closeWriter)
 {
     IXamlLineInfoConsumer consumer = writer as IXamlLineInfoConsumer;
     bool flag = false;
     if (readerLineInfo != null)
     {
         flag = true;
     }
     while (reader.Read())
     {
         if (flag)
         {
             consumer.SetLineInfo(readerLineInfo.LineNumber, readerLineInfo.LinePosition);
         }
         writer.WriteNode(reader);
     }
     if (closeWriter)
     {
         writer.Close();
     }
 }
 void WriteSerializedPropertyReference(XamlWriter targetWriter, IXamlLineInfo lineInfo, string targetName, string sourceName)
 {
     // Line Info for the entire <ActivityPropertyReference> element 
     // comes from the end of the <PropertyReference> tag
     targetWriter.WriteStartObject(this.activityPropertyReferenceXamlType, lineInfo);
     targetWriter.WriteStartMember(this.activityPropertyReferenceTargetProperty, lineInfo);
     targetWriter.WriteValue(targetName, lineInfo);
     targetWriter.WriteEndMember(lineInfo);
     if (sourceName != null)
     {
         targetWriter.WriteStartMember(this.activityPropertyReferenceSourceProperty, lineInfo);
         targetWriter.WriteValue(sourceName, lineInfo);
         targetWriter.WriteEndMember(lineInfo);
     }
     targetWriter.WriteEndObject(lineInfo);
 }
示例#10
0
        private object LoadAsync(XmlReader reader, ParserContext parserContext)
        {
            if (reader == null)
            {
                throw new ArgumentNullException("reader");
            }

            if (parserContext == null)
            {
                parserContext = new ParserContext();
            }

            _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);
                }
            }
            _baseUri = parserContext.BaseUri;
            System.Xaml.XamlXmlReaderSettings settings = new System.Xaml.XamlXmlReaderSettings();
            settings.IgnoreUidsOnPropertyElements = true;
            settings.BaseUri         = parserContext.BaseUri;
            settings.ProvideLineInfo = true;
            XamlSchemaContext schemaContext = parserContext.XamlTypeMapper != null ?
                                              parserContext.XamlTypeMapper.SchemaContext : GetWpfSchemaContext();

            try
            {
                _textReader = new System.Xaml.XamlXmlReader(reader, schemaContext, settings);

                _stack = new XamlContextStack <WpfXamlFrame>(() => new WpfXamlFrame());

                System.Xaml.XamlObjectWriterSettings objectSettings = XamlReader.CreateObjectWriterSettings();
                objectSettings.AfterBeginInitHandler = delegate(object sender, System.Xaml.XamlObjectEventArgs args)
                {
                    if (rootObject == null)
                    {
                        rootObject      = args.Instance;
                        _styleConnector = rootObject as IStyleConnector;
                    }

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

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

                        XmlAttributeProperties.SetXmlnsDictionary(dObject, dictionary);
                    }
                };

                _objectWriter            = new System.Xaml.XamlObjectWriter(_textReader.SchemaContext, objectSettings);
                _parseCancelled          = false;
                _skipJournaledProperties = parserContext.SkipJournaledProperties;

                XamlMember synchronousModeProperty   = _textReader.SchemaContext.GetXamlDirective("http://schemas.microsoft.com/winfx/2006/xaml", "SynchronousMode");
                XamlMember synchronousRecordProperty = _textReader.SchemaContext.GetXamlDirective("http://schemas.microsoft.com/winfx/2006/xaml", "AsyncRecords");

                System.Xaml.XamlReader xamlReader = _textReader;

                IXamlLineInfo         xamlLineInfo         = xamlReader as IXamlLineInfo;
                IXamlLineInfoConsumer xamlLineInfoConsumer = _objectWriter as IXamlLineInfoConsumer;
                bool shouldPassLineNumberInfo = false;
                if ((xamlLineInfo != null && xamlLineInfo.HasLineInfo) &&
                    (xamlLineInfoConsumer != null && xamlLineInfoConsumer.ShouldProvideLineInfo))
                {
                    shouldPassLineNumberInfo = true;
                }

                bool async = false;
                bool lastPropWasSyncMode    = false;
                bool lastPropWasSyncRecords = false;

                while (!_textReader.IsEof)
                {
                    WpfXamlLoader.TransformNodes(xamlReader, _objectWriter, true /*onlyLoadOneNode*/, _skipJournaledProperties, shouldPassLineNumberInfo, xamlLineInfo, xamlLineInfoConsumer, _stack, _styleConnector);

                    if (xamlReader.NodeType == System.Xaml.XamlNodeType.StartMember)
                    {
                        if (xamlReader.Member == synchronousModeProperty)
                        {
                            lastPropWasSyncMode = true;
                        }
                        else if (xamlReader.Member == synchronousRecordProperty)
                        {
                            lastPropWasSyncRecords = true;
                        }
                    }
                    else if (xamlReader.NodeType == System.Xaml.XamlNodeType.Value)
                    {
                        if (lastPropWasSyncMode == true)
                        {
                            if (xamlReader.Value as String == "Async")
                            {
                                async = true;
                            }
                        }
                        else if (lastPropWasSyncRecords == true)
                        {
                            if (xamlReader.Value is int)
                            {
                                _maxAsynxRecords = (int)xamlReader.Value;
                            }
                            else if (xamlReader.Value is String)
                            {
                                _maxAsynxRecords = Int32.Parse(xamlReader.Value as String, TypeConverterHelper.InvariantEnglishUS);
                            }
                        }
                    }
                    else if (xamlReader.NodeType == System.Xaml.XamlNodeType.EndMember)
                    {
                        lastPropWasSyncMode    = false;
                        lastPropWasSyncRecords = false;
                    }

                    if (async && rootObject != null)
                    {
                        break;
                    }
                }
            }
            catch (Exception e)
            {
                // Don't wrap critical exceptions or already-wrapped exceptions.
                if (MS.Internal.CriticalExceptions.IsCriticalException(e) || !ShouldReWrapException(e, parserContext.BaseUri))
                {
                    throw;
                }
                RewrapException(e, parserContext.BaseUri);
            }

            if (!_textReader.IsEof)
            {
                Post();
                //ThreadStart threadStart = new ThreadStart(ReadXamlAsync);
                //Thread thread = new Thread(threadStart);
                //thread.Start();
            }
            else
            {
                TreeBuildComplete();
            }

            if (rootObject is DependencyObject)
            {
                if (parserContext.BaseUri != null && !String.IsNullOrEmpty(parserContext.BaseUri.ToString()))
                {
                    (rootObject as DependencyObject).SetValue(BaseUriHelper.BaseUriProperty, parserContext.BaseUri);
                }
                //else
                //    (rootObject as DependencyObject).SetValue(BaseUriHelper.BaseUriProperty, BaseUriHelper.PackAppBaseUri);
                WpfXamlLoader.EnsureXmlNamespaceMaps(rootObject, schemaContext);
            }

            Application app = rootObject as Application;

            if (app != null)
            {
                app.ApplicationMarkupBaseUri = GetBaseUri(settings.BaseUri);
            }

            return(rootObject);
        }
示例#11
0
        /// <summary>
        /// called when in async mode when get a time slice to read and load the Tree
        /// </summary>
        internal virtual void HandleAsyncQueueItem()
        {
            try
            {
                int startTickCount = MS.Win32.SafeNativeMethods.GetTickCount();
                //bool moreData = true;

                // for debugging, can set the Maximum Async records to
                // read via markup
                // x:AsyncRecords="3" would loop three times
                int maxRecords = _maxAsynxRecords;

                System.Xaml.XamlReader xamlReader = _textReader;

                IXamlLineInfo         xamlLineInfo         = xamlReader as IXamlLineInfo;
                IXamlLineInfoConsumer xamlLineInfoConsumer = _objectWriter as IXamlLineInfoConsumer;
                bool shouldPassLineNumberInfo = false;
                if ((xamlLineInfo != null && xamlLineInfo.HasLineInfo) &&
                    (xamlLineInfoConsumer != null && xamlLineInfoConsumer.ShouldProvideLineInfo))
                {
                    shouldPassLineNumberInfo = true;
                }

                XamlMember synchronousRecordProperty = _textReader.SchemaContext.GetXamlDirective(XamlLanguage.Xaml2006Namespace, "AsyncRecords");

                while (!xamlReader.IsEof && !_parseCancelled)
                {
                    WpfXamlLoader.TransformNodes(xamlReader, _objectWriter, true /*onlyLoadOneNode*/, _skipJournaledProperties, shouldPassLineNumberInfo, xamlLineInfo, xamlLineInfoConsumer, _stack, _styleConnector);

                    if (xamlReader.NodeType == System.Xaml.XamlNodeType.Value && _stack.CurrentFrame.Property == synchronousRecordProperty)
                    {
                        if (xamlReader.Value is int)
                        {
                            _maxAsynxRecords = (int)xamlReader.Value;
                        }
                        else if (xamlReader.Value is String)
                        {
                            _maxAsynxRecords = Int32.Parse(xamlReader.Value as String, TypeConverterHelper.InvariantEnglishUS);
                        }
                        maxRecords = _maxAsynxRecords;
                    }

                    //Debug.Assert (1 >= RootList.Count, "Multiple roots not supported in async mode");

                    // check the timeout
                    int elapsed = MS.Win32.SafeNativeMethods.GetTickCount() - startTickCount;

                    // check for rollover
                    if (elapsed < 0)
                    {
                        startTickCount = 0; // reset to 0,
                    }
                    else if (elapsed > AsyncLoopTimeout)
                    {
                        break;
                    }

                    // decrement and compare with zero so the unitialized -1  and zero case
                    // doesn't break the loop.
                    if (--maxRecords == 0)
                    {
                        break;
                    }
                }
            }
            catch (XamlParseException e)
            {
                _parseException = e;
            }
            catch (Exception e)
            {
                if (CriticalExceptions.IsCriticalException(e) || !XamlReader.ShouldReWrapException(e, _baseUri))
                {
                    _parseException = e;
                }
                else
                {
                    _parseException = XamlReader.WrapException(e, null, _baseUri);
                }
            }
            finally
            {
                if (_parseException != null || _parseCancelled)
                {
                    TreeBuildComplete();
                }
                else
                {
                    // if not at the EndOfDocument then post another work item
                    if (false == _textReader.IsEof)
                    {
                        Post();
                    }
                    else
                    {
                        // Building of the Tree is complete.
                        TreeBuildComplete();
                    }
                }
            }
        }
 public static void WriteValue(this XamlWriter writer, object value, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteValue(value);
 }
        private static XamlNode CreateCurrentNode(XamlReader xamlReader, IXamlLineInfo xamlLineInfo)
        {
            XamlNode currentNode = new XamlNode
            {
                Namespace = xamlReader.Namespace,
                NodeType = xamlReader.NodeType,
                Type = xamlReader.Type,
                Member = xamlReader.Member,
                Value = xamlReader.Value,
                LineNumber = xamlLineInfo.LineNumber,
                LinePosition = xamlLineInfo.LinePosition,
            };

            return currentNode;
        }
示例#14
0
 public static void WriteStartObject(this XamlWriter writer, XamlType type, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteStartObject(type);
 }
示例#15
0
 public static void WriteGetObject(this XamlWriter writer, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteGetObject();
 }
示例#16
0
 internal static void RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri) 
 {
     throw WrapException(e, lineInfo, baseUri);
 }
示例#17
0
 internal static XamlParseException WrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
 { 
     Exception baseException = (e.InnerException == null) ? e : e.InnerException; 
     if (baseException is System.Windows.Markup.XamlParseException)
     { 
         var xe = ((System.Windows.Markup.XamlParseException)baseException);
         xe.BaseUri = xe.BaseUri ?? baseUri;
         if (lineInfo != null && xe.LinePosition == 0 && xe.LineNumber == 0)
         { 
             xe.LinePosition = lineInfo.LinePosition;
             xe.LineNumber = lineInfo.LineNumber; 
         } 
         return xe;
     } 
     if (e is System.Xaml.XamlException)
     {
         System.Xaml.XamlException xe = (System.Xaml.XamlException)e;
         return new XamlParseException(xe.Message, xe.LineNumber, xe.LinePosition, baseUri, baseException); 
     }
     else if (e is XmlException) 
     { 
         XmlException xe = (XmlException)e;
         return new XamlParseException(xe.Message, xe.LineNumber, xe.LinePosition, baseUri, baseException); 
     }
     else
     {
         if (lineInfo != null) 
         {
             return new XamlParseException(e.Message, lineInfo.LineNumber, lineInfo.LinePosition, baseUri, baseException); 
         } 
         else
         { 
             return new XamlParseException(e.Message, baseException);
         }
     }
 } 
 private void DisableRewrite()
 {
     this.notRewriting = true;
     this.nodeReader = this.innerReader;
     this.nodeReaderLineInfo = this.innerReader as IXamlLineInfo;
 }
 public void BufferDefaultValue(string propertyName, XamlMember propertyValue, XamlReader reader, IXamlLineInfo lineInfo)
 {
     if (this.alreadyBufferedDefinitions)
     {
         this.ProcessDefaultValue(propertyName, propertyValue, reader.ReadSubtree(), lineInfo);
     }
     else
     {
         if (this.valueHolders == null)
         {
             this.valueHolders = new Dictionary<string, ValueHolder>();
         }
         ValueHolder holder = new ValueHolder(this.parent.SchemaContext, propertyValue, reader, lineInfo);
         this.valueHolders[propertyName] = holder;
     }
 }
 public bool ProcessNode(XamlReader reader, XamlWriter targetWriter, int currentDepth, IXamlLineInfo readerLineInfo)
 {
     if ((currentDepth == this.Depth) && ((reader.NodeType == XamlNodeType.NamespaceDeclaration) || (reader.NodeType == XamlNodeType.None)))
     {
         this.bufferedNodes.Writer.WriteNode(reader, readerLineInfo);
         reader.Read();
         return true;
     }
     if ((((reader.NodeType == XamlNodeType.StartObject) && reader.Type.IsGeneric) && ((reader.Type.UnderlyingType != null) && (reader.Type.Name == "PropertyReferenceExtension"))) && (reader.Type.UnderlyingType.GetGenericTypeDefinition() == typeof(PropertyReferenceExtension<>)))
     {
         if (this.bufferedNodes.Count > 0)
         {
             XamlServices.Transform(this.bufferedNodes.Reader, targetWriter, false);
             this.bufferedNodes = null;
         }
         XamlType type = reader.Type;
         XamlReader reader2 = reader.ReadSubtree();
         XamlType xamlType = reader.SchemaContext.GetXamlType(typeof(ActivityBuilder));
         XamlType type3 = reader.SchemaContext.GetXamlType(typeof(ActivityPropertyReference));
         targetWriter.WriteStartMember(xamlType.GetAttachableMember("PropertyReference"), readerLineInfo);
         reader2.Read();
         targetWriter.WriteStartObject(type3, readerLineInfo);
         targetWriter.WriteStartMember(type3.GetMember("TargetProperty"), readerLineInfo);
         targetWriter.WriteValue(this.currentMember.Name, readerLineInfo);
         targetWriter.WriteEndMember(readerLineInfo);
         bool flag = reader2.Read();
         bool flag2 = false;
         while (flag)
         {
             if (((reader2.NodeType == XamlNodeType.StartMember) && (reader2.Member.DeclaringType == type)) && (reader2.Member.Name == "PropertyName"))
             {
                 flag2 = true;
             }
             else if (flag2)
             {
                 if (reader2.NodeType == XamlNodeType.EndMember)
                 {
                     flag2 = false;
                 }
                 else if (reader2.NodeType == XamlNodeType.Value)
                 {
                     targetWriter.WriteStartMember(type3.GetMember("SourceProperty"), readerLineInfo);
                     targetWriter.WriteValue((string) reader2.Value, readerLineInfo);
                     targetWriter.WriteEndMember(readerLineInfo);
                 }
             }
             flag = reader2.Read();
         }
         targetWriter.WriteEndObject(readerLineInfo);
         targetWriter.WriteEndMember(readerLineInfo);
         this.ExitObject = true;
         reader2.Close();
     }
     else
     {
         this.FlushBuffer(targetWriter);
         targetWriter.WriteNode(reader, readerLineInfo);
     }
     return false;
 }
 public ValueHolder(XamlSchemaContext schemaContext, XamlMember propertyValue, XamlReader reader, IXamlLineInfo lineInfo)
 {
     this.nodes = new XamlNodeQueue(schemaContext);
     this.PropertyValue = propertyValue;
     XamlWriterExtensions.Transform(reader.ReadSubtree(), this.nodes.Writer, lineInfo, true);
 }
 public void ProcessDefaultValue(string propertyName, XamlMember propertyValue, XamlReader reader, IXamlLineInfo lineInfo)
 {
     ActivityPropertyHolder holder;
     if (!this.PropertyHolders.TryGetValue(propertyName, out holder))
     {
         throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.InvalidProperty(propertyName), lineInfo));
     }
     holder.ProcessDefaultValue(propertyValue, reader, lineInfo);
 }
示例#23
0
 public XamlNullExtensionNode(IXamlLineInfo lineInfo) : base(lineInfo)
 {
     Type = new XamlAstClrTypeReference(lineInfo, XamlPseudoType.Null, false);
 }
示例#24
0
 public XamlTransformException(string message, IXamlLineInfo lineInfo) : base(message, lineInfo)
 {
 }
示例#25
0
        public static bool ParseConstantIfTypeAllows(string s, IXamlType type, IXamlLineInfo info, out XamlConstantNode rv)
        {
            rv = null;
            if (type.Namespace != "System")
            {
                return(false);
            }

            object Parse()
            {
                if (type.Name == "Byte")
                {
                    return(byte.Parse(s, CultureInfo.InvariantCulture));
                }
                if (type.Name == "SByte")
                {
                    return(sbyte.Parse(s, CultureInfo.InvariantCulture));
                }
                if (type.Name == "Int16")
                {
                    return(Int16.Parse(s, CultureInfo.InvariantCulture));
                }
                if (type.Name == "UInt16")
                {
                    return(UInt16.Parse(s, CultureInfo.InvariantCulture));
                }
                if (type.Name == "Int32")
                {
                    return(Int32.Parse(s, CultureInfo.InvariantCulture));
                }
                if (type.Name == "UInt32")
                {
                    return(UInt32.Parse(s, CultureInfo.InvariantCulture));
                }
                if (type.Name == "Int64")
                {
                    return(Int64.Parse(s, CultureInfo.InvariantCulture));
                }
                if (type.Name == "UInt64")
                {
                    return(UInt64.Parse(s, CultureInfo.InvariantCulture));
                }
                if (type.Name == "Single")
                {
                    return(Single.Parse(s, CultureInfo.InvariantCulture));
                }
                if (type.Name == "Double")
                {
                    return(Double.Parse(s, CultureInfo.InvariantCulture));
                }
                if (type.Name == "Boolean")
                {
                    return(Boolean.Parse(s));
                }
                return(null);
            }

            var r = Parse();

            if (r != null)
            {
                rv = new XamlConstantNode(info, type, r);
                return(true);
            }

            return(false);
        }
示例#26
0
 public XamlLoadException(string message, IXamlLineInfo lineInfo) : base(message, lineInfo)
 {
 }
示例#27
0
 public static void WriteNode(this XamlWriter writer, XamlReader reader, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteNode(reader);
 }
        // For dynamic activity property, we needs to collect the source location of
        // its default value when the value is inlined.
        private KeyValuePair <string, SourceLocation> TransformDynamicActivityProperty(
            XamlReader reader,
            XamlObjectWriter objectWriter,
            SourceTextScanner sourceTextScanner)
        {
            // (Number of SM -Number of EM) since SM DAP.Name is read.
            // SO DAP                   ---nameReadingLevel=0
            //   SM NAME                ---nameReadingLevel=1
            //     SO String            ---nameReadingLevel=1
            //       SM Initialize      ---nameReadingLevel=2
            //         VA StringValue   ---nameReadingLevel=2
            //       EM                 ---nameReadingLevel=1
            //     SO                   ---nameReadingLevel=1
            //   EM                     ---nameReadingLevel=0
            // EO                       ---nameReadingLevel=0
            int nameReadingLevel = 0;

            IXamlLineInfo  lineInfo             = (IXamlLineInfo)reader;
            SourceLocation defaultValueLocation = null;
            string         propertyName         = null;

            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                case XamlNodeType.StartMember:
                    if (nameReadingLevel > 0 ||
                        reader.Member == this.dynamicActivityPropertyNameMember)
                    {
                        ++nameReadingLevel;
                    }
                    else if (reader.Member == this.dynamicActivityPropertyValueMember)
                    {
                        LineColumnPair startPoint = new LineColumnPair(lineInfo.LineNumber, lineInfo.LinePosition);
                        defaultValueLocation = GetInlineAttributeValueLocation(startPoint, sourceTextScanner);
                    }

                    break;

                case XamlNodeType.EndMember:
                    if (nameReadingLevel > 0)
                    {
                        --nameReadingLevel;
                    }

                    break;

                case XamlNodeType.Value:
                    if (nameReadingLevel > 0)
                    {
                        propertyName = reader.Value as string;
                    }

                    break;
                }

                objectWriter.WriteNode(reader);
            }

            if (propertyName != null && defaultValueLocation != null)
            {
                return(new KeyValuePair <string, SourceLocation>(propertyName, defaultValueLocation));
            }

            return(new KeyValuePair <string, SourceLocation>());
        }
示例#29
0
 public static void WriteStartMember(this XamlWriter writer, XamlMember xamlMember, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteStartMember(xamlMember);
 }
示例#30
0
 public XamlValidatingReader(XamlReader reader, IXamlLineInfo xamlLineInfo)
 {
     this.reader       = reader;
     this.xamlLineInfo = xamlLineInfo;
     this.nodes        = new Stack <System.Activities.Debugger.XamlNode>();
 }
 public void ProcessDefaultValue(XamlMember propertyValue, XamlReader subReader, IXamlLineInfo lineInfo)
 {
     XamlReader reader;
     bool flag = false;
     subReader.Read();
     if (!subReader.Member.IsNameValid)
     {
         throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.InvalidXamlMember(subReader.Member.Name), lineInfo));
     }
     this.nodes.Writer.WriteStartMember(propertyValue, lineInfo);
     subReader.Read();
     if (subReader.NodeType == XamlNodeType.GetObject)
     {
         subReader.Read();
         subReader.Read();
         reader = subReader.ReadSubtree();
         reader.Read();
     }
     else
     {
         reader = subReader;
     }
     if ((reader.NodeType != XamlNodeType.EndMember) && (reader.NodeType != XamlNodeType.StartObject))
     {
         flag = true;
         this.nodes.Writer.WriteStartObject(this.Type, lineInfo);
         this.nodes.Writer.WriteStartMember(XamlLanguage.Initialization, lineInfo);
     }
     while (!reader.IsEof)
     {
         this.nodes.Writer.WriteNode(reader, lineInfo);
         reader.Read();
     }
     reader.Close();
     if (!object.ReferenceEquals(reader, subReader))
     {
         subReader.Read();
         while (subReader.Read())
         {
             this.nodes.Writer.WriteNode(subReader, lineInfo);
         }
     }
     if (flag)
     {
         this.nodes.Writer.WriteEndObject(lineInfo);
         this.nodes.Writer.WriteEndMember(lineInfo);
     }
     subReader.Close();
 }
示例#32
0
        internal static void TransformNodes(System.Xaml.XamlReader xamlReader, System.Xaml.XamlObjectWriter xamlWriter,
                                            bool onlyLoadOneNode,
                                            bool skipJournaledProperties,
                                            bool shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer,
                                            XamlContextStack <WpfXamlFrame> stack,
                                            IStyleConnector styleConnector)
        {
            while (xamlReader.Read())
            {
                if (shouldPassLineNumberInfo)
                {
                    if (xamlLineInfo.LineNumber != 0)
                    {
                        xamlLineInfoConsumer.SetLineInfo(xamlLineInfo.LineNumber, xamlLineInfo.LinePosition);
                    }
                }

                switch (xamlReader.NodeType)
                {
                case System.Xaml.XamlNodeType.NamespaceDeclaration:
                    xamlWriter.WriteNode(xamlReader);
                    if (stack.Depth == 0 || stack.CurrentFrame.Type != null)
                    {
                        stack.PushScope();
                        // Need to create an XmlnsDictionary.
                        // Look up stack to see if we have one earlier
                        //  If so, use that.  Otherwise new a xmlnsDictionary
                        WpfXamlFrame iteratorFrame = stack.CurrentFrame;
                        while (iteratorFrame != null)
                        {
                            if (iteratorFrame.XmlnsDictionary != null)
                            {
                                stack.CurrentFrame.XmlnsDictionary =
                                    new XmlnsDictionary(iteratorFrame.XmlnsDictionary);
                                break;
                            }
                            iteratorFrame = (WpfXamlFrame)iteratorFrame.Previous;
                        }
                        if (stack.CurrentFrame.XmlnsDictionary == null)
                        {
                            stack.CurrentFrame.XmlnsDictionary =
                                new XmlnsDictionary();
                        }
                    }
                    stack.CurrentFrame.XmlnsDictionary.Add(xamlReader.Namespace.Prefix, xamlReader.Namespace.Namespace);
                    break;

                case System.Xaml.XamlNodeType.StartObject:
                    xamlWriter.WriteNode(xamlReader);
                    // If there's a frame but no Type, that means there
                    // was a namespace. Just set the Type
                    if (stack.Depth != 0 && stack.CurrentFrame.Type == null)
                    {
                        stack.CurrentFrame.Type = xamlReader.Type;
                    }
                    else
                    {
                        // Propagate the FreezeFreezable property from the current stack frame
                        stack.PushScope();
                        stack.CurrentFrame.Type = xamlReader.Type;
                        if (stack.PreviousFrame.FreezeFreezable)
                        {
                            stack.CurrentFrame.FreezeFreezable = true;
                        }
                    }
                    break;

                case System.Xaml.XamlNodeType.GetObject:
                    xamlWriter.WriteNode(xamlReader);
                    // If there wasn't a namespace node before this get object, need to pushScope.
                    if (stack.CurrentFrame.Type != null)
                    {
                        stack.PushScope();
                    }
                    stack.CurrentFrame.Type = stack.PreviousFrame.Property.Type;
                    break;

                case System.Xaml.XamlNodeType.EndObject:
                    xamlWriter.WriteNode(xamlReader);
                    // Freeze if required
                    if (stack.CurrentFrame.FreezeFreezable)
                    {
                        Freezable freezable = xamlWriter.Result as Freezable;
                        if (freezable != null && freezable.CanFreeze)
                        {
                            freezable.Freeze();
                        }
                    }
                    DependencyObject dependencyObject = xamlWriter.Result as DependencyObject;
                    if (dependencyObject != null && stack.CurrentFrame.XmlSpace.HasValue)
                    {
                        XmlAttributeProperties.SetXmlSpace(dependencyObject, stack.CurrentFrame.XmlSpace.Value ? "default" : "preserve");
                    }
                    stack.PopScope();
                    break;

                case System.Xaml.XamlNodeType.StartMember:
                    // ObjectWriter should NOT process PresentationOptions:Freeze directive since it is Unknown
                    // The space directive node stream should not be written because it induces object instantiation,
                    // and the Baml2006Reader can produce space directives prematurely.
                    if (!(xamlReader.Member.IsDirective && xamlReader.Member == XamlReaderHelper.Freeze) &&
                        xamlReader.Member != XmlSpace.Value &&
                        xamlReader.Member != XamlLanguage.Space)
                    {
                        xamlWriter.WriteNode(xamlReader);
                    }

                    stack.CurrentFrame.Property = xamlReader.Member;
                    if (skipJournaledProperties)
                    {
                        if (!stack.CurrentFrame.Property.IsDirective)
                        {
                            System.Windows.Baml2006.WpfXamlMember wpfMember = stack.CurrentFrame.Property as System.Windows.Baml2006.WpfXamlMember;
                            if (wpfMember != null)
                            {
                                DependencyProperty prop = wpfMember.DependencyProperty;

                                if (prop != null)
                                {
                                    FrameworkPropertyMetadata metadata = prop.GetMetadata(stack.CurrentFrame.Type.UnderlyingType) as FrameworkPropertyMetadata;
                                    if (metadata != null && metadata.Journal == true)
                                    {
                                        //
                                        int count = 1;
                                        while (xamlReader.Read())
                                        {
                                            switch (xamlReader.NodeType)
                                            {
                                            case System.Xaml.XamlNodeType.StartMember:
                                                count++;
                                                break;

                                            case System.Xaml.XamlNodeType.EndMember:
                                                count--;
                                                if (count == 0)
                                                {
                                                    xamlWriter.WriteNode(xamlReader);
                                                }
                                                break;
                                            }
                                            if (count == 0)
                                            {
                                                break;
                                            }
                                        }
                                        // shouldn't this have been a XamlReader.Skip()?
                                        System.Diagnostics.Debug.Assert(count == 0, "Mismatch StartMember/EndMember");
                                    }
                                }
                            }
                        }
                    }
                    break;

                case System.Xaml.XamlNodeType.EndMember:
                    WpfXamlFrame currentFrame    = stack.CurrentFrame;
                    XamlMember   currentProperty = currentFrame.Property;
                    // ObjectWriter should not process PresentationOptions:Freeze directive nodes since it is unknown
                    // The space directive node stream should not be written because it induces object instantiation,
                    // and the Baml2006Reader can produce space directives prematurely.
                    if (!(currentProperty.IsDirective && currentProperty == XamlReaderHelper.Freeze) &&
                        currentProperty != XmlSpace.Value &&
                        currentProperty != XamlLanguage.Space)
                    {
                        xamlWriter.WriteNode(xamlReader);
                    }
                    currentFrame.Property = null;
                    break;

                case System.Xaml.XamlNodeType.Value:
                    if (stack.CurrentFrame.Property.IsDirective && stack.CurrentFrame.Property == XamlLanguage.Shared)
                    {
                        bool isShared;
                        if (bool.TryParse(xamlReader.Value as string, out isShared))
                        {
                            if (!isShared)
                            {
                                if (!(xamlReader is Baml2006Reader))
                                {
                                    throw new XamlParseException(SR.Get(SRID.SharedAttributeInLooseXaml));
                                }
                            }
                        }
                    }
                    // ObjectWriter should not process PresentationOptions:Freeze directive nodes since it is unknown
                    if (stack.CurrentFrame.Property.IsDirective && stack.CurrentFrame.Property == XamlReaderHelper.Freeze)
                    {
                        bool freeze = Convert.ToBoolean(xamlReader.Value, TypeConverterHelper.InvariantEnglishUS);
                        stack.CurrentFrame.FreezeFreezable = freeze;
                        var bamlReader = xamlReader as System.Windows.Baml2006.Baml2006Reader;
                        if (bamlReader != null)
                        {
                            bamlReader.FreezeFreezables = freeze;
                        }
                    }
                    // The space directive node stream should not be written because it induces object instantiation,
                    // and the Baml2006Reader can produce space directives prematurely.
                    else if (stack.CurrentFrame.Property == XmlSpace.Value || stack.CurrentFrame.Property == XamlLanguage.Space)
                    {
                        if (typeof(DependencyObject).IsAssignableFrom(stack.CurrentFrame.Type.UnderlyingType))
                        {
                            System.Diagnostics.Debug.Assert(xamlReader.Value is string, "XmlAttributeProperties.XmlSpaceProperty has the type string.");
                            stack.CurrentFrame.XmlSpace = (string)xamlReader.Value == "default";
                        }
                    }
                    else
                    {
                        // Ideally we should check if we're inside FrameworkTemplate's Content and not register those.
                        // However, checking if the instance is null accomplishes the same with a much smaller perf impact.
                        if (styleConnector != null &&
                            stack.CurrentFrame.Instance != null &&
                            stack.CurrentFrame.Property == XamlLanguage.ConnectionId &&
                            typeof(Style).IsAssignableFrom(stack.CurrentFrame.Type.UnderlyingType))
                        {
                            styleConnector.Connect((int)xamlReader.Value, stack.CurrentFrame.Instance);
                        }

                        xamlWriter.WriteNode(xamlReader);
                    }
                    break;

                default:
                    xamlWriter.WriteNode(xamlReader);
                    break;
                }

                //Only do this loop for one node if loadAsync
                if (onlyLoadOneNode)
                {
                    return;
                }
            }
        }
 public MemberInformation(XamlMember member, IXamlLineInfo lineInfo)
     : this()
 {
     Member = member;
     if (lineInfo != null)
     {
         LineNumber = lineInfo.LineNumber;
         LinePosition = lineInfo.LinePosition;
     }
 }
示例#34
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++);
                }

                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
            }
        }
示例#35
0
 internal static void RewrapException(Exception e, IXamlLineInfo lineInfo, Uri baseUri)
 {
     throw WrapException(e, lineInfo, baseUri);
 }
 public void BufferDefaultValue(string propertyName, XamlMember propertyValue, XamlReader reader, IXamlLineInfo lineInfo)
 {
     if (this.alreadyBufferedDefinitions)
     {
         this.ProcessDefaultValue(propertyName, propertyValue, reader.ReadSubtree(), lineInfo);
     }
     else
     {
         if (this.valueHolders == null)
         {
             this.valueHolders = new Dictionary <string, ValueHolder>();
         }
         ValueHolder holder = new ValueHolder(this.parent.SchemaContext, propertyValue, reader, lineInfo);
         this.valueHolders[propertyName] = holder;
     }
 }
示例#37
0
        private static XamlIlBindingPathNode TransformBindingPath(AstTransformationContext context, IXamlLineInfo lineInfo, Func <IXamlType> startTypeResolver, IXamlType selfType, IEnumerable <BindingExpressionGrammar.INode> bindingExpression)
        {
            List <IXamlIlBindingPathElementNode> transformNodes = new List <IXamlIlBindingPathElementNode>();
            List <IXamlIlBindingPathElementNode> nodes          = new List <IXamlIlBindingPathElementNode>();

            foreach (var astNode in bindingExpression)
            {
                var targetTypeResolver = nodes.Count == 0 ? startTypeResolver : () => nodes[nodes.Count - 1].Type;
                switch (astNode)
                {
                case BindingExpressionGrammar.EmptyExpressionNode _:
                    break;

                case BindingExpressionGrammar.NotNode _:
                    transformNodes.Add(new XamlIlNotPathElementNode(context.Configuration.WellKnownTypes.Boolean));
                    break;

                case BindingExpressionGrammar.StreamNode _:
                {
                    IXamlType targetType = targetTypeResolver();
                    IXamlType observableType;
                    if (targetType.GenericTypeDefinition?.Equals(context.Configuration.TypeSystem.FindType("System.IObservable`1")) == true)
                    {
                        observableType = targetType;
                    }
                    else
                    {
                        observableType = targetType.GetAllInterfaces().FirstOrDefault(i => i.GenericTypeDefinition?.Equals(context.Configuration.TypeSystem.FindType("System.IObservable`1")) ?? false);
                    }

                    if (observableType != null)
                    {
                        nodes.Add(new XamlIlStreamObservablePathElementNode(observableType.GenericArguments[0]));
                        break;
                    }
                    bool foundTask = false;
                    for (var currentType = targetType; currentType != null; currentType = currentType.BaseType)
                    {
                        if (currentType.GenericTypeDefinition.Equals(context.Configuration.TypeSystem.GetType("System.Threading.Tasks.Task`1")))
                        {
                            foundTask = true;
                            nodes.Add(new XamlIlStreamTaskPathElementNode(currentType.GenericArguments[0]));
                            break;
                        }
                    }
                    if (foundTask)
                    {
                        break;
                    }
                    throw new XamlX.XamlParseException($"Compiled bindings do not support stream bindings for objects of type {targetType.FullName}.", lineInfo);
                }

                case BindingExpressionGrammar.PropertyNameNode propName:
                {
                    IXamlType targetType = targetTypeResolver();
                    var       avaloniaPropertyFieldNameMaybe = propName.PropertyName + "Property";
                    var       avaloniaPropertyFieldMaybe     = targetType.GetAllFields().FirstOrDefault(f =>
                                                                                                        f.IsStatic && f.IsPublic && f.Name == avaloniaPropertyFieldNameMaybe);

                    if (avaloniaPropertyFieldMaybe != null)
                    {
                        nodes.Add(new XamlIlAvaloniaPropertyPropertyPathElementNode(avaloniaPropertyFieldMaybe,
                                                                                    XamlIlAvaloniaPropertyHelper.GetAvaloniaPropertyType(avaloniaPropertyFieldMaybe, context.GetAvaloniaTypes(), lineInfo)));
                    }
                    else if (GetAllDefinedProperties(targetType).FirstOrDefault(p => p.Name == propName.PropertyName) is IXamlProperty clrProperty)
                    {
                        nodes.Add(new XamlIlClrPropertyPathElementNode(clrProperty));
                    }
                    else if (GetAllDefinedMethods(targetType).FirstOrDefault(m => m.Name == propName.PropertyName) is IXamlMethod method)
                    {
                        nodes.Add(new XamlIlClrMethodPathElementNode(method, context.Configuration.WellKnownTypes.Delegate));
                    }
                    else
                    {
                        throw new XamlX.XamlParseException($"Unable to resolve property or method of name '{propName.PropertyName}' on type '{targetType}'.", lineInfo);
                    }
                    break;
                }

                case BindingExpressionGrammar.IndexerNode indexer:
                {
                    IXamlType targetType = targetTypeResolver();
                    if (targetType.IsArray)
                    {
                        nodes.Add(new XamlIlArrayIndexerPathElementNode(targetType, indexer.Arguments, lineInfo));
                        break;
                    }

                    IXamlProperty property = null;
                    foreach (var currentType in TraverseTypeHierarchy(targetType))
                    {
                        var defaultMemberAttribute = currentType.CustomAttributes.FirstOrDefault(x => x.Type.Namespace == "System.Reflection" && x.Type.Name == "DefaultMemberAttribute");
                        if (defaultMemberAttribute != null)
                        {
                            property = currentType.GetAllProperties().FirstOrDefault(x => x.Name == (string)defaultMemberAttribute.Parameters[0]);
                            break;
                        }
                    }
                    if (property is null)
                    {
                        throw new XamlX.XamlParseException($"The type '${targetType}' does not have an indexer.", lineInfo);
                    }

                    IEnumerable <IXamlType> parameters = property.IndexerParameters;

                    List <IXamlAstValueNode> values = new List <IXamlAstValueNode>();
                    int currentParamIndex           = 0;
                    foreach (var param in parameters)
                    {
                        var textNode = new XamlAstTextNode(lineInfo, indexer.Arguments[currentParamIndex], type: context.Configuration.WellKnownTypes.String);
                        if (!XamlTransformHelpers.TryGetCorrectlyTypedValue(context, textNode,
                                                                            param, out var converted))
                        {
                            throw new XamlX.XamlParseException(
                                      $"Unable to convert indexer parameter value of '{indexer.Arguments[currentParamIndex]}' to {param.GetFqn()}",
                                      textNode);
                        }

                        values.Add(converted);
                        currentParamIndex++;
                    }

                    bool isNotifyingCollection = targetType.GetAllInterfaces().Any(i => i.FullName == "System.Collections.Specialized.INotifyCollectionChanged");

                    nodes.Add(new XamlIlClrIndexerPathElementNode(property, values, string.Join(",", indexer.Arguments), isNotifyingCollection));
                    break;
                }

                case BindingExpressionGrammar.AttachedPropertyNameNode attachedProp:
                    var avaloniaPropertyFieldName = attachedProp.PropertyName + "Property";
                    var avaloniaPropertyField     = GetType(attachedProp.Namespace, attachedProp.TypeName).GetAllFields().FirstOrDefault(f =>
                                                                                                                                         f.IsStatic && f.IsPublic && f.Name == avaloniaPropertyFieldName);
                    nodes.Add(new XamlIlAvaloniaPropertyPropertyPathElementNode(avaloniaPropertyField,
                                                                                XamlIlAvaloniaPropertyHelper.GetAvaloniaPropertyType(avaloniaPropertyField, context.GetAvaloniaTypes(), lineInfo)));
                    break;

                case BindingExpressionGrammar.SelfNode _:
                    nodes.Add(new SelfPathElementNode(selfType));
                    break;

                case VisualAncestorBindingExpressionNode visualAncestor:
                    nodes.Add(new FindVisualAncestorPathElementNode(visualAncestor.Type, visualAncestor.Level));
                    break;

                case TemplatedParentBindingExpressionNode templatedParent:
                    var templatedParentField = context.GetAvaloniaTypes().StyledElement.GetAllFields()
                                               .FirstOrDefault(f => f.IsStatic && f.IsPublic && f.Name == "TemplatedParentProperty");
                    nodes.Add(new XamlIlAvaloniaPropertyPropertyPathElementNode(
                                  templatedParentField,
                                  templatedParent.Type));
                    break;

                case BindingExpressionGrammar.AncestorNode ancestor:
                    if (ancestor.Namespace is null && ancestor.TypeName is null)
                    {
                        var styledElementType = context.GetAvaloniaTypes().StyledElement;
                        var ancestorType      = context
                                                .ParentNodes()
                                                .OfType <XamlAstConstructableObjectNode>()
                                                .Where(x => styledElementType.IsAssignableFrom(x.Type.GetClrType()))
                                                .Skip(1)
                                                .ElementAtOrDefault(ancestor.Level)
                                                ?.Type.GetClrType();

                        if (ancestorType is null)
                        {
                            throw new XamlX.XamlParseException("Unable to resolve implicit ancestor type based on XAML tree.", lineInfo);
                        }

                        nodes.Add(new FindAncestorPathElementNode(ancestorType, ancestor.Level));
                    }
                    else
                    {
                        nodes.Add(new FindAncestorPathElementNode(GetType(ancestor.Namespace, ancestor.TypeName), ancestor.Level));
                    }
                    break;
            public void ProcessDefaultValue(string propertyName, XamlMember propertyValue, XamlReader reader, IXamlLineInfo lineInfo)
            {
                ActivityPropertyHolder holder;

                if (!this.PropertyHolders.TryGetValue(propertyName, out holder))
                {
                    throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.InvalidProperty(propertyName), lineInfo));
                }
                holder.ProcessDefaultValue(propertyValue, reader, lineInfo);
            }
示例#39
0
 public ParsedBindingPathNode(IXamlLineInfo lineInfo, IXamlType compiledBindingType, IList <BindingExpressionGrammar.INode> path)
     : base(lineInfo)
 {
     Type = new XamlAstClrTypeReference(lineInfo, compiledBindingType, false);
     Path = path;
 }
                public ActivityPropertyHolder(DynamicActivityXamlReader parent, XamlReader reader)
                {
                    this.parent = parent;
                    this.nodes  = new XamlNodeQueue(parent.SchemaContext);
                    IXamlLineInfo innerReaderLineInfo = parent.innerReaderLineInfo;

                    reader.Read();
                    this.nodes.Writer.WriteStartObject(parent.activityPropertyXamlType, innerReaderLineInfo);
                    int  num  = 1;
                    int  a    = 0;
                    int  num3 = 0;
                    bool flag = reader.Read();

                    while (flag)
                    {
                        XamlMember activityPropertyName;
                        switch (reader.NodeType)
                        {
                        case XamlNodeType.StartObject:
                        case XamlNodeType.GetObject:
                        {
                            num++;
                            DynamicActivityXamlReader.IncrementIfPositive(ref a);
                            DynamicActivityXamlReader.IncrementIfPositive(ref num3);
                            if ((num3 <= 0) || !(reader.Type == parent.xamlTypeXamlType))
                            {
                                goto Label_0231;
                            }
                            this.nodes.Writer.WriteStartObject(parent.typeXamlType, innerReaderLineInfo);
                            flag = reader.Read();
                            continue;
                        }

                        case XamlNodeType.EndObject:
                        {
                            num--;
                            if (num != 0)
                            {
                                goto Label_0213;
                            }
                            flag = reader.Read();
                            continue;
                        }

                        case XamlNodeType.StartMember:
                            if (!(reader.Member.DeclaringType == XamlLanguage.Property))
                            {
                                goto Label_0231;
                            }
                            activityPropertyName = reader.Member;
                            if (!(activityPropertyName == DynamicActivityXamlReader.xPropertyName))
                            {
                                break;
                            }
                            activityPropertyName = parent.activityPropertyName;
                            if (a == 0)
                            {
                                a = 1;
                            }
                            goto Label_0115;

                        case XamlNodeType.EndMember:
                            DynamicActivityXamlReader.DecrementIfPositive(ref a);
                            DynamicActivityXamlReader.DecrementIfPositive(ref num3);
                            goto Label_0231;

                        case XamlNodeType.Value:
                            if (a != 1)
                            {
                                goto Label_014F;
                            }
                            this.Name = reader.Value as string;
                            goto Label_0231;

                        default:
                            goto Label_0231;
                        }
                        if (activityPropertyName == DynamicActivityXamlReader.xPropertyType)
                        {
                            activityPropertyName = parent.activityPropertyType;
                            if (num3 == 0)
                            {
                                num3 = 1;
                            }
                        }
                        else
                        {
                            if (activityPropertyName != DynamicActivityXamlReader.xPropertyAttributes)
                            {
                                throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.PropertyMemberNotSupportedByActivityXamlServices(activityPropertyName.Name), innerReaderLineInfo));
                            }
                            activityPropertyName = parent.activityPropertyAttributes;
                        }
Label_0115:
                        this.nodes.Writer.WriteStartMember(activityPropertyName, innerReaderLineInfo);
                        flag = reader.Read();
                        continue;
Label_014F:
                        if (num3 == 1)
                        {
                            XamlTypeName xamlTypeName = XamlTypeName.Parse(reader.Value as string, parent.namespaceTable);
                            XamlType     xamlType     = parent.SchemaContext.GetXamlType(xamlTypeName);
                            if (xamlType == null)
                            {
                                throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.InvalidPropertyType(reader.Value as string, this.Name), innerReaderLineInfo));
                            }
                            this.Type = xamlType;
                        }
                        goto Label_0231;
Label_0213:
                        DynamicActivityXamlReader.DecrementIfPositive(ref a);
                        DynamicActivityXamlReader.DecrementIfPositive(ref num3);
Label_0231:
                        this.nodes.Writer.WriteNode(reader, innerReaderLineInfo);
                        flag = reader.Read();
                    }
                    reader.Close();
                }
示例#41
0
 public XamlIntermediateRootObjectNode(IXamlLineInfo lineInfo, XamlTypeWellKnownTypes types) : base(lineInfo)
 {
     Type = new XamlAstClrTypeReference(lineInfo, types.Object, false);
 }
 public void CopyTo(XamlNodeQueue targetNodeQueue, IXamlLineInfo readerInfo)
 {
     XamlServices.Transform(this.nodes.Reader, targetNodeQueue.Writer, false);
     targetNodeQueue.Writer.WriteEndObject(readerInfo);
 }
示例#43
0
 public static XamlConstantNode GetLiteralFieldConstantNode(IXamlField field, IXamlLineInfo info)
 => new XamlConstantNode(info, field.FieldType, GetLiteralFieldConstantValue(field));
 public static void WriteNode(this XamlWriter writer, XamlReader reader, IXamlLineInfo lineInfo) 
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteNode(reader);
 }
示例#45
0
 public static void WriteValue(this XamlWriter writer, object value, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteValue(value);
 }
 public static void WriteGetObject(this XamlWriter writer, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteGetObject();
 }
示例#47
0
 public static void WriteEndMember(this XamlWriter writer, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteEndMember();
 }
 public static void WriteStartMember(this XamlWriter writer, XamlMember xamlMember, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteStartMember(xamlMember);
 }
示例#49
0
 public static void WriteNamespace(this XamlWriter writer, NamespaceDeclaration namespaceDeclaration, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteNamespace(namespaceDeclaration);
 }
        public DynamicActivityXamlReader(bool isBuilder, XamlReader innerReader, XamlSchemaContext schemaContext)
            : base()
        {
            this.isBuilder = isBuilder;
            this.innerReader = innerReader;
            this.schemaContext = schemaContext ?? innerReader.SchemaContext;

            this.xamlTypeXamlType = this.schemaContext.GetXamlType(typeof(XamlType));
            this.typeXamlType = this.schemaContext.GetXamlType(typeof(Type));

            this.baseActivityXamlType = this.schemaContext.GetXamlType(typeof(Activity));
            this.activityPropertyXamlType = this.schemaContext.GetXamlType(typeof(DynamicActivityProperty));
            this.activityPropertyType = this.activityPropertyXamlType.GetMember("Type");
            this.activityPropertyName = this.activityPropertyXamlType.GetMember("Name");
            this.activityPropertyValue = this.activityPropertyXamlType.GetMember("Value");
            this.activityPropertyAttributes = this.activityPropertyXamlType.GetMember("Attributes");

            this.namespaceTable = new NamespaceTable();
            this.frontLoadedDirectives = true;

            // we pump items through this node-list when rewriting
            this.nodeQueue = new XamlNodeQueue(this.schemaContext);
            this.nodeReader = this.nodeQueue.Reader;
            IXamlLineInfo lineInfo = innerReader as IXamlLineInfo;
            if (lineInfo != null && lineInfo.HasLineInfo)
            {
                this.innerReaderLineInfo = lineInfo;
                this.nodeReaderLineInfo = (IXamlLineInfo)nodeQueue.Reader;
                this.hasLineInfo = true;
            }
        }
示例#51
0
        internal static void TransformNodes(System.Xaml.XamlReader xamlReader, System.Xaml.XamlObjectWriter xamlWriter,
                                         bool onlyLoadOneNode, 
                                         bool skipJournaledProperties,
                                         bool shouldPassLineNumberInfo, IXamlLineInfo xamlLineInfo, IXamlLineInfoConsumer xamlLineInfoConsumer, 
                                         XamlContextStack<WpfXamlFrame> stack, 
                                         IStyleConnector styleConnector)
        { 
            while (xamlReader.Read())
            {
                if (shouldPassLineNumberInfo)
                { 
                    if (xamlLineInfo.LineNumber != 0)
                    { 
                        xamlLineInfoConsumer.SetLineInfo(xamlLineInfo.LineNumber, xamlLineInfo.LinePosition); 
                    }
                } 

                switch (xamlReader.NodeType)
                {
                case System.Xaml.XamlNodeType.NamespaceDeclaration: 
                    xamlWriter.WriteNode(xamlReader);
                    if (stack.Depth == 0 || stack.CurrentFrame.Type != null) 
                    { 
                        stack.PushScope();
                        // Need to create an XmlnsDictionary. 
                        // Look up stack to see if we have one earlier
                        //  If so, use that.  Otherwise new a xmlnsDictionary
                        WpfXamlFrame iteratorFrame = stack.CurrentFrame;
                        while (iteratorFrame != null) 
                        {
                            if (iteratorFrame.XmlnsDictionary != null) 
                            { 
                                stack.CurrentFrame.XmlnsDictionary =
                                    new XmlnsDictionary(iteratorFrame.XmlnsDictionary); 
                                break;
                            }
                            iteratorFrame = (WpfXamlFrame)iteratorFrame.Previous;
                        } 
                        if (stack.CurrentFrame.XmlnsDictionary == null)
                        { 
                            stack.CurrentFrame.XmlnsDictionary = 
                                     new XmlnsDictionary();
                        } 
                    }
                    stack.CurrentFrame.XmlnsDictionary.Add(xamlReader.Namespace.Prefix, xamlReader.Namespace.Namespace);
                    break;
                case System.Xaml.XamlNodeType.StartObject: 
                    xamlWriter.WriteNode(xamlReader);
                    // If there's a frame but no Type, that means there 
                    // was a namespace. Just set the Type 
                    if (stack.Depth != 0 && stack.CurrentFrame.Type == null)
                    { 
                        stack.CurrentFrame.Type = xamlReader.Type;
                    }
                    else
                    { 
                        // Propagate the FreezeFreezable property from the current stack frame
                        stack.PushScope(); 
                        stack.CurrentFrame.Type = xamlReader.Type; 
                        if (stack.PreviousFrame.FreezeFreezable)
                        { 
                            stack.CurrentFrame.FreezeFreezable = true;
                        }
                    }
                    break; 
                case System.Xaml.XamlNodeType.GetObject:
                    xamlWriter.WriteNode(xamlReader); 
                    // If there wasn't a namespace node before this get object, need to pushScope. 
                    if (stack.CurrentFrame.Type != null)
                    { 
                        stack.PushScope();
                    }
                    stack.CurrentFrame.Type = stack.PreviousFrame.Property.Type;
                    break; 
                case System.Xaml.XamlNodeType.EndObject:
                    xamlWriter.WriteNode(xamlReader); 
                    // Freeze if required 
                    if (stack.CurrentFrame.FreezeFreezable)
                    { 
                        Freezable freezable = xamlWriter.Result as Freezable;
                        if (freezable != null && freezable.CanFreeze)
                        {
                            freezable.Freeze(); 
                        }
                    } 
                    DependencyObject dependencyObject = xamlWriter.Result as DependencyObject; 
                    if (dependencyObject != null && stack.CurrentFrame.XmlSpace.HasValue)
                    { 
                        XmlAttributeProperties.SetXmlSpace(dependencyObject, stack.CurrentFrame.XmlSpace.Value ? "default" : "preserve");
                    }
                    stack.PopScope();
                    break; 
                case System.Xaml.XamlNodeType.StartMember:
                    // ObjectWriter should NOT process PresentationOptions:Freeze directive since it is Unknown 
                    // The space directive node stream should not be written because it induces object instantiation, 
                    // and the Baml2006Reader can produce space directives prematurely.
                    if (!(xamlReader.Member.IsDirective && xamlReader.Member == XamlReaderHelper.Freeze) && 
                        xamlReader.Member != XmlSpace.Value &&
                        xamlReader.Member != XamlLanguage.Space)
                    {
                        xamlWriter.WriteNode(xamlReader); 
                    }
 
                    stack.CurrentFrame.Property = xamlReader.Member; 
                    if (skipJournaledProperties)
                    { 
                        if (!stack.CurrentFrame.Property.IsDirective)
                        {
                            System.Windows.Baml2006.WpfXamlMember wpfMember = stack.CurrentFrame.Property as System.Windows.Baml2006.WpfXamlMember;
                            if (wpfMember != null) 
                            {
                                DependencyProperty prop = wpfMember.DependencyProperty; 
 
                                if (prop != null)
                                { 
                                    FrameworkPropertyMetadata metadata = prop.GetMetadata(stack.CurrentFrame.Type.UnderlyingType) as FrameworkPropertyMetadata;
                                    if (metadata != null && metadata.Journal == true)
                                    {
                                        // 
                                        int count = 1;
                                        while (xamlReader.Read()) 
                                        { 
                                            switch (xamlReader.NodeType)
                                            { 
                                            case System.Xaml.XamlNodeType.StartMember:
                                                count++;
                                                break;
                                            case System.Xaml.XamlNodeType.EndMember: 
                                                count--;
                                                if (count == 0) 
                                                { 
                                                    xamlWriter.WriteNode(xamlReader);
                                                } 
                                                break;
                                            }
                                            if (count == 0)
                                                break; 
                                        }
                                        // shouldn't this have been a XamlReader.Skip()? 
                                        System.Diagnostics.Debug.Assert(count == 0, "Mismatch StartMember/EndMember"); 
                                    }
                                } 
                            }
                        }
                    }
                    break; 
                case System.Xaml.XamlNodeType.EndMember:
                    WpfXamlFrame currentFrame = stack.CurrentFrame; 
                    XamlMember currentProperty = currentFrame.Property; 
                    // ObjectWriter should not process PresentationOptions:Freeze directive nodes since it is unknown
                    // The space directive node stream should not be written because it induces object instantiation, 
                    // and the Baml2006Reader can produce space directives prematurely.
                    if (!(currentProperty.IsDirective && currentProperty == XamlReaderHelper.Freeze) &&
                        currentProperty != XmlSpace.Value &&
                        currentProperty != XamlLanguage.Space) 
                    {
                        xamlWriter.WriteNode(xamlReader); 
                    } 
                    currentFrame.Property = null;
                    break; 
                case System.Xaml.XamlNodeType.Value:
                    if (stack.CurrentFrame.Property.IsDirective && stack.CurrentFrame.Property == XamlLanguage.Shared)
                    {
                        bool isShared; 
                        if (bool.TryParse(xamlReader.Value as string, out isShared))
                        { 
                            if (!isShared) 
                            {
                                if (!(xamlReader is Baml2006Reader)) 
                                {
                                    throw new XamlParseException(SR.Get(SRID.SharedAttributeInLooseXaml));
                                }
                            } 
                        }
                    } 
                    // ObjectWriter should not process PresentationOptions:Freeze directive nodes since it is unknown 
                    if (stack.CurrentFrame.Property.IsDirective && stack.CurrentFrame.Property == XamlReaderHelper.Freeze)
                    { 
                        bool freeze = Convert.ToBoolean(xamlReader.Value, TypeConverterHelper.InvariantEnglishUS);
                        stack.CurrentFrame.FreezeFreezable = freeze;
                        var bamlReader = xamlReader as System.Windows.Baml2006.Baml2006Reader;
                        if (bamlReader != null) 
                        {
                            bamlReader.FreezeFreezables = freeze; 
                        } 
                    }
                    // The space directive node stream should not be written because it induces object instantiation, 
                    // and the Baml2006Reader can produce space directives prematurely.
                    else if (stack.CurrentFrame.Property == XmlSpace.Value || stack.CurrentFrame.Property == XamlLanguage.Space)
                    {
                        if (typeof(DependencyObject).IsAssignableFrom(stack.CurrentFrame.Type.UnderlyingType)) 
                        {
                            System.Diagnostics.Debug.Assert(xamlReader.Value is string, "XmlAttributeProperties.XmlSpaceProperty has the type string."); 
                            stack.CurrentFrame.XmlSpace = (string)xamlReader.Value == "default"; 
                        }
                    } 
                    else
                    {
                        // Ideally we should check if we're inside FrameworkTemplate's Content and not register those.
                        // However, checking if the instance is null accomplishes the same with a much smaller perf impact. 
                        if (styleConnector != null &&
                            stack.CurrentFrame.Instance != null && 
                            stack.CurrentFrame.Property == XamlLanguage.ConnectionId && 
                            typeof(Style).IsAssignableFrom(stack.CurrentFrame.Type.UnderlyingType))
                        { 
                            styleConnector.Connect((int)xamlReader.Value, stack.CurrentFrame.Instance);
                        }

                        xamlWriter.WriteNode(xamlReader); 
                    }
                    break; 
                default: 
                    xamlWriter.WriteNode(xamlReader);
                    break; 
                }

                //Only do this loop for one node if loadAsync
                if (onlyLoadOneNode) 
                {
                    return; 
                } 
            }
        } 
 public XamlDebuggerXmlReader(XamlReader underlyingReader, IXamlLineInfo xamlLineInfo, TextReader textReader)
 {
     this.underlyingReader = underlyingReader;
     this.xamlLineInfo = xamlLineInfo;
     this.xmlReaderWithSourceLocation = new XmlReaderWithSourceLocation(textReader);
     this.initializationValueRanges = new Dictionary<XamlNode, DocumentRange>();
     // Parse the XML at once to get all the locations we wanted.
     while (this.xmlReaderWithSourceLocation.Read())
     {
     }
     this.schemaContext = underlyingReader.SchemaContext;
     this.objectDeclarationRecords = new Stack<XamlNode>();
     this.bufferedXamlNodes = new Queue<XamlNode>();
     this.current = this.CreateCurrentNode();
     this.SourceLocationFound += XamlDebuggerXmlReader.SetSourceLocation;
 }
                public void ProcessDefaultValue(XamlMember propertyValue, XamlReader subReader, IXamlLineInfo lineInfo)
                {
                    XamlReader reader;
                    bool       flag = false;

                    subReader.Read();
                    if (!subReader.Member.IsNameValid)
                    {
                        throw FxTrace.Exception.AsError(DynamicActivityXamlReader.CreateXamlException(System.Activities.SR.InvalidXamlMember(subReader.Member.Name), lineInfo));
                    }
                    this.nodes.Writer.WriteStartMember(propertyValue, lineInfo);
                    subReader.Read();
                    if (subReader.NodeType == XamlNodeType.GetObject)
                    {
                        subReader.Read();
                        subReader.Read();
                        reader = subReader.ReadSubtree();
                        reader.Read();
                    }
                    else
                    {
                        reader = subReader;
                    }
                    if ((reader.NodeType != XamlNodeType.EndMember) && (reader.NodeType != XamlNodeType.StartObject))
                    {
                        flag = true;
                        this.nodes.Writer.WriteStartObject(this.Type, lineInfo);
                        this.nodes.Writer.WriteStartMember(XamlLanguage.Initialization, lineInfo);
                    }
                    while (!reader.IsEof)
                    {
                        this.nodes.Writer.WriteNode(reader, lineInfo);
                        reader.Read();
                    }
                    reader.Close();
                    if (!object.ReferenceEquals(reader, subReader))
                    {
                        subReader.Read();
                        while (subReader.Read())
                        {
                            this.nodes.Writer.WriteNode(subReader, lineInfo);
                        }
                    }
                    if (flag)
                    {
                        this.nodes.Writer.WriteEndObject(lineInfo);
                        this.nodes.Writer.WriteEndMember(lineInfo);
                    }
                    subReader.Close();
                }
 public void CopyTo(XamlNodeQueue targetNodeQueue, IXamlLineInfo readerInfo)
 {
     XamlServices.Transform(this.nodes.Reader, targetNodeQueue.Writer, false);
     targetNodeQueue.Writer.WriteEndObject(readerInfo);
 }
 public static void WriteEndMember(this XamlWriter writer, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteEndMember();
 }
 public ValueHolder(XamlSchemaContext schemaContext, XamlMember propertyValue, XamlReader reader, IXamlLineInfo lineInfo)
 {
     this.nodes         = new XamlNodeQueue(schemaContext);
     this.PropertyValue = propertyValue;
     XamlWriterExtensions.Transform(reader.ReadSubtree(), this.nodes.Writer, lineInfo, true);
 }
 public static void WriteNamespace(this XamlWriter writer, NamespaceDeclaration namespaceDeclaration, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteNamespace(namespaceDeclaration);
 }
 public bool ProcessNode(XamlReader reader, XamlWriter targetWriter, int currentDepth, IXamlLineInfo readerLineInfo)
 {
     if ((currentDepth == this.Depth) && ((reader.NodeType == XamlNodeType.NamespaceDeclaration) || (reader.NodeType == XamlNodeType.None)))
     {
         this.bufferedNodes.Writer.WriteNode(reader, readerLineInfo);
         reader.Read();
         return(true);
     }
     if ((((reader.NodeType == XamlNodeType.StartObject) && reader.Type.IsGeneric) && ((reader.Type.UnderlyingType != null) && (reader.Type.Name == "PropertyReferenceExtension"))) && (reader.Type.UnderlyingType.GetGenericTypeDefinition() == typeof(PropertyReferenceExtension <>)))
     {
         if (this.bufferedNodes.Count > 0)
         {
             XamlServices.Transform(this.bufferedNodes.Reader, targetWriter, false);
             this.bufferedNodes = null;
         }
         XamlType   type     = reader.Type;
         XamlReader reader2  = reader.ReadSubtree();
         XamlType   xamlType = reader.SchemaContext.GetXamlType(typeof(ActivityBuilder));
         XamlType   type3    = reader.SchemaContext.GetXamlType(typeof(ActivityPropertyReference));
         targetWriter.WriteStartMember(xamlType.GetAttachableMember("PropertyReference"), readerLineInfo);
         reader2.Read();
         targetWriter.WriteStartObject(type3, readerLineInfo);
         targetWriter.WriteStartMember(type3.GetMember("TargetProperty"), readerLineInfo);
         targetWriter.WriteValue(this.currentMember.Name, readerLineInfo);
         targetWriter.WriteEndMember(readerLineInfo);
         bool flag  = reader2.Read();
         bool flag2 = false;
         while (flag)
         {
             if (((reader2.NodeType == XamlNodeType.StartMember) && (reader2.Member.DeclaringType == type)) && (reader2.Member.Name == "PropertyName"))
             {
                 flag2 = true;
             }
             else if (flag2)
             {
                 if (reader2.NodeType == XamlNodeType.EndMember)
                 {
                     flag2 = false;
                 }
                 else if (reader2.NodeType == XamlNodeType.Value)
                 {
                     targetWriter.WriteStartMember(type3.GetMember("SourceProperty"), readerLineInfo);
                     targetWriter.WriteValue((string)reader2.Value, readerLineInfo);
                     targetWriter.WriteEndMember(readerLineInfo);
                 }
             }
             flag = reader2.Read();
         }
         targetWriter.WriteEndObject(readerLineInfo);
         targetWriter.WriteEndMember(readerLineInfo);
         this.ExitObject = true;
         reader2.Close();
     }
     else
     {
         this.FlushBuffer(targetWriter);
         targetWriter.WriteNode(reader, readerLineInfo);
     }
     return(false);
 }
 public static void WriteStartObject(this XamlWriter writer, XamlType type, IXamlLineInfo lineInfo)
 {
     PropagateLineInfo(writer, lineInfo);
     writer.WriteStartObject(type);
 }
 private void DisableRewrite()
 {
     this.notRewriting       = true;
     this.nodeReader         = this.innerReader;
     this.nodeReaderLineInfo = this.innerReader as IXamlLineInfo;
 }