Beispiel #1
0
        public BamlRecord ReadRecord()
        {
            BamlRecordType recordType = (BamlRecordType)_reader.ReadByte();
            BamlRecord     record     = StaticBamlRecords.GetRecord(recordType);

            long startPosition = Position;
            int  variableSize  = 0;

            if (record.IsVariableSize)
            {
                variableSize = _reader.Read7BitEncodedInt();
            }

            for (int i = 0; i < record.Fields.Length; i++)
            {
                record.Fields[i].Value = ReadField(record.Fields[i]);
            }

            // this deals with the rare case of undefined padding
            // at the end of a record.  Only allowed for PropertyCustom
            if (record.IsVariableSize)
            {
                int processedSize = (int)(Position - startPosition);
                int extraPadding  = variableSize - processedSize;
                Debug.Assert(extraPadding >= 0);
                if (extraPadding > 0)
                {
                    Debug.Assert(recordType == BamlRecordType.PropertyCustom);
                    byte[] bytes = _reader.ReadBytes(extraPadding);
                }
            }
            return(record);
        }
Beispiel #2
0
        // Token: 0x06001EC9 RID: 7881 RVA: 0x00093BE4 File Offset: 0x00091DE4
        internal BamlRecord CloneRecord(BamlRecord record)
        {
            BamlRecordType recordType = record.RecordType;
            BamlRecord     bamlRecord;

            if (recordType != BamlRecordType.ElementStart)
            {
                if (recordType != BamlRecordType.PropertyCustom)
                {
                    bamlRecord = this.AllocateRecord(record.RecordType);
                }
                else if (record is BamlPropertyCustomWriteInfoRecord)
                {
                    bamlRecord = new BamlPropertyCustomWriteInfoRecord();
                }
                else
                {
                    bamlRecord = new BamlPropertyCustomRecord();
                }
            }
            else if (record is BamlNamedElementStartRecord)
            {
                bamlRecord = new BamlNamedElementStartRecord();
            }
            else
            {
                bamlRecord = new BamlElementStartRecord();
            }
            record.Copy(bamlRecord);
            return(bamlRecord);
        }
Beispiel #3
0
        public string RootElement()
        {
            EnsureInit();
            var root = "unknown";
            do
            {
                _currentType = (BamlRecordType)_reader.ReadByte();
                if (_currentType == BamlRecordType.DocumentEnd) break;
                if (_currentType == BamlRecordType.ElementStart && !_firstElementStartMet)
                {
                    _firstElementStartMet = true;
                    root = ReadElementStart();
                    break;
                }
                var position = _reader.BaseStream.Position;
                ComputeBytesToSkip();
                ProcessNext();

                if (_bytesToSkip > 0)
                {
                    _reader.BaseStream.Position = position + _bytesToSkip;
                }
            } while (true);

            return root;
        }
        // Token: 0x060020F1 RID: 8433 RVA: 0x00097790 File Offset: 0x00095990
        public void WriteEndComplexProperty()
        {
            this.VerifyWriteState();
            BamlRecordType bamlRecordType = this.Pop();

            switch (bamlRecordType)
            {
            case BamlRecordType.PropertyComplexStart:
            {
                int lineNumber   = 0;
                int linePosition = 0;
                int depth        = this._depth - 1;
                this._depth = depth;
                XamlPropertyComplexEndNode xamlPropertyComplexEnd = new XamlPropertyComplexEndNode(lineNumber, linePosition, depth);
                this._bamlRecordWriter.WritePropertyComplexEnd(xamlPropertyComplexEnd);
                goto IL_11F;
            }

            case BamlRecordType.PropertyArrayStart:
            {
                int lineNumber2   = 0;
                int linePosition2 = 0;
                int depth         = this._depth - 1;
                this._depth = depth;
                XamlPropertyArrayEndNode xamlPropertyArrayEndNode = new XamlPropertyArrayEndNode(lineNumber2, linePosition2, depth);
                this._bamlRecordWriter.WritePropertyArrayEnd(xamlPropertyArrayEndNode);
                goto IL_11F;
            }

            case BamlRecordType.PropertyIListStart:
            {
                int lineNumber3   = 0;
                int linePosition3 = 0;
                int depth         = this._depth - 1;
                this._depth = depth;
                XamlPropertyIListEndNode xamlPropertyIListEndNode = new XamlPropertyIListEndNode(lineNumber3, linePosition3, depth);
                this._bamlRecordWriter.WritePropertyIListEnd(xamlPropertyIListEndNode);
                goto IL_11F;
            }

            case BamlRecordType.PropertyIDictionaryStart:
            {
                int lineNumber4   = 0;
                int linePosition4 = 0;
                int depth         = this._depth - 1;
                this._depth = depth;
                XamlPropertyIDictionaryEndNode xamlPropertyIDictionaryEndNode = new XamlPropertyIDictionaryEndNode(lineNumber4, linePosition4, depth);
                this._bamlRecordWriter.WritePropertyIDictionaryEnd(xamlPropertyIDictionaryEndNode);
                goto IL_11F;
            }
            }
            throw new InvalidOperationException(SR.Get("BamlWriterBadScope", new object[]
            {
                bamlRecordType.ToString(),
                BamlRecordType.PropertyComplexEnd.ToString()
            }));
IL_11F:
            this._parserContext.PopScope();
        }
 internal static bool IsDebugBamlRecordType(BamlRecordType recordType)
 {
     if (   recordType == BamlRecordType.LineNumberAndPosition
         || recordType == BamlRecordType.LinePosition )
     {
         return true;
     }
     return false;
 }
Beispiel #6
0
 internal static bool IsDebugBamlRecordType(BamlRecordType recordType)
 {
     if (recordType == BamlRecordType.LineNumberAndPosition ||
         recordType == BamlRecordType.LinePosition)
     {
         return(true);
     }
     return(false);
 }
Beispiel #7
0
 private static BamlRecord BamlRecordFromType(BamlRecordType type)
 {
     return(type switch
     {
         BamlRecordType.AssemblyInfo => new AssemblyInfoRecord(),
         BamlRecordType.AttributeInfo => new AttributeInfoRecord(),
         BamlRecordType.ConstructorParametersStart => new ConstructorParametersStartRecord(),
         BamlRecordType.ConstructorParametersEnd => new ConstructorParametersEndRecord(),
         BamlRecordType.ConstructorParameterType => new ConstructorParameterTypeRecord(),
         BamlRecordType.ConnectionId => new ConnectionIdRecord(),
         BamlRecordType.ContentProperty => new ContentPropertyRecord(),
         BamlRecordType.DefAttribute => new DefAttributeRecord(),
         BamlRecordType.DefAttributeKeyString => new DefAttributeKeyStringRecord(),
         BamlRecordType.DefAttributeKeyType => new DefAttributeKeyTypeRecord(),
         BamlRecordType.DeferableContentStart => new DeferableContentStartRecord(),
         BamlRecordType.DocumentEnd => new DocumentEndRecord(),
         BamlRecordType.DocumentStart => new DocumentStartRecord(),
         BamlRecordType.ElementEnd => new ElementEndRecord(),
         BamlRecordType.ElementStart => new ElementStartRecord(),
         BamlRecordType.KeyElementEnd => new KeyElementEndRecord(),
         BamlRecordType.KeyElementStart => new KeyElementStartRecord(),
         BamlRecordType.LineNumberAndPosition => new LineNumberAndPositionRecord(),
         BamlRecordType.LinePosition => new LinePositionRecord(),
         BamlRecordType.LiteralContent => new LiteralContentRecord(),
         BamlRecordType.NamedElementStart => new NamedElementStartRecord(),
         BamlRecordType.OptimizedStaticResource => new OptimizedStaticResourceRecord(),
         BamlRecordType.PIMapping => new PIMappingRecord(),
         BamlRecordType.PresentationOptionsAttribute => new PresentationOptionsAttributeRecord(),
         BamlRecordType.Property => new PropertyRecord(),
         BamlRecordType.PropertyArrayEnd => new PropertyArrayEndRecord(),
         BamlRecordType.PropertyArrayStart => new PropertyArrayStartRecord(),
         BamlRecordType.PropertyComplexEnd => new PropertyComplexEndRecord(),
         BamlRecordType.PropertyComplexStart => new PropertyComplexStartRecord(),
         BamlRecordType.PropertyCustom => new PropertyCustomRecord(),
         BamlRecordType.PropertyDictionaryEnd => new PropertyDictionaryEndRecord(),
         BamlRecordType.PropertyDictionaryStart => new PropertyDictionaryStartRecord(),
         BamlRecordType.PropertyListEnd => new PropertyListEndRecord(),
         BamlRecordType.PropertyListStart => new PropertyListStartRecord(),
         BamlRecordType.PropertyStringReference => new PropertyStringReferenceRecord(),
         BamlRecordType.PropertyTypeReference => new PropertyTypeReferenceRecord(),
         BamlRecordType.PropertyWithConverter => new PropertyWithConverterRecord(),
         BamlRecordType.PropertyWithExtension => new PropertyWithExtensionRecord(),
         BamlRecordType.PropertyWithStaticResourceId => new PropertyWithStaticResourceIdRecord(),
         BamlRecordType.RoutedEvent => new RoutedEventRecord(),
         BamlRecordType.StaticResourceEnd => new StaticResourceEndRecord(),
         BamlRecordType.StaticResourceId => new StaticResourceIdRecord(),
         BamlRecordType.StaticResourceStart => new StaticResourceStartRecord(),
         BamlRecordType.StringInfo => new StringInfoRecord(),
         BamlRecordType.Text => new TextRecord(),
         BamlRecordType.TextWithConverter => new TextWithConverterRecord(),
         BamlRecordType.TextWithId => new TextWithIdRecord(),
         BamlRecordType.TypeInfo => new TypeInfoRecord(),
         BamlRecordType.TypeSerializerInfo => new TypeSerializerInfoRecord(),
         BamlRecordType.XmlnsProperty => new XmlnsPropertyRecord(),
         _ => throw new NotSupportedException("Unsupported record type: " + type)
     });
Beispiel #8
0
        private BamlRecordType ReadRecordType(out TextLineSections text)
        {
            long pos      = Position;
            int  recordId = _reader.ReadByte();

            Position = pos;

            BamlRecordType val     = (BamlRecordType)recordId;
            string         meaning = string.Format("{0} [BamlRecord]", val.ToString());

            byte[] bytes = _reader.ReadBytes(1);
            text = new TextLineSections(pos, bytes, meaning);
            return(val);
        }
Beispiel #9
0
        // Token: 0x06001ECA RID: 7882 RVA: 0x00093C48 File Offset: 0x00091E48
        private BamlRecord AllocateWriteRecord(BamlRecordType recordType)
        {
            BamlRecord result;

            if (recordType == BamlRecordType.PropertyCustom)
            {
                result = new BamlPropertyCustomWriteInfoRecord();
            }
            else
            {
                result = this.AllocateRecord(recordType);
            }
            return(result);
        }
        // Token: 0x060020F9 RID: 8441 RVA: 0x00097BFC File Offset: 0x00095DFC
        private void VerifyEndTagState(BamlRecordType expectedStartTag, BamlRecordType endTagBeingWritten)
        {
            this.VerifyWriteState();
            BamlRecordType bamlRecordType = this.Pop();

            if (bamlRecordType != expectedStartTag)
            {
                throw new InvalidOperationException(SR.Get("BamlWriterBadScope", new object[]
                {
                    bamlRecordType.ToString(),
                    endTagBeingWritten.ToString()
                }));
            }
        }
Beispiel #11
0
 public BamlRecord(BamlRecordType recordId, bool isVariableSize, BamlRecordFlags flags, BamlField[] fields)
 {
     if (null == fields)
     {
         throw new ArgumentNullException("fields");
     }
     if (recordId <= BamlRecordType.Unknown || recordId >= BamlRecordType.LastRecordType)
     {
         throw new ArgumentOutOfRangeException("BamlRecordType recordId");
     }
     _recordId       = recordId;
     _flags          = flags;
     _isVariableSize = isVariableSize;
     _fields         = fields;
 }
Beispiel #12
0
 static void NavigateTree(BamlDocument doc, BamlRecordType start, BamlRecordType end, ref int index)
 {
     index++;
     while (true)
     {
         if (doc[index].Type == start)
         {
             NavigateTree(doc, start, end, ref index);
         }
         else if (doc[index].Type == end)
         {
             return;
         }
         index++;
     }
 }
        // 
        // This method checks to see if the baml record type is one of the records used
        // to build up the map table, e.g. type information.
        //
        static internal bool IsMapTableRecordType( BamlRecordType bamlRecordType )
        {
            switch( bamlRecordType )
            {
                case BamlRecordType.PIMapping:
                case BamlRecordType.AssemblyInfo:
                case BamlRecordType.TypeInfo:
                case BamlRecordType.TypeSerializerInfo:
                case BamlRecordType.AttributeInfo:
                case BamlRecordType.StringInfo:
                    return true;

                default:
                    return false;
            }
        }
Beispiel #14
0
		public static IHandler LookupHandler(BamlRecordType type) {
#if DEBUG
			switch (type) {
				case BamlRecordType.AssemblyInfo:
				case BamlRecordType.TypeInfo:
				case BamlRecordType.AttributeInfo:
				case BamlRecordType.StringInfo:
					break;
				default:
					if (!handlers.ContainsKey(type))
						throw new NotSupportedException(type.ToString());
					break;
			}
#endif
			return handlers.ContainsKey(type) ? handlers[type] : null;
		}
Beispiel #15
0
        //
        // This method checks to see if the baml record type is one of the records used
        // to build up the map table, e.g. type information.
        //
        static internal bool IsMapTableRecordType(BamlRecordType bamlRecordType)
        {
            switch (bamlRecordType)
            {
            case BamlRecordType.PIMapping:
            case BamlRecordType.AssemblyInfo:
            case BamlRecordType.TypeInfo:
            case BamlRecordType.TypeSerializerInfo:
            case BamlRecordType.AttributeInfo:
            case BamlRecordType.StringInfo:
                return(true);

            default:
                return(false);
            }
        }
        // Token: 0x060020ED RID: 8429 RVA: 0x00097364 File Offset: 0x00095564
        public void WriteXmlnsProperty(string localName, string xmlNamespace)
        {
            this.VerifyWriteState();
            BamlRecordType bamlRecordType = this.PeekRecordType();

            if (bamlRecordType != BamlRecordType.ElementStart && bamlRecordType != BamlRecordType.PropertyComplexStart && bamlRecordType != BamlRecordType.PropertyArrayStart && bamlRecordType != BamlRecordType.PropertyIListStart && bamlRecordType != BamlRecordType.PropertyIDictionaryStart)
            {
                throw new InvalidOperationException(SR.Get("BamlWriterBadXmlns", new object[]
                {
                    "WriteXmlnsProperty",
                    bamlRecordType.ToString()
                }));
            }
            XamlXmlnsPropertyNode xamlXmlnsPropertyNode = new XamlXmlnsPropertyNode(0, 0, this._depth, localName, xmlNamespace);

            this._bamlRecordWriter.WriteNamespacePrefix(xamlXmlnsPropertyNode);
            this._parserContext.XmlnsDictionary[localName] = xmlNamespace;
        }
Beispiel #17
0
        // Token: 0x06001ECC RID: 7884 RVA: 0x00093F24 File Offset: 0x00092124
        internal BamlRecord GetWriteRecord(BamlRecordType recordType)
        {
            if (this._writeCache == null)
            {
                this._writeCache = new BamlRecord[57];
            }
            BamlRecord bamlRecord = this._writeCache[(int)recordType];

            if (bamlRecord == null)
            {
                bamlRecord = this.AllocateWriteRecord(recordType);
            }
            else
            {
                this._writeCache[(int)recordType] = null;
            }
            bamlRecord.RecordSize = -1;
            return(bamlRecord);
        }
Beispiel #18
0
        private static void NavigateTree(IList <BamlRecord> records, BamlRecordType start, BamlRecordType end, ref int index)
        {
            index++;

            while (true) //Assume there always is a end
            {
                var recordType = records[index].Type;

                if (recordType == start)
                {
                    NavigateTree(records, start, end, ref index);
                }
                else if (recordType == end)
                {
                    return;
                }

                index++;
            }
        }
Beispiel #19
0
        public static IHandler LookupHandler(BamlRecordType type)
        {
#if DEBUG
            switch (type)
            {
            case BamlRecordType.AssemblyInfo:
            case BamlRecordType.TypeInfo:
            case BamlRecordType.AttributeInfo:
            case BamlRecordType.StringInfo:
                break;

            default:
                if (!handlers.ContainsKey(type))
                {
                    throw new NotSupportedException(type.ToString());
                }
                break;
            }
#endif
            return(handlers.ContainsKey(type) ? handlers[type] : null);
        }
        // This should only be called from BamlRecordWriter -- it gets a record from the record
        // cache that must be freed with ReleaseRecord before GetRecord is called again.
        internal BamlRecord GetWriteRecord(BamlRecordType recordType)
        {
            // Create the cache of records used in writing, on demand

            if( _writeCache == null )
            {
                _writeCache = new BamlRecord[(int)BamlRecordType.LastRecordType];
            }

            BamlRecord record = _writeCache[(int)recordType];
            if (null == record)
            {
                record = AllocateWriteRecord(recordType);
            }
            else
            {
                _writeCache[(int)recordType] = null;
            }

            // It is important to set RecordSize for variable size records
            // to a negative number to indicate that it has not been set yet.
            // Fixed size records should ignore this set.
            record.RecordSize = -1;
            return record;
        }
Beispiel #21
0
        public string RootElement()
        {
            EnsureInit();
            var root = "unknown";
            do
            {
                _currentType = (BamlRecordType)_reader.ReadByte();
                if (_currentType == BamlRecordType.DocumentEnd) break;
                if (_currentType == BamlRecordType.ElementStart && !_firstElementStartMet)
                {
                    _firstElementStartMet = true;
                    root = ReadElementStart();
                    break;
                }
                var position = _reader.BaseStream.Position;
                ComputeBytesToSkip();
                ProcessNext();

                if (_bytesToSkip > 0)
                {
                    _reader.BaseStream.Position = position + _bytesToSkip;
                }
            } while (true);

            return root;
        }
Beispiel #22
0
 // Token: 0x06001EE1 RID: 7905 RVA: 0x000940D9 File Offset: 0x000922D9
 internal static bool IsContentRecord(BamlRecordType bamlRecordType)
 {
     return(bamlRecordType == BamlRecordType.PropertyComplexStart || bamlRecordType == BamlRecordType.PropertyArrayStart || bamlRecordType == BamlRecordType.PropertyIListStart || bamlRecordType == BamlRecordType.PropertyIDictionaryStart || bamlRecordType == BamlRecordType.Text);
 }
 // Token: 0x06008364 RID: 33636 RVA: 0x00244EFC File Offset: 0x002430FC
 public WriteStackNode(BamlRecordType recordType)
 {
     this._recordType           = recordType;
     this._endAttributesReached = false;
 }
        internal static bool DoesRecordTypeHaveDebugExtension(BamlRecordType recordType)
        {
            switch(recordType)
            {
                case BamlRecordType.ElementStart:
                case BamlRecordType.ElementEnd:
                case BamlRecordType.Property:
                case BamlRecordType.PropertyComplexStart:
                case BamlRecordType.PropertyArrayStart:
                case BamlRecordType.PropertyIListStart:
                case BamlRecordType.PropertyIDictionaryStart:
                case BamlRecordType.XmlnsProperty:
                case BamlRecordType.PIMapping:
                case BamlRecordType.PropertyTypeReference:
                case BamlRecordType.PropertyWithExtension:
                case BamlRecordType.PropertyWithConverter:
                case BamlRecordType.KeyElementStart:
                case BamlRecordType.ConnectionId:
                case BamlRecordType.ContentProperty:
                case BamlRecordType.StaticResourceStart:
                case BamlRecordType.PresentationOptionsAttribute:
                    return true;

                case BamlRecordType.DocumentStart:
                case BamlRecordType.DocumentEnd:                // End record
                case BamlRecordType.PropertyCustom:             // The "custom" size of this is a problem
                case BamlRecordType.PropertyComplexEnd:         // End record
                case BamlRecordType.PropertyArrayEnd:           // End record
                case BamlRecordType.PropertyIListEnd:           // End record
                case BamlRecordType.PropertyIDictionaryEnd:     // End record
                case BamlRecordType.LiteralContent:             // Not needed
                case BamlRecordType.Text:                       // Not needed
                case BamlRecordType.TextWithConverter:          // Not common enough
                case BamlRecordType.RoutedEvent:                // Not common enough
                case BamlRecordType.ClrEvent:                   // Not common enough
                case BamlRecordType.XmlAttribute:               // Not common enough
                case BamlRecordType.ProcessingInstruction:      // Not common enough
                case BamlRecordType.Comment:                    // Not common enough
                case BamlRecordType.DefTag:                     // Not common enough
                case BamlRecordType.DefAttribute:               // Not common enough
                case BamlRecordType.EndAttributes:              // Not common enough
                case BamlRecordType.AssemblyInfo:               // Info records (in general) don't advance file position
                case BamlRecordType.TypeInfo:                   // Info records (in general) don't advance file position
                case BamlRecordType.TypeSerializerInfo:         // Not common enough
                case BamlRecordType.AttributeInfo:              // Info records (in general) don't advance file position
                case BamlRecordType.StringInfo:                 // Info records (in general) don't advance file position
                case BamlRecordType.PropertyStringReference:    // Not common enough
                case BamlRecordType.DeferableContentStart:      // This would complicate Deferable Content Size
                case BamlRecordType.ConstructorParametersStart: // Not Needed
                case BamlRecordType.ConstructorParametersEnd:   // End record
                case BamlRecordType.ConstructorParameterType:   // Not Needed
                case BamlRecordType.NamedElementStart:          // Not common enough
                case BamlRecordType.TextWithId:                 // Not Needed
                case BamlRecordType.LineNumberAndPosition:      // This would become recursive
                case BamlRecordType.LinePosition:               // This would become recursive
                case BamlRecordType.DefAttributeKeyString:
                case BamlRecordType.DefAttributeKeyType:
                case BamlRecordType.KeyElementEnd:
                case BamlRecordType.StaticResourceEnd:
                case BamlRecordType.StaticResourceId:
                case BamlRecordType.OptimizedStaticResource:
                case BamlRecordType.PropertyWithStaticResourceId:
                    return false;

                default:
                    Debug.Assert(false, "Unhandled case in DoesRecordTypeHaveDebugExtension");
                    return false;
            }
        }
        // Token: 0x060020F0 RID: 8432 RVA: 0x000975CC File Offset: 0x000957CC
        public void WriteStartComplexProperty(string assemblyName, string ownerTypeFullName, string propName)
        {
            this.VerifyWriteState();
            this._parserContext.PushScope();
            this.ProcessMarkupExtensionNodes();
            Type   type             = null;
            bool   propertyCanWrite = true;
            object obj;
            Type   type2;

            this.GetDpOrPi(assemblyName, ownerTypeFullName, propName, out obj, out type2);
            if (obj == null)
            {
                MethodInfo mi = this.GetMi(assemblyName, ownerTypeFullName, propName, out type2);
                if (mi != null)
                {
                    XamlTypeMapper.GetPropertyType(mi, out type, out propertyCanWrite);
                }
            }
            else
            {
                type = XamlTypeMapper.GetPropertyType(obj);
                PropertyInfo propertyInfo = obj as PropertyInfo;
                if (propertyInfo != null)
                {
                    propertyCanWrite = propertyInfo.CanWrite;
                }
                else
                {
                    DependencyProperty dependencyProperty = obj as DependencyProperty;
                    if (dependencyProperty != null)
                    {
                        propertyCanWrite = !dependencyProperty.ReadOnly;
                    }
                }
            }
            int depth;

            if (type == null)
            {
                this.Push(BamlRecordType.PropertyComplexStart);
                int lineNumber   = 0;
                int linePosition = 0;
                depth       = this._depth;
                this._depth = depth + 1;
                XamlPropertyComplexStartNode xamlComplexPropertyNode = new XamlPropertyComplexStartNode(lineNumber, linePosition, depth, null, assemblyName, ownerTypeFullName, propName);
                this._bamlRecordWriter.WritePropertyComplexStart(xamlComplexPropertyNode);
                return;
            }
            BamlRecordType propertyStartRecordType = BamlRecordManager.GetPropertyStartRecordType(type, propertyCanWrite);

            this.Push(propertyStartRecordType);
            switch (propertyStartRecordType)
            {
            case BamlRecordType.PropertyArrayStart:
            {
                int lineNumber2   = 0;
                int linePosition2 = 0;
                depth       = this._depth;
                this._depth = depth + 1;
                XamlPropertyArrayStartNode xamlPropertyArrayStartNode = new XamlPropertyArrayStartNode(lineNumber2, linePosition2, depth, obj, assemblyName, ownerTypeFullName, propName);
                this._bamlRecordWriter.WritePropertyArrayStart(xamlPropertyArrayStartNode);
                return;
            }

            case BamlRecordType.PropertyIListStart:
            {
                int lineNumber3   = 0;
                int linePosition3 = 0;
                depth       = this._depth;
                this._depth = depth + 1;
                XamlPropertyIListStartNode xamlPropertyIListStart = new XamlPropertyIListStartNode(lineNumber3, linePosition3, depth, obj, assemblyName, ownerTypeFullName, propName);
                this._bamlRecordWriter.WritePropertyIListStart(xamlPropertyIListStart);
                return;
            }

            case BamlRecordType.PropertyIDictionaryStart:
            {
                int lineNumber4   = 0;
                int linePosition4 = 0;
                depth       = this._depth;
                this._depth = depth + 1;
                XamlPropertyIDictionaryStartNode xamlPropertyIDictionaryStartNode = new XamlPropertyIDictionaryStartNode(lineNumber4, linePosition4, depth, obj, assemblyName, ownerTypeFullName, propName);
                this._bamlRecordWriter.WritePropertyIDictionaryStart(xamlPropertyIDictionaryStartNode);
                return;
            }
            }
            int lineNumber5   = 0;
            int linePosition5 = 0;

            depth       = this._depth;
            this._depth = depth + 1;
            XamlPropertyComplexStartNode xamlComplexPropertyNode2 = new XamlPropertyComplexStartNode(lineNumber5, linePosition5, depth, obj, assemblyName, ownerTypeFullName, propName);

            this._bamlRecordWriter.WritePropertyComplexStart(xamlComplexPropertyNode2);
        }
Beispiel #26
0
        // Token: 0x06001ECB RID: 7883 RVA: 0x00093C6C File Offset: 0x00091E6C
        private BamlRecord AllocateRecord(BamlRecordType recordType)
        {
            switch (recordType)
            {
            case BamlRecordType.DocumentStart:
                return(new BamlDocumentStartRecord());

            case BamlRecordType.DocumentEnd:
                return(new BamlDocumentEndRecord());

            case BamlRecordType.ElementStart:
                return(new BamlElementStartRecord());

            case BamlRecordType.ElementEnd:
                return(new BamlElementEndRecord());

            case BamlRecordType.Property:
                return(new BamlPropertyRecord());

            case BamlRecordType.PropertyCustom:
                return(new BamlPropertyCustomRecord());

            case BamlRecordType.PropertyComplexStart:
                return(new BamlPropertyComplexStartRecord());

            case BamlRecordType.PropertyComplexEnd:
                return(new BamlPropertyComplexEndRecord());

            case BamlRecordType.PropertyArrayStart:
                return(new BamlPropertyArrayStartRecord());

            case BamlRecordType.PropertyArrayEnd:
                return(new BamlPropertyArrayEndRecord());

            case BamlRecordType.PropertyIListStart:
                return(new BamlPropertyIListStartRecord());

            case BamlRecordType.PropertyIListEnd:
                return(new BamlPropertyIListEndRecord());

            case BamlRecordType.PropertyIDictionaryStart:
                return(new BamlPropertyIDictionaryStartRecord());

            case BamlRecordType.PropertyIDictionaryEnd:
                return(new BamlPropertyIDictionaryEndRecord());

            case BamlRecordType.LiteralContent:
                return(new BamlLiteralContentRecord());

            case BamlRecordType.Text:
                return(new BamlTextRecord());

            case BamlRecordType.TextWithConverter:
                return(new BamlTextWithConverterRecord());

            case BamlRecordType.RoutedEvent:
                return(new BamlRoutedEventRecord());

            case BamlRecordType.XmlnsProperty:
                return(new BamlXmlnsPropertyRecord());

            case BamlRecordType.DefAttribute:
                return(new BamlDefAttributeRecord());

            case BamlRecordType.PIMapping:
                return(new BamlPIMappingRecord());

            case BamlRecordType.AssemblyInfo:
            case BamlRecordType.TypeInfo:
            case BamlRecordType.TypeSerializerInfo:
            case BamlRecordType.AttributeInfo:
            case BamlRecordType.StringInfo:
                return(null);

            case BamlRecordType.PropertyStringReference:
                return(new BamlPropertyStringReferenceRecord());

            case BamlRecordType.PropertyTypeReference:
                return(new BamlPropertyTypeReferenceRecord());

            case BamlRecordType.PropertyWithExtension:
                return(new BamlPropertyWithExtensionRecord());

            case BamlRecordType.PropertyWithConverter:
                return(new BamlPropertyWithConverterRecord());

            case BamlRecordType.DeferableContentStart:
                return(new BamlDeferableContentStartRecord());

            case BamlRecordType.DefAttributeKeyString:
                return(new BamlDefAttributeKeyStringRecord());

            case BamlRecordType.DefAttributeKeyType:
                return(new BamlDefAttributeKeyTypeRecord());

            case BamlRecordType.KeyElementStart:
                return(new BamlKeyElementStartRecord());

            case BamlRecordType.KeyElementEnd:
                return(new BamlKeyElementEndRecord());

            case BamlRecordType.ConstructorParametersStart:
                return(new BamlConstructorParametersStartRecord());

            case BamlRecordType.ConstructorParametersEnd:
                return(new BamlConstructorParametersEndRecord());

            case BamlRecordType.ConstructorParameterType:
                return(new BamlConstructorParameterTypeRecord());

            case BamlRecordType.ConnectionId:
                return(new BamlConnectionIdRecord());

            case BamlRecordType.ContentProperty:
                return(new BamlContentPropertyRecord());

            case BamlRecordType.StaticResourceStart:
                return(new BamlStaticResourceStartRecord());

            case BamlRecordType.StaticResourceEnd:
                return(new BamlStaticResourceEndRecord());

            case BamlRecordType.StaticResourceId:
                return(new BamlStaticResourceIdRecord());

            case BamlRecordType.TextWithId:
                return(new BamlTextWithIdRecord());

            case BamlRecordType.PresentationOptionsAttribute:
                return(new BamlPresentationOptionsAttributeRecord());

            case BamlRecordType.LineNumberAndPosition:
                return(new BamlLineAndPositionRecord());

            case BamlRecordType.LinePosition:
                return(new BamlLinePositionRecord());

            case BamlRecordType.OptimizedStaticResource:
                return(new BamlOptimizedStaticResourceRecord());

            case BamlRecordType.PropertyWithStaticResourceId:
                return(new BamlPropertyWithStaticResourceIdRecord());
            }
            return(null);
        }
    /***************************************************************************\
    *
    * BamlWriter.VerifyEndTagState
    *
    * Verify that we are in a good state to perform a record write and that
    * the xamlnodetype on the node type stack is of the expected type.  This
    * is called when an end tag record is written
    *
    \***************************************************************************/
    
    private void VerifyEndTagState(
        BamlRecordType   expectedStartTag,
        BamlRecordType   endTagBeingWritten)
    {
        VerifyWriteState();

        BamlRecordType startTagState = Pop();
        if (startTagState != expectedStartTag)
        {
            throw new InvalidOperationException(SR.Get(SRID.BamlWriterBadScope,
                                                       startTagState.ToString(),
                                                       endTagBeingWritten.ToString()));
        }
    }
Beispiel #28
0
        public static BamlDocument ReadDocument(Stream str)
        {
            BamlDocument     ret    = new BamlDocument();
            BamlBinaryReader reader = new BamlBinaryReader(str);

            {
                BinaryReader rdr = new BinaryReader(str, Encoding.Unicode);
                uint         len = rdr.ReadUInt32();
                ret.Signature = new string(rdr.ReadChars((int)(len >> 1)));
                rdr.ReadBytes((int)(((len + 3) & ~3) - len));
            }
            if (ret.Signature != "MSBAML")
            {
                throw new NotSupportedException();
            }
            ret.ReaderVersion = new BamlDocument.BamlVersion()
            {
                Major = reader.ReadUInt16(), Minor = reader.ReadUInt16()
            };
            ret.UpdaterVersion = new BamlDocument.BamlVersion()
            {
                Major = reader.ReadUInt16(), Minor = reader.ReadUInt16()
            };
            ret.WriterVersion = new BamlDocument.BamlVersion()
            {
                Major = reader.ReadUInt16(), Minor = reader.ReadUInt16()
            };
            if (ret.ReaderVersion.Major != 0 || ret.ReaderVersion.Minor != 0x60 ||
                ret.UpdaterVersion.Major != 0 || ret.UpdaterVersion.Minor != 0x60 ||
                ret.WriterVersion.Major != 0 || ret.WriterVersion.Minor != 0x60)
            {
                throw new NotSupportedException();
            }

            Dictionary <long, BamlRecord> recs = new Dictionary <long, BamlRecord>();

            while (str.Position < str.Length)
            {
                long           pos  = str.Position;
                BamlRecordType type = (BamlRecordType)reader.ReadByte();
                BamlRecord     rec  = null;
                switch (type)
                {
                case BamlRecordType.AssemblyInfo:
                    rec = new AssemblyInfoRecord(); break;

                case BamlRecordType.AttributeInfo:
                    rec = new AttributeInfoRecord(); break;

                case BamlRecordType.ConstructorParametersStart:
                    rec = new ConstructorParametersStartRecord(); break;

                case BamlRecordType.ConstructorParametersEnd:
                    rec = new ConstructorParametersEndRecord(); break;

                case BamlRecordType.ConstructorParameterType:
                    rec = new ConstructorParameterTypeRecord(); break;

                case BamlRecordType.ConnectionId:
                    rec = new ConnectionIdRecord(); break;

                case BamlRecordType.ContentProperty:
                    rec = new ContentPropertyRecord(); break;

                case BamlRecordType.DefAttribute:
                    rec = new DefAttributeRecord(); break;

                case BamlRecordType.DefAttributeKeyString:
                    rec = new DefAttributeKeyStringRecord(); break;

                case BamlRecordType.DefAttributeKeyType:
                    rec = new DefAttributeKeyTypeRecord(); break;

                case BamlRecordType.DeferableContentStart:
                    rec = new DeferableContentStartRecord(); break;

                case BamlRecordType.DocumentEnd:
                    rec = new DocumentEndRecord(); break;

                case BamlRecordType.DocumentStart:
                    rec = new DocumentStartRecord(); break;

                case BamlRecordType.ElementEnd:
                    rec = new ElementEndRecord(); break;

                case BamlRecordType.ElementStart:
                    rec = new ElementStartRecord(); break;

                case BamlRecordType.KeyElementEnd:
                    rec = new KeyElementEndRecord(); break;

                case BamlRecordType.KeyElementStart:
                    rec = new KeyElementStartRecord(); break;

                case BamlRecordType.LineNumberAndPosition:
                    rec = new LineNumberAndPositionRecord(); break;

                case BamlRecordType.LinePosition:
                    rec = new LinePositionRecord(); break;

                case BamlRecordType.LiteralContent:
                    rec = new LiteralContentRecord(); break;

                case BamlRecordType.NamedElementStart:
                    rec = new NamedElementStartRecord(); break;

                case BamlRecordType.OptimizedStaticResource:
                    rec = new OptimizedStaticResourceRecord(); break;

                case BamlRecordType.PIMapping:
                    rec = new PIMappingRecord(); break;

                case BamlRecordType.PresentationOptionsAttribute:
                    rec = new PresentationOptionsAttributeRecord(); break;

                case BamlRecordType.Property:
                    rec = new PropertyRecord(); break;

                case BamlRecordType.PropertyArrayEnd:
                    rec = new PropertyArrayEndRecord(); break;

                case BamlRecordType.PropertyArrayStart:
                    rec = new PropertyArrayStartRecord(); break;

                case BamlRecordType.PropertyComplexEnd:
                    rec = new PropertyComplexEndRecord(); break;

                case BamlRecordType.PropertyComplexStart:
                    rec = new PropertyComplexStartRecord(); break;

                case BamlRecordType.PropertyCustom:
                    rec = new PropertyCustomRecord(); break;

                case BamlRecordType.PropertyDictionaryEnd:
                    rec = new PropertyDictionaryEndRecord(); break;

                case BamlRecordType.PropertyDictionaryStart:
                    rec = new PropertyDictionaryStartRecord(); break;

                case BamlRecordType.PropertyListEnd:
                    rec = new PropertyListEndRecord(); break;

                case BamlRecordType.PropertyListStart:
                    rec = new PropertyListStartRecord(); break;

                case BamlRecordType.PropertyStringReference:
                    rec = new PropertyStringReferenceRecord(); break;

                case BamlRecordType.PropertyTypeReference:
                    rec = new PropertyTypeReferenceRecord(); break;

                case BamlRecordType.PropertyWithConverter:
                    rec = new PropertyWithConverterRecord(); break;

                case BamlRecordType.PropertyWithExtension:
                    rec = new PropertyWithExtensionRecord(); break;

                case BamlRecordType.PropertyWithStaticResourceId:
                    rec = new PropertyWithStaticResourceIdRecord(); break;

                case BamlRecordType.RoutedEvent:
                    rec = new RoutedEventRecord(); break;

                case BamlRecordType.StaticResourceEnd:
                    rec = new StaticResourceEndRecord(); break;

                case BamlRecordType.StaticResourceId:
                    rec = new StaticResourceIdRecord(); break;

                case BamlRecordType.StaticResourceStart:
                    rec = new StaticResourceStartRecord(); break;

                case BamlRecordType.StringInfo:
                    rec = new StringInfoRecord(); break;

                case BamlRecordType.Text:
                    rec = new TextRecord(); break;

                case BamlRecordType.TextWithConverter:
                    rec = new TextWithConverterRecord(); break;

                case BamlRecordType.TextWithId:
                    rec = new TextWithIdRecord(); break;

                case BamlRecordType.TypeInfo:
                    rec = new TypeInfoRecord(); break;

                case BamlRecordType.XmlnsProperty:
                    rec = new XmlnsPropertyRecord(); break;

                case BamlRecordType.XmlAttribute:
                case BamlRecordType.TypeSerializerInfo:
                case BamlRecordType.ProcessingInstruction:
                case BamlRecordType.LastRecordType:
                case BamlRecordType.EndAttributes:
                case BamlRecordType.DefTag:
                case BamlRecordType.ClrEvent:
                case BamlRecordType.Comment:
                default:
                    throw new NotSupportedException();
                }
                rec.Position = pos;

                rec.Read(reader);
                ret.Add(rec);
                recs.Add(pos, rec);
            }
            for (int i = 0; i < ret.Count; i++)
            {
                var defer = ret[i] as IBamlDeferRecord;
                if (defer != null)
                {
                    defer.ReadDefer(ret, i, _ => recs[_]);
                }
            }

            return(ret);
        }
Beispiel #29
0
 internal BamlRecord ReadNextRecordWithDebugExtension( 
     long           bytesAvailable,
     BamlRecordType recordType)
 {
     BamlRecord bamlRecord = BamlRecordManager.ReadNextRecord(BinaryReader, bytesAvailable, recordType); 
     if (IsDebugBamlStream)
     { 
         if (BamlRecordHelper.DoesRecordTypeHaveDebugExtension(bamlRecord.RecordType)) 
         {
             BamlRecord debugExtensionRecord = ReadDebugExtensionRecord(); 
             bamlRecord.Next = debugExtensionRecord;
         }
     }
     return bamlRecord; 
 }
        // Helper function to create a BamlRecord from a BamlRecordType
        private BamlRecord AllocateRecord(BamlRecordType recordType)
        {
            BamlRecord record;

            switch(recordType)
            {
                case BamlRecordType.DocumentStart:
                    record = new BamlDocumentStartRecord();
                    break;
                case BamlRecordType.DocumentEnd:
                    record = new BamlDocumentEndRecord();
                    break;
                case BamlRecordType.ConnectionId:
                    record = new BamlConnectionIdRecord();
                    break;
                case BamlRecordType.ElementStart:
                    record = new BamlElementStartRecord();
                    break;
                case BamlRecordType.ElementEnd:
                    record = new BamlElementEndRecord();
                    break;
                case BamlRecordType.DeferableContentStart:
                    record = new BamlDeferableContentStartRecord();
                    break;
                case BamlRecordType.DefAttributeKeyString:
                    record = new BamlDefAttributeKeyStringRecord();
                    break;
                case BamlRecordType.DefAttributeKeyType:
                    record = new BamlDefAttributeKeyTypeRecord();
                    break;
                case BamlRecordType.LiteralContent:
                    record = new BamlLiteralContentRecord();
                    break;
                case BamlRecordType.Property:
                    record = new BamlPropertyRecord();
                    break;
                case BamlRecordType.PropertyWithConverter:
                    record = new BamlPropertyWithConverterRecord();
                    break;
                case BamlRecordType.PropertyStringReference:
                    record = new BamlPropertyStringReferenceRecord();
                    break;
                case BamlRecordType.PropertyTypeReference:
                    record = new BamlPropertyTypeReferenceRecord();
                    break;
                case BamlRecordType.PropertyWithExtension:
                    record = new BamlPropertyWithExtensionRecord();
                    break;
                case BamlRecordType.PropertyCustom:
                    record = new BamlPropertyCustomRecord();
                    break;
                case BamlRecordType.PropertyComplexStart:
                    record = new BamlPropertyComplexStartRecord();
                    break;
                case BamlRecordType.PropertyComplexEnd:
                    record = new BamlPropertyComplexEndRecord();
                    break;
                case BamlRecordType.RoutedEvent:
                    record = new BamlRoutedEventRecord();
                    break;
                case BamlRecordType.PropertyArrayStart:
                    record = new BamlPropertyArrayStartRecord();
                    break;
                case BamlRecordType.PropertyArrayEnd:
                    record = new BamlPropertyArrayEndRecord();
                    break;
                case BamlRecordType.PropertyIListStart:
                    record = new BamlPropertyIListStartRecord();
                    break;
                case BamlRecordType.PropertyIListEnd:
                    record = new BamlPropertyIListEndRecord();
                    break;
                case BamlRecordType.PropertyIDictionaryStart:
                    record = new BamlPropertyIDictionaryStartRecord();
                    break;
                case BamlRecordType.PropertyIDictionaryEnd:
                    record = new BamlPropertyIDictionaryEndRecord();
                    break;
                case BamlRecordType.Text:
                    record = new BamlTextRecord();
                    break;
                case BamlRecordType.TextWithConverter:
                    record = new BamlTextWithConverterRecord();
                    break;
                case BamlRecordType.TextWithId:
                    record = new BamlTextWithIdRecord();
                    break;
                case BamlRecordType.XmlnsProperty:
                    record = new BamlXmlnsPropertyRecord();
                    break;
                case BamlRecordType.PIMapping:
                    record = new BamlPIMappingRecord();
                    break;
                case BamlRecordType.DefAttribute:
                    record = new BamlDefAttributeRecord();
                    break;
                case BamlRecordType.PresentationOptionsAttribute:
                    record = new BamlPresentationOptionsAttributeRecord();
                    break;                    
                case BamlRecordType.KeyElementStart:
                    record = new BamlKeyElementStartRecord();
                    break;
                case BamlRecordType.KeyElementEnd:
                    record = new BamlKeyElementEndRecord();
                    break;
                case BamlRecordType.ConstructorParametersStart:
                    record = new BamlConstructorParametersStartRecord();
                    break;
                case BamlRecordType.ConstructorParametersEnd:
                    record = new BamlConstructorParametersEndRecord();
                    break;
                case BamlRecordType.ConstructorParameterType:
                    record = new BamlConstructorParameterTypeRecord();
                    break;
                case BamlRecordType.ContentProperty:
                    record = new BamlContentPropertyRecord();
                    break;
                case BamlRecordType.AssemblyInfo:
                case BamlRecordType.TypeInfo:
                case BamlRecordType.TypeSerializerInfo:
                case BamlRecordType.AttributeInfo:
                case BamlRecordType.StringInfo:
                    Debug.Assert(false,"Assembly, Type and Attribute records are not cached, so don't ask for one.");
                    record = null;
                    break;
                case BamlRecordType.StaticResourceStart:
                    record = new BamlStaticResourceStartRecord();
                    break;
                case BamlRecordType.StaticResourceEnd:
                    record = new BamlStaticResourceEndRecord();
                    break;
                case BamlRecordType.StaticResourceId:
                    record = new BamlStaticResourceIdRecord();
                    break;
                case BamlRecordType.LineNumberAndPosition:
                    record = new BamlLineAndPositionRecord();
                    break;
                case BamlRecordType.LinePosition:
                    record = new BamlLinePositionRecord();
                    break;
                case BamlRecordType.OptimizedStaticResource:
                    record = new BamlOptimizedStaticResourceRecord();
                    break;
                case BamlRecordType.PropertyWithStaticResourceId:
                    record = new BamlPropertyWithStaticResourceIdRecord();
                    break;
                default:
                    Debug.Assert(false,"Unknown RecordType");
                    record = null;
                    break;
            }

            return record;
        }
Beispiel #31
0
 // Token: 0x06001DCA RID: 7626 RVA: 0x0008C619 File Offset: 0x0008A819
 internal static bool IsMapTableRecordType(BamlRecordType bamlRecordType)
 {
     return(bamlRecordType - BamlRecordType.PIMapping <= 5);
 }
Beispiel #32
0
        // Token: 0x06001DCD RID: 7629 RVA: 0x0008C658 File Offset: 0x0008A858
        internal static bool DoesRecordTypeHaveDebugExtension(BamlRecordType recordType)
        {
            switch (recordType)
            {
            case BamlRecordType.DocumentStart:
            case BamlRecordType.DocumentEnd:
            case BamlRecordType.PropertyCustom:
            case BamlRecordType.PropertyComplexEnd:
            case BamlRecordType.PropertyArrayEnd:
            case BamlRecordType.PropertyIListEnd:
            case BamlRecordType.PropertyIDictionaryEnd:
            case BamlRecordType.LiteralContent:
            case BamlRecordType.Text:
            case BamlRecordType.TextWithConverter:
            case BamlRecordType.RoutedEvent:
            case BamlRecordType.ClrEvent:
            case BamlRecordType.XmlAttribute:
            case BamlRecordType.ProcessingInstruction:
            case BamlRecordType.Comment:
            case BamlRecordType.DefTag:
            case BamlRecordType.DefAttribute:
            case BamlRecordType.EndAttributes:
            case BamlRecordType.AssemblyInfo:
            case BamlRecordType.TypeInfo:
            case BamlRecordType.TypeSerializerInfo:
            case BamlRecordType.AttributeInfo:
            case BamlRecordType.StringInfo:
            case BamlRecordType.PropertyStringReference:
            case BamlRecordType.DeferableContentStart:
            case BamlRecordType.DefAttributeKeyString:
            case BamlRecordType.DefAttributeKeyType:
            case BamlRecordType.KeyElementEnd:
            case BamlRecordType.ConstructorParametersStart:
            case BamlRecordType.ConstructorParametersEnd:
            case BamlRecordType.ConstructorParameterType:
            case BamlRecordType.NamedElementStart:
            case BamlRecordType.StaticResourceEnd:
            case BamlRecordType.StaticResourceId:
            case BamlRecordType.TextWithId:
            case BamlRecordType.LineNumberAndPosition:
            case BamlRecordType.LinePosition:
            case BamlRecordType.OptimizedStaticResource:
            case BamlRecordType.PropertyWithStaticResourceId:
                return(false);

            case BamlRecordType.ElementStart:
            case BamlRecordType.ElementEnd:
            case BamlRecordType.Property:
            case BamlRecordType.PropertyComplexStart:
            case BamlRecordType.PropertyArrayStart:
            case BamlRecordType.PropertyIListStart:
            case BamlRecordType.PropertyIDictionaryStart:
            case BamlRecordType.XmlnsProperty:
            case BamlRecordType.PIMapping:
            case BamlRecordType.PropertyTypeReference:
            case BamlRecordType.PropertyWithExtension:
            case BamlRecordType.PropertyWithConverter:
            case BamlRecordType.KeyElementStart:
            case BamlRecordType.ConnectionId:
            case BamlRecordType.ContentProperty:
            case BamlRecordType.StaticResourceStart:
            case BamlRecordType.PresentationOptionsAttribute:
                return(true);

            default:
                return(false);
            }
        }
        // This helper checks for records that indicate that you're out of
        // an element start, and into it's "content" (in the xml sense).
        // We have to infer this, because unlike Xml, Baml doesn't provide
        // an end-attributes record.

        internal static bool IsContentRecord( BamlRecordType bamlRecordType )
        {
            return bamlRecordType == BamlRecordType.PropertyComplexStart
                   ||
                   bamlRecordType == BamlRecordType.PropertyArrayStart
                   ||
                   bamlRecordType == BamlRecordType.PropertyIListStart
                   ||
                   bamlRecordType == BamlRecordType.PropertyIDictionaryStart
                   ||
                   bamlRecordType == BamlRecordType.Text;
            
        }
        // Token: 0x060020EB RID: 8427 RVA: 0x000970C0 File Offset: 0x000952C0
        public void WriteProperty(string assemblyName, string ownerTypeFullName, string propName, string value, BamlAttributeUsage propUsage)
        {
            this.VerifyWriteState();
            BamlRecordType bamlRecordType = this.PeekRecordType();

            if (bamlRecordType != BamlRecordType.ElementStart)
            {
                throw new InvalidOperationException(SR.Get("BamlWriterNoInElement", new object[]
                {
                    "WriteProperty",
                    bamlRecordType.ToString()
                }));
            }
            object obj;
            Type   declaringType;

            this.GetDpOrPi(assemblyName, ownerTypeFullName, propName, out obj, out declaringType);
            AttributeData attributeData = this._extensionParser.IsMarkupExtensionAttribute(declaringType, propName, ref value, 0, 0, 0, obj);

            if (attributeData == null)
            {
                XamlPropertyNode xamlPropertyNode = new XamlPropertyNode(0, 0, this._depth, obj, assemblyName, ownerTypeFullName, propName, value, propUsage, false);
                Type             propertyType     = XamlTypeMapper.GetPropertyType(obj);
                if (propertyType == typeof(DependencyProperty))
                {
                    Type declaringType2 = null;
                    this._dpProperty = XamlTypeMapper.ParsePropertyName(this._parserContext, value, ref declaringType2);
                    if (this._bamlRecordWriter != null && this._dpProperty != null)
                    {
                        short valueId;
                        short attributeOrTypeId = this._parserContext.MapTable.GetAttributeOrTypeId(this._bamlRecordWriter.BinaryWriter, declaringType2, this._dpProperty.Name, out valueId);
                        if (attributeOrTypeId < 0)
                        {
                            xamlPropertyNode.ValueId    = attributeOrTypeId;
                            xamlPropertyNode.MemberName = null;
                        }
                        else
                        {
                            xamlPropertyNode.ValueId    = valueId;
                            xamlPropertyNode.MemberName = this._dpProperty.Name;
                        }
                    }
                }
                else if (this._dpProperty != null)
                {
                    xamlPropertyNode.ValuePropertyType   = this._dpProperty.PropertyType;
                    xamlPropertyNode.ValuePropertyMember = this._dpProperty;
                    xamlPropertyNode.ValuePropertyName   = this._dpProperty.Name;
                    xamlPropertyNode.ValueDeclaringType  = this._dpProperty.OwnerType;
                    string fullName = this._dpProperty.OwnerType.Assembly.FullName;
                    this._dpProperty = null;
                }
                this._bamlRecordWriter.WriteProperty(xamlPropertyNode);
                return;
            }
            if (!attributeData.IsSimple)
            {
                this._extensionParser.CompileAttribute(this._markupExtensionNodes, attributeData);
                return;
            }
            if (attributeData.IsTypeExtension)
            {
                Type typeFromBaseString = this._xamlTypeMapper.GetTypeFromBaseString(attributeData.Args, this._parserContext, true);
                XamlPropertyWithTypeNode xamlPropertyWithType = new XamlPropertyWithTypeNode(0, 0, this._depth, obj, assemblyName, ownerTypeFullName, propName, typeFromBaseString.FullName, typeFromBaseString.Assembly.FullName, typeFromBaseString, string.Empty, string.Empty);
                this._bamlRecordWriter.WritePropertyWithType(xamlPropertyWithType);
                return;
            }
            XamlPropertyWithExtensionNode xamlPropertyNode2 = new XamlPropertyWithExtensionNode(0, 0, this._depth, obj, assemblyName, ownerTypeFullName, propName, attributeData.Args, attributeData.ExtensionTypeId, attributeData.IsValueNestedExtension, attributeData.IsValueTypeExtension);

            this._bamlRecordWriter.WritePropertyWithExtension(xamlPropertyNode2);
        }
 private void Push(BamlRecordType recordType, Type elementType)
 {
     CheckEndAttributes();
     _nodeTypeStack.Push(new WriteStackNode(recordType, elementType));
 }
        // Token: 0x060020EE RID: 8430 RVA: 0x000973F4 File Offset: 0x000955F4
        public void WriteDefAttribute(string name, string value)
        {
            this.VerifyWriteState();
            BamlRecordType bamlRecordType = this.PeekRecordType();

            if (bamlRecordType != BamlRecordType.ElementStart && name != "Uid")
            {
                throw new InvalidOperationException(SR.Get("BamlWriterNoInElement", new object[]
                {
                    "WriteDefAttribute",
                    bamlRecordType.ToString()
                }));
            }
            if (name == "Key")
            {
                DefAttributeData defAttributeData = this._extensionParser.IsMarkupExtensionDefAttribute(this.PeekElementType(), ref value, 0, 0, 0);
                if (defAttributeData != null)
                {
                    if (name != "Key")
                    {
                        defAttributeData.IsSimple = false;
                    }
                    if (defAttributeData.IsSimple)
                    {
                        int    num       = defAttributeData.Args.IndexOf(':');
                        string prefix    = string.Empty;
                        string localName = defAttributeData.Args;
                        if (num > 0)
                        {
                            prefix    = defAttributeData.Args.Substring(0, num);
                            localName = defAttributeData.Args.Substring(num + 1);
                        }
                        string namespaceURI = this._parserContext.XmlnsDictionary[prefix];
                        string empty        = string.Empty;
                        string empty2       = string.Empty;
                        Type   type         = null;
                        Type   type2        = null;
                        bool   elementType  = ((IParserHelper)this).GetElementType(false, localName, namespaceURI, ref empty, ref empty2, ref type, ref type2);
                        if (elementType)
                        {
                            XamlDefAttributeKeyTypeNode xamlDefNode = new XamlDefAttributeKeyTypeNode(0, 0, this._depth, empty2, type.Assembly.FullName, type);
                            this._bamlRecordWriter.WriteDefAttributeKeyType(xamlDefNode);
                        }
                        else
                        {
                            defAttributeData.IsSimple = false;
                            DefAttributeData defAttributeData2 = defAttributeData;
                            defAttributeData2.Args += "}";
                        }
                    }
                    if (!defAttributeData.IsSimple)
                    {
                        this._extensionParser.CompileDictionaryKey(this._markupExtensionNodes, defAttributeData);
                    }
                    return;
                }
            }
            XamlDefAttributeNode xamlDefNode2 = new XamlDefAttributeNode(0, 0, this._depth, name, value);

            this._bamlRecordWriter.WriteDefAttribute(xamlDefNode2);
        }
 public WriteStackNode(
     BamlRecordType   recordType)
 {
     _recordType = recordType;
     _endAttributesReached = false;
 }
Beispiel #38
0
        // Token: 0x06001EC5 RID: 7877 RVA: 0x00093A70 File Offset: 0x00091C70
        internal BamlRecord ReadNextRecord(BinaryReader bamlBinaryReader, long bytesAvailable, BamlRecordType recordType)
        {
            BamlRecord bamlRecord;

            switch (recordType)
            {
            case BamlRecordType.AssemblyInfo:
                bamlRecord = new BamlAssemblyInfoRecord();
                goto IL_A6;

            case BamlRecordType.TypeInfo:
                bamlRecord = new BamlTypeInfoRecord();
                goto IL_A6;

            case BamlRecordType.TypeSerializerInfo:
                bamlRecord = new BamlTypeInfoWithSerializerRecord();
                goto IL_A6;

            case BamlRecordType.AttributeInfo:
                bamlRecord = new BamlAttributeInfoRecord();
                goto IL_A6;

            case BamlRecordType.StringInfo:
                bamlRecord = new BamlStringInfoRecord();
                goto IL_A6;

            case BamlRecordType.DefAttributeKeyString:
                bamlRecord = new BamlDefAttributeKeyStringRecord();
                goto IL_A6;

            case BamlRecordType.DefAttributeKeyType:
                bamlRecord = new BamlDefAttributeKeyTypeRecord();
                goto IL_A6;

            case BamlRecordType.KeyElementStart:
                bamlRecord = new BamlKeyElementStartRecord();
                goto IL_A6;
            }
            bamlRecord = this._readCache[(int)recordType];
            if (bamlRecord == null || bamlRecord.IsPinned)
            {
                bamlRecord = (this._readCache[(int)recordType] = this.AllocateRecord(recordType));
            }
IL_A6:
            bamlRecord.Next = null;
            if (bamlRecord != null)
            {
                if (bamlRecord.LoadRecordSize(bamlBinaryReader, bytesAvailable) && bytesAvailable >= (long)bamlRecord.RecordSize)
                {
                    bamlRecord.LoadRecordData(bamlBinaryReader);
                }
                else
                {
                    bamlRecord = null;
                }
            }
            return(bamlRecord);
        }
 public WriteStackNode(
     BamlRecordType   recordType,
     Type             elementType) : this(recordType)
 {
     _elementType = elementType;
 }
 // Token: 0x06002101 RID: 8449 RVA: 0x00097E61 File Offset: 0x00096061
 private void Push(BamlRecordType recordType, Type elementType)
 {
     this.CheckEndAttributes();
     this._nodeTypeStack.Push(new BamlWriter.WriteStackNode(recordType, elementType));
 }
Beispiel #41
0
		void ReadRecordType()
		{
			byte type = reader.ReadByte();
			if (type < 0)
				currentType = BamlRecordType.DocumentEnd;
			else
				currentType = (BamlRecordType)type;
			
			if (currentType.ToString().EndsWith("End"))
				Debug.Unindent();
			Debug.WriteLine(string.Format("{0} (0x{0:x})", currentType));
			if (currentType.ToString().EndsWith("Start"))
				Debug.Indent();
		}
 // Token: 0x06008365 RID: 33637 RVA: 0x00244F12 File Offset: 0x00243112
 public WriteStackNode(BamlRecordType recordType, Type elementType) : this(recordType)
 {
     this._elementType = elementType;
 }
        // Helper function to create a BamlRecord from a BamlRecordType
        private BamlRecord AllocateWriteRecord(BamlRecordType recordType)
        {
            BamlRecord record;

            switch (recordType)
            {
                case BamlRecordType.PropertyCustom:
                    record = new BamlPropertyCustomWriteInfoRecord();
                    break;

                default:
                    record = AllocateRecord(recordType);
                    break;
            }

            return record;
        }
Beispiel #44
0
		static void NavigateTree(BamlDocument doc, BamlRecordType start, BamlRecordType end, ref int index) {
			index++;
			while (true) {
				if (doc[index].Type == start)
					NavigateTree(doc, start, end, ref index);
				else if (doc[index].Type == end)
					return;
				index++;
			}
		}
Beispiel #45
0
        public static BamlRecord GetRecord(BamlRecordType recordId)
        {
            BamlRecord rec = _records[(int)recordId];

            return(rec.Clone());
        }
        // Genericaly load and create the proper class.
        // This method assumes the seek pointer has already moved passed the recordType
        // field and is at the RecordSize or record contents (depending on record).
        // This method is used so the caller can first read the type of record, and expects
        // to get back the entire record, or nothing (for async support).
        internal BamlRecord ReadNextRecord(
            BinaryReader   bamlBinaryReader,
            long           bytesAvailable,
            BamlRecordType recordType)
        {
            BamlRecord bamlRecord; // = null

            // Create the proper BamlRecord based on the recordType.  The assembly,
            // type and attribute records are created every time, since they are
            // used by the BamlMapTable.  The other records are re-used, so they
            // are created once and cached.
            switch(recordType)
            {
                case BamlRecordType.AssemblyInfo:
                    bamlRecord = new BamlAssemblyInfoRecord();
                    break;
                case BamlRecordType.TypeInfo:
                    bamlRecord = new BamlTypeInfoRecord();
                    break;
                case BamlRecordType.TypeSerializerInfo:
                    bamlRecord = new BamlTypeInfoWithSerializerRecord();
                    break;
                case BamlRecordType.AttributeInfo:
                    bamlRecord = new BamlAttributeInfoRecord();
                    break;
                case BamlRecordType.StringInfo:
                    bamlRecord = new BamlStringInfoRecord();
                    break;
                case BamlRecordType.DefAttributeKeyString:
                    bamlRecord = new BamlDefAttributeKeyStringRecord();
                    break;
                case BamlRecordType.DefAttributeKeyType:
                    bamlRecord = new BamlDefAttributeKeyTypeRecord();
                    break;
                case BamlRecordType.KeyElementStart:
                    bamlRecord = new BamlKeyElementStartRecord();
                    break;

                default:

                    // Get the current record from the cache.  If there's nothing there yet,
                    // or if what is there is pinned, then create one.  Note that records in the
                    // read cache are implicitly recycled, and records in the write cache are explicitly
                    // recycled (i.e., there's a ReleaseWriteRecord, but no ReleaseReadRecord).

                    bamlRecord = _readCache[(int)recordType];
                    if (null == bamlRecord || bamlRecord.IsPinned )
                    {
                        bamlRecord = _readCache[(int)recordType] = AllocateRecord(recordType);
                    }

                    break;
            }

            bamlRecord.Next = null;

            if (null != bamlRecord)
            {
                // If LoadRecordSize indicates it can determine the record size
                // and has determined that there is enough content to load the
                // entire record, then continue.
                if (bamlRecord.LoadRecordSize(bamlBinaryReader, bytesAvailable) &&
                    bytesAvailable >= bamlRecord.RecordSize)
                {
                    bamlRecord.LoadRecordData(bamlBinaryReader);
                }
                else
                {
                    bamlRecord = null;
                }
            }

            return bamlRecord;
        }
Beispiel #47
0
        internal static bool DoesRecordTypeHaveDebugExtension(BamlRecordType recordType)
        {
            switch (recordType)
            {
            case BamlRecordType.ElementStart:
            case BamlRecordType.ElementEnd:
            case BamlRecordType.Property:
            case BamlRecordType.PropertyComplexStart:
            case BamlRecordType.PropertyArrayStart:
            case BamlRecordType.PropertyIListStart:
            case BamlRecordType.PropertyIDictionaryStart:
            case BamlRecordType.XmlnsProperty:
            case BamlRecordType.PIMapping:
            case BamlRecordType.PropertyTypeReference:
            case BamlRecordType.PropertyWithExtension:
            case BamlRecordType.PropertyWithConverter:
            case BamlRecordType.KeyElementStart:
            case BamlRecordType.ConnectionId:
            case BamlRecordType.ContentProperty:
            case BamlRecordType.StaticResourceStart:
            case BamlRecordType.PresentationOptionsAttribute:
                return(true);

            case BamlRecordType.DocumentStart:
            case BamlRecordType.DocumentEnd:                    // End record
            case BamlRecordType.PropertyCustom:                 // The "custom" size of this is a problem
            case BamlRecordType.PropertyComplexEnd:             // End record
            case BamlRecordType.PropertyArrayEnd:               // End record
            case BamlRecordType.PropertyIListEnd:               // End record
            case BamlRecordType.PropertyIDictionaryEnd:         // End record
            case BamlRecordType.LiteralContent:                 // Not needed
            case BamlRecordType.Text:                           // Not needed
            case BamlRecordType.TextWithConverter:              // Not common enough
            case BamlRecordType.RoutedEvent:                    // Not common enough
            case BamlRecordType.ClrEvent:                       // Not common enough
            case BamlRecordType.XmlAttribute:                   // Not common enough
            case BamlRecordType.ProcessingInstruction:          // Not common enough
            case BamlRecordType.Comment:                        // Not common enough
            case BamlRecordType.DefTag:                         // Not common enough
            case BamlRecordType.DefAttribute:                   // Not common enough
            case BamlRecordType.EndAttributes:                  // Not common enough
            case BamlRecordType.AssemblyInfo:                   // Info records (in general) don't advance file position
            case BamlRecordType.TypeInfo:                       // Info records (in general) don't advance file position
            case BamlRecordType.TypeSerializerInfo:             // Not common enough
            case BamlRecordType.AttributeInfo:                  // Info records (in general) don't advance file position
            case BamlRecordType.StringInfo:                     // Info records (in general) don't advance file position
            case BamlRecordType.PropertyStringReference:        // Not common enough
            case BamlRecordType.DeferableContentStart:          // This would complicate Deferable Content Size
            case BamlRecordType.ConstructorParametersStart:     // Not Needed
            case BamlRecordType.ConstructorParametersEnd:       // End record
            case BamlRecordType.ConstructorParameterType:       // Not Needed
            case BamlRecordType.NamedElementStart:              // Not common enough
            case BamlRecordType.TextWithId:                     // Not Needed
            case BamlRecordType.LineNumberAndPosition:          // This would become recursive
            case BamlRecordType.LinePosition:                   // This would become recursive
            case BamlRecordType.DefAttributeKeyString:
            case BamlRecordType.DefAttributeKeyType:
            case BamlRecordType.KeyElementEnd:
            case BamlRecordType.StaticResourceEnd:
            case BamlRecordType.StaticResourceId:
            case BamlRecordType.OptimizedStaticResource:
            case BamlRecordType.PropertyWithStaticResourceId:
                return(false);

            default:
                Debug.Assert(false, "Unhandled case in DoesRecordTypeHaveDebugExtension");
                return(false);
            }
        }