/***************************************************************************\ * * BamlReader.SetCommonPropertyInfo * * Get information that is common to all types of property records and * fill in the passed node info record with this information. * Return the attribute info found. * \***************************************************************************/ private BamlAttributeInfoRecord SetCommonPropertyInfo( BamlNodeInfo nodeInfo, short attrId) { BamlAttributeInfoRecord attrInfo = MapTable.GetAttributeInfoFromId(attrId); BamlTypeInfoRecord typeInfo = MapTable.GetTypeInfoFromId(attrInfo.OwnerTypeId); // Fill node info record with this data. nodeInfo.LocalName = attrInfo.Name; nodeInfo.Name = typeInfo.TypeFullName + "." + nodeInfo.LocalName; string assembly, prefix, namespaceUri; GetAssemblyAndPrefixAndXmlns(typeInfo, out assembly, out prefix, out namespaceUri); nodeInfo.AssemblyName = assembly; nodeInfo.Prefix = prefix; nodeInfo.XmlNamespace = namespaceUri; nodeInfo.ClrNamespace = typeInfo.ClrNamespace; nodeInfo.AttributeUsage = attrInfo.AttributeUsage; return attrInfo; }
/***************************************************************************\ * * BamlReader.ReadConstructorStart * * Read a <x:ConstructorParameters ... > start tag, which indicates that * the following objects are to be used as constructor parameters. * \***************************************************************************/ private void ReadConstructorStart() { ClearProperties(); NodeTypeInternal = BamlNodeType.StartConstructor; // Push information on the node stack to indicate we have a start array BamlNodeInfo nodeInfo = new BamlNodeInfo(); nodeInfo.RecordType = BamlRecordType.ConstructorParametersStart; _nodeStack.Push(nodeInfo); }
/***************************************************************************\ * * BamlReader.ReadElementStartRecord * * Read the start of an element. This is either a CLR or DependencyObject * that is part of an object tree. * \***************************************************************************/ private void ReadElementStartRecord() { ClearProperties(); _propertyDP = null; _parserContext.PushScope(); _prefixDictionary.PushScope(); BamlElementStartRecord bamlRecord = (BamlElementStartRecord)_currentBamlRecord; BamlTypeInfoRecord typeInfo = MapTable.GetTypeInfoFromId(bamlRecord.TypeId); NodeTypeInternal = BamlNodeType.StartElement; _name = typeInfo.TypeFullName; _localName = _name.Substring(_name.LastIndexOf(".", StringComparison.Ordinal) + 1); _ownerTypeName = string.Empty; _clrNamespace = typeInfo.ClrNamespace; GetAssemblyAndPrefixAndXmlns(typeInfo, out _assemblyName, out _prefix, out _xmlNamespace); // Push information on the node stack to indicate we have a start element BamlNodeInfo nodeInfo = new BamlNodeInfo(); nodeInfo.Name = _name; nodeInfo.LocalName = _localName; nodeInfo.AssemblyName = _assemblyName; nodeInfo.Prefix = _prefix; nodeInfo.ClrNamespace = _clrNamespace; nodeInfo.XmlNamespace = _xmlNamespace; nodeInfo.RecordType = BamlRecordType.ElementStart; _useTypeConverter = bamlRecord.CreateUsingTypeConverter; _isInjected = bamlRecord.IsInjected; // If we are in a deferable block, then see if this is a top level element for // that block that matches an offset in the list of defered dictionary keys. If // so, then insert a x:Key="keystring" to make this appear like a normal // dictionary. if (_deferableContentBlockDepth == _nodeStack.Count) { // Calculate the offset for the start of the current element record in // the baml stream. Int32 offset = (Int32)(_bamlRecordReader.StreamPosition - _deferableContentPosition); // Subtract off the size of the current Record. offset -= bamlRecord.RecordSize + BamlRecord.RecordTypeFieldLength; // If there is a debug extension record then subtract that off also. if (BamlRecordHelper.HasDebugExtensionRecord(_parserContext.IsDebugBamlStream, bamlRecord)) { BamlRecord bamlDebugRecord = bamlRecord.Next; offset -= bamlDebugRecord.RecordSize + BamlRecord.RecordTypeFieldLength; } InsertDeferedKey(offset); } _nodeStack.Push(nodeInfo); // Read the properties that may be part of the start tag of this element ReadProperties(); }
/***************************************************************************\ * * BamlReader.ReadPropertyComplexStartRecord * * Read the start of a complex property. This can be any type of complex * property, including arrays, ILists, IDictionaries, Clr properties or * dependency properties. * \***************************************************************************/ private void ReadPropertyComplexStartRecord() { ClearProperties(); _parserContext.PushScope(); _prefixDictionary.PushScope(); BamlNodeInfo nodeInfo = new BamlNodeInfo(); SetCommonPropertyInfo(nodeInfo, ((BamlPropertyComplexStartRecord)_currentBamlRecord).AttributeId); // Set instance variables to node info extracted from record. NodeTypeInternal = BamlNodeType.StartComplexProperty; _localName = nodeInfo.LocalName; int index = nodeInfo.Name.LastIndexOf(".", StringComparison.Ordinal); if (index > 0) { _ownerTypeName = nodeInfo.Name.Substring(0, index); } else { // Eg. xmlns property _ownerTypeName = string.Empty; } _name = nodeInfo.Name; _clrNamespace = nodeInfo.ClrNamespace; _assemblyName = nodeInfo.AssemblyName; _prefix = nodeInfo.Prefix; _xmlNamespace = nodeInfo.XmlNamespace; nodeInfo.RecordType = _currentBamlRecord.RecordType; _nodeStack.Push(nodeInfo); // Read the properties that may be part of the start tag ReadProperties(); }
/***************************************************************************\ * * BamlReader.ReadDocumentStartRecord * * Read the start of the document record. This should contain some * version information. * \***************************************************************************/ private void ReadDocumentStartRecord() { ClearProperties(); NodeTypeInternal = BamlNodeType.StartDocument; BamlDocumentStartRecord documentStartRecord = (BamlDocumentStartRecord)_currentBamlRecord; _parserContext.IsDebugBamlStream = documentStartRecord.DebugBaml; // Push information on the node stack to indicate we have a start document BamlNodeInfo nodeInfo = new BamlNodeInfo(); nodeInfo.RecordType = BamlRecordType.DocumentStart; _nodeStack.Push(nodeInfo); }