Example #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);
        }
Example #2
0
        private void ProcessBamlRecord(BamlRecord record)
        {
            _recordNumber += 1;
            if ((record.Flags & BamlRecordFlags.Start) != 0)
            {
                IndentLevel += 1;
            }
            if ((record.Flags & BamlRecordFlags.Table) != 0)
            {
                switch (record.Id)
                {
                case BamlRecordType.AssemblyInfo:
                    _assemblyInfoTable.Add((short)record.Fields[0].Value, (string)record.Fields[1].Value);
                    break;

                case BamlRecordType.TypeInfo:
                    _typeInfoTable.Add((short)record.Fields[0].Value, (string)record.Fields[2].Value);
                    break;

                case BamlRecordType.AttributeInfo:
                    _attributeInfoTable.Add((short)record.Fields[0].Value, (string)record.Fields[3].Value);
                    break;

                default:
                    //Debug.Assert(false, "Bad record in BamlRecordFlags.Table");
                    break;
                }
            }
        }
Example #3
0
 private void ProcessRecord(BamlRecord record)
 {
     switch (record.Id)
     {
     case BamlRecordType.AttributeInfo:
         ProcessAttributeInfo(record);
         break;
     }
 }
Example #4
0
        private void ProcessAttributeInfo(BamlRecord record)
        {
            System.Diagnostics.Debug.Assert(record.Fields[0].BamlFieldType == BamlFieldType.AttributeId);
            Int16 attrId = (Int16)record.Fields[0].Value;

            System.Diagnostics.Debug.Assert(record.Fields[3].BamlFieldType == BamlFieldType.Value);
            string strValue = (string)record.Fields[3].Value;

            _attributeIdMap[attrId] = strValue;
        }
Example #5
0
        public IEnumerable <String> GetLines()
        {
            DataFormatVersion version = ReadFormatVersion();

            yield return(VersionToString(version));

            while (!Done())
            {
                long       address = _reader.BaseStream.Position;
                BamlRecord record  = ReadRecord();

                if ((record.Flags & BamlRecordFlags.End) != 0)
                {
                    IndentLevel -= 1;
                }
                string indent = Indent;  // save the indent because ProcessBamlRecord() may change it.

                ProcessBamlRecord(record);

                if (record.Flags == BamlRecordFlags.Debug && !ShowDebugRecords)
                {
                    continue;
                }

                if (record.Flags == BamlRecordFlags.Table && !ShowTableRecords)
                {
                    continue;
                }

                string recNumString  = String.Format("#{0:d3}: ", _recordNumber);
                string addressString = String.Format("{0:x5}: ", address);

                string preamble = String.Empty;
                preamble += (ShowRecordNumbers) ? recNumString : String.Empty;
                preamble += (ShowAddresses) ? addressString : String.Empty;
                preamble += indent;
                yield return(preamble + RecordToString(record));
            }
        }
Example #6
0
        private string RecordToString(BamlRecord record)
        {
            StringBuilder sb = new StringBuilder();

            sb.Append(record.Id.ToString());

            for (int i = 0; i < record.Fields.Length; i++)
            {
                BamlField currentField = record.Fields[i];
                string    name         = String.Empty;
                string    valString;
                switch (currentField.BamlFieldType)
                {
                case BamlFieldType.TypeId:
                case BamlFieldType.ConverterTypeId:
                    valString = TypeIdToString((short)currentField.Value);
                    break;

                case BamlFieldType.AttributeId:
                    valString = AttributeIdToString((short)currentField.Value);
                    break;

                default:
                    valString = currentField.Value as String;
                    if (valString != null)
                    {
                        valString = ("\"" + valString + "\"");
                    }
                    else
                    {
                        valString = currentField.Value.ToString();
                    }
                    break;
                }
                sb.Append(", " + currentField.Name + "(" + valString + ")");
            }
            return(sb.ToString());
        }
Example #7
0
        static StaticBamlRecords()
        {
            BamlRecordType recordId;

            BamlField[] fields;

            _records = new BamlRecord[(int)BamlRecordType.LastRecordType];

            // DocumentStart = 1
            recordId = BamlRecordType.DocumentStart;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.LoadAsync),
                new BamlField(BamlFieldType.MaxAsyncRecords),
                new BamlField(BamlFieldType.DebugBamlStream),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // DocumentEnd = 2
            recordId = BamlRecordType.DocumentEnd;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.End, fields);

            // ElementStart = 3
            recordId = BamlRecordType.ElementStart;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.TypeId),
                new BamlField(BamlFieldType.FlagsByte),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.Start, fields);

            // ElementEnd = 4
            recordId = BamlRecordType.ElementEnd;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.End, fields);

            // Property = 5
            recordId = BamlRecordType.Property;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.AttributeId),
                new BamlField(BamlFieldType.Value),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.Table, fields);

            // PropertyCustom = 6
            recordId = BamlRecordType.PropertyCustom;
            fields   = new BamlField[]           // same interface as Property
            {
                new BamlField(BamlFieldType.AttributeId),
                new BamlField(BamlFieldType.SerializerTypeId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.Table, fields);

            // PropertyComplexStart = 7
            recordId = BamlRecordType.PropertyComplexStart;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.AttributeId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.Start, fields);

            // PropertyComplexEnd = 8
            recordId = BamlRecordType.PropertyComplexEnd;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.End, fields);

            // PropertyArrayStart = 9
            recordId = BamlRecordType.PropertyArrayStart;
            fields   = new BamlField[]         // based on ComplexPropertyStart
            {
                new BamlField(BamlFieldType.AttributeId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.Start, fields);

            // PropertyArrayEnd = 10
            recordId = BamlRecordType.PropertyArrayEnd;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.End, fields);

            // PropertyIListStart = 11
            recordId = BamlRecordType.PropertyIListStart;
            fields   = new BamlField[]         // based on ComplexPropertyStart
            {
                new BamlField(BamlFieldType.AttributeId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.Start, fields);

            // PropertyIListEnd = 12
            recordId = BamlRecordType.PropertyIListEnd;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.End, fields);

            // PropertyIDictionaryStart = 13
            recordId = BamlRecordType.PropertyIDictionaryStart;
            fields   = new BamlField[]         // based on PropertyComplexStart
            {
                new BamlField(BamlFieldType.AttributeId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.Start, fields);

            // PropertyIDictionaryEnd = 14
            recordId = BamlRecordType.PropertyIDictionaryEnd;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.End, fields);

            // LiteralContent = 15
            recordId = BamlRecordType.LiteralContent;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.Value),
                new BamlField(BamlFieldType.LineNumber),
                new BamlField(BamlFieldType.LinePosition),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.None, fields);

            // Text =16
            recordId = BamlRecordType.Text;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.Value),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.None, fields);

            // TextWithConverter = 17
            recordId = BamlRecordType.TextWithConverter;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.Value),
                new BamlField(BamlFieldType.ConverterTypeId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.None, fields);

            // RoutedEvent = 18                     UNUSED
            recordId = BamlRecordType.RoutedEvent;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.AttributeId),
                new BamlField(BamlFieldType.Value),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.None, fields);

            // ClrEvent = 19                        NOT IMPLEMENTED in Avalon
            recordId = BamlRecordType.ClrEvent;
            fields   = new BamlField[] {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // XmlnsProperty = 20
            recordId = BamlRecordType.XmlnsProperty;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.NamespacePrefix),
                new BamlField(BamlFieldType.Value),
                new BamlField(BamlFieldType.AssemblyIdList),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.Table, fields);

            // XmlAttribute = 21                     NOT IMPLEMENTED in Avalon
            recordId = BamlRecordType.XmlAttribute;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // ProcessingInstruction = 22            NOT IMPLEMENTED in Avalon
            recordId = BamlRecordType.ProcessingInstruction;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // Comment = 23                          NOT IMPLEMENTED in Avalon
            recordId = BamlRecordType.Comment;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // DefTag = 24                           NOT IMPLEMENTED in Avalon
            recordId = BamlRecordType.DefTag;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // DefAttribute = 25
            recordId = BamlRecordType.DefAttribute;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.Value),
                new BamlField(BamlFieldType.NameId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.None, fields);

            // EndAttributes = 26                    NOT IMPLEMENTED in Avalon
            recordId = BamlRecordType.EndAttributes;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // PIMapping = 27
            recordId = BamlRecordType.PIMapping;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.XmlNamespace),
                new BamlField(BamlFieldType.ClrNamespace),
                new BamlField(BamlFieldType.AssemblyId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.Table, fields);

            // AssemblyInfo = 28
            recordId = BamlRecordType.AssemblyInfo;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.AssemblyId),
                new BamlField(BamlFieldType.AssemblyFullName),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.Table, fields);

            // TypeInfo = 29
            recordId = BamlRecordType.TypeInfo;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.TypeId),
                new BamlField(BamlFieldType.AssemblyId),
                new BamlField(BamlFieldType.TypeFullName),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.Table, fields);

            // TypeSerializerInfo = 30
            recordId = BamlRecordType.TypeSerializerInfo;
            fields   = new BamlField[] //                       based on TypeInfo
            {
                new BamlField(BamlFieldType.TypeId),
                new BamlField(BamlFieldType.AssemblyId),
                new BamlField(BamlFieldType.TypeFullName),
                new BamlField(BamlFieldType.SerializerTypeId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.Table, fields);

            // AttributeInfo = 31
            recordId = BamlRecordType.AttributeInfo;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.AttributeId, "NewAttributeId"),
                new BamlField(BamlFieldType.TypeId, "OwnerTypeId"),
                new BamlField(BamlFieldType.AttributeUsage),
                new BamlField(BamlFieldType.Value, "NewAttributeValue"),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.Table, fields);

            // StringInfo = 32
            recordId = BamlRecordType.StringInfo;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.StringId),
                new BamlField(BamlFieldType.Value),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.Table, fields);

            // PropertyStringReference = 33                 UNUSED
            recordId = BamlRecordType.PropertyStringReference;
            fields   = new BamlField[]         // based on PropertyComplexStart
            {
                new BamlField(BamlFieldType.AttributeId),
                new BamlField(BamlFieldType.StringId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // PropertyTypeReference = 34
            recordId = BamlRecordType.PropertyTypeReference;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.AttributeId),
                new BamlField(BamlFieldType.TypeId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // PropertyWithExtension = 35
            recordId = BamlRecordType.PropertyWithExtension;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.AttributeId),
                new BamlField(BamlFieldType.ExtensionTypeId),
                new BamlField(BamlFieldType.ValueId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // PropertyWithConverter = 36
            recordId = BamlRecordType.PropertyWithConverter;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.AttributeId),
                new BamlField(BamlFieldType.Value),
                new BamlField(BamlFieldType.ConverterTypeId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.None, fields);

            // DeferableContentStart = 37
            recordId = BamlRecordType.DeferableContentStart;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.ContentSize),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.Table, fields);

            // DefAttributeKeyString = 38
            recordId = BamlRecordType.DefAttributeKeyString;
            fields   = new BamlField[]
            {
                // the "value" is not serialized on this record.
                new BamlField(BamlFieldType.ValueId),
                new BamlField(BamlFieldType.ValuePosition),
                new BamlField(BamlFieldType.Shared),
                new BamlField(BamlFieldType.SharedSet),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.None, fields);

            // DefAttributeKeyType = 39
            recordId = BamlRecordType.DefAttributeKeyType;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.TypeId),
                new BamlField(BamlFieldType.FlagsByte),
                new BamlField(BamlFieldType.ValuePosition),
                new BamlField(BamlFieldType.Shared),
                new BamlField(BamlFieldType.SharedSet),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // KeyElementStart = 40
            recordId = BamlRecordType.KeyElementStart;
            fields   = new BamlField[]      // same as DefAttributeKeyType
            {
                new BamlField(BamlFieldType.TypeId),
                new BamlField(BamlFieldType.ValuePosition),
                new BamlField(BamlFieldType.FlagsByte),
                new BamlField(BamlFieldType.Shared),
                new BamlField(BamlFieldType.SharedSet),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.Start, fields);

            // KeyElementEnd = 41
            recordId = BamlRecordType.KeyElementEnd;
            fields   = new BamlField[]       // same as ElementEnd
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.End, fields);

            // ConstructorParametersStart=  42
            recordId = BamlRecordType.ConstructorParametersStart;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.Start, fields);

            // ConstructorParametersEnd = 43
            recordId = BamlRecordType.ConstructorParametersEnd;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.End, fields);

            // ConstructorParameterType = 44
            recordId = BamlRecordType.ConstructorParameterType;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.TypeId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // ConnectionId = 45
            recordId = BamlRecordType.ConnectionId;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.ConnectionId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // ContentProperty = 46
            recordId = BamlRecordType.ContentProperty;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.AttributeId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // NamedElementStart = 47
            recordId = BamlRecordType.NamedElementStart;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.TypeId),
                new BamlField(BamlFieldType.RuntimeName),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.Start, fields);

            // StaticResourceStart = 48
            recordId = BamlRecordType.StaticResourceStart;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.TypeId),
                new BamlField(BamlFieldType.FlagsByte),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.Start, fields);

            // StaticResourceEnd = 49
            recordId = BamlRecordType.StaticResourceEnd;
            fields   = new BamlField[]
            {
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.End, fields);

            // StaticResourceId = 50
            recordId = BamlRecordType.StaticResourceId;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.StaticResourceId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // TextWithId = 51
            recordId = BamlRecordType.TextWithId;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.ValueId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.None, fields);

            // PresentationOptionsAttribute = 52
            recordId = BamlRecordType.PresentationOptionsAttribute;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.Value),
                new BamlField(BamlFieldType.NameId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, true, BamlRecordFlags.None, fields);

            // LineNumber = 53
            recordId = BamlRecordType.LineNumberAndPosition;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.LineNumber),
                new BamlField(BamlFieldType.LinePosition),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.Debug, fields);

            // LinePosition = 54
            recordId = BamlRecordType.LinePosition;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.LinePosition),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.Debug, fields);

            // PropertyWithStaticResourceId = 55
            recordId = BamlRecordType.PropertyWithStaticResourceId;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.AttributeId),
                new BamlField(BamlFieldType.StaticResourceId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);

            // OptimizedStaticResource = 56
            recordId = BamlRecordType.OptimizedStaticResource;
            fields   = new BamlField[]
            {
                new BamlField(BamlFieldType.FlagsByte),
                new BamlField(BamlFieldType.ValueId),
            };
            _records[(int)recordId] = new BamlRecord(recordId, false, BamlRecordFlags.None, fields);
        }
Example #8
0
        public static BamlRecord GetRecord(BamlRecordType recordId)
        {
            BamlRecord rec = _records[(int)recordId];

            return(rec.Clone());
        }