// 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); }
// Token: 0x06002070 RID: 8304 RVA: 0x000962A4 File Offset: 0x000944A4 internal override void Copy(BamlRecord record) { base.Copy(record); BamlTypeInfoRecord bamlTypeInfoRecord = (BamlTypeInfoRecord)record; bamlTypeInfoRecord._typeInfoFlags = this._typeInfoFlags; bamlTypeInfoRecord._assemblyId = this._assemblyId; bamlTypeInfoRecord._typeFullName = this._typeFullName; bamlTypeInfoRecord._type = this._type; }
// Return the Type given a type info record. The Type is cached in the info record. internal Type GetTypeFromTypeInfo(BamlTypeInfoRecord typeInfo) { if (null == typeInfo.Type) { BamlAssemblyInfoRecord assemblyInfoRecord = GetAssemblyInfoFromId(typeInfo.AssemblyId); if (null != assemblyInfoRecord) { // Check for cached type in object hash table. TypeInfoKey key = GetTypeInfoKey(assemblyInfoRecord.AssemblyFullName, typeInfo.TypeFullName); BamlTypeInfoRecord cachedTypeInfo = GetHashTableData(key) as BamlTypeInfoRecord; if (cachedTypeInfo != null && cachedTypeInfo.Type != null) { typeInfo.Type = cachedTypeInfo.Type; } else { Assembly assembly = GetAssemblyFromAssemblyInfo(assemblyInfoRecord); if (null != assembly) { Type type = assembly.GetType(typeInfo.TypeFullName); typeInfo.Type = type; AddHashTableData(key, typeInfo); } } } } return typeInfo.Type; }
// Return a type info record for a type identified by the passed ID. If the // ID is negative, then this is a known type, so manufacture a BamlTypeInfoRecord // for it. internal BamlTypeInfoRecord GetTypeInfoFromId(short id) { // If the id is less than 0, it is a known type that lives in the // known assembly, so manufacture a type info record for it. if (id < 0) { // For some types, we create a TypeInfo record with serializer information. For // all other types, we create a regular TypeInfo record. // NOTE: When serializers are publically extensible, then this should be // reflected for as part of the KnownElementsInitializer. BamlTypeInfoRecord info; if (-id == (short)KnownElements.Style) { info = new BamlTypeInfoWithSerializerRecord(); ((BamlTypeInfoWithSerializerRecord)info).SerializerTypeId = -(int) KnownElements.XamlStyleSerializer; ((BamlTypeInfoWithSerializerRecord)info).SerializerType = KnownTypes.Types[(int)KnownElements.XamlStyleSerializer]; info.AssemblyId = -1; } else if (-id == (short)KnownElements.ControlTemplate || -id == (short)KnownElements.DataTemplate || -id == (short)KnownElements.HierarchicalDataTemplate || -id == (short)KnownElements.ItemsPanelTemplate) { info = new BamlTypeInfoWithSerializerRecord(); ((BamlTypeInfoWithSerializerRecord)info).SerializerTypeId = -(int) KnownElements.XamlTemplateSerializer; ((BamlTypeInfoWithSerializerRecord)info).SerializerType = KnownTypes.Types[(int)KnownElements.XamlTemplateSerializer]; info.AssemblyId = -1; } else { // Search the Assembly table to see if this type has a match. If not, then // we know that it is a known assembly for an Avalon known type. We have to do // this since some of the known types are not avalon types, such as Bool, Object, // Double, and others... info = new BamlTypeInfoRecord(); info.AssemblyId = GetAssemblyIdForType(KnownTypes.Types[-id]); } info.TypeId = id; info.Type = KnownTypes.Types[-id]; info.TypeFullName = info.Type.FullName; return info; } else { return (BamlTypeInfoRecord) TypeIdMap[id]; } }
// Add an already-loaded type info record to the map table. This can // only be appended to the end of the existing map. If it is the same // as an existing record, ensure we're not trying to overwrite something. internal void LoadTypeInfoRecord(BamlTypeInfoRecord record) { Debug.Assert(TypeIdMap.Count == record.TypeId || record.TypeFullName == ((BamlTypeInfoRecord)TypeIdMap[record.TypeId]).TypeFullName); if (TypeIdMap.Count == record.TypeId) { TypeIdMap.Add(record); } }
// Return the Type ID for the passed typeFullName by creating a new record and adding // it to the type info hashtable. A BamlTypeInfoRecord is created if there is no serializer // for this type, and a BamlTypeInfoWithSerializerRecord is created if there is a serializer. internal short AddTypeInfoMap(BinaryWriter binaryWriter, string assemblyFullName, string typeFullName, Type elementType, string serializerAssemblyFullName, string serializerTypeFullName) { TypeInfoKey key = GetTypeInfoKey(assemblyFullName, typeFullName); BamlTypeInfoRecord bamlTypeInfoRecord; // Create either a normal TypeInfo record, or a TypeInfoWithSerializer record, depending // on whether or not there is a serializer for this type. if (serializerTypeFullName == string.Empty) { bamlTypeInfoRecord = new BamlTypeInfoRecord(); } else { bamlTypeInfoRecord = new BamlTypeInfoWithSerializerRecord(); short serializerTypeId; // If we do not already have a type record for the serializer associated with // this type, then recurse and write out the serializer assembly and type first. if (!GetTypeInfoId(binaryWriter, serializerAssemblyFullName, serializerTypeFullName, out serializerTypeId)) { serializerTypeId = AddTypeInfoMap(binaryWriter, serializerAssemblyFullName, serializerTypeFullName, null, string.Empty, string.Empty); } ((BamlTypeInfoWithSerializerRecord)bamlTypeInfoRecord).SerializerTypeId = serializerTypeId; } bamlTypeInfoRecord.TypeFullName = typeFullName; // get id for assembly BamlAssemblyInfoRecord bamlAssemblyInfoRecord = AddAssemblyMap(binaryWriter, assemblyFullName); bamlTypeInfoRecord.AssemblyId = bamlAssemblyInfoRecord.AssemblyId; bamlTypeInfoRecord.IsInternalType = (elementType != null && ReflectionHelper.IsInternalType(elementType)); // review, could be a race condition here. bamlTypeInfoRecord.TypeId = (short) TypeIdMap.Add(bamlTypeInfoRecord); // add to the hash ObjectHashTable.Add(key,bamlTypeInfoRecord); // Write to BAML bamlTypeInfoRecord.Write(binaryWriter); return bamlTypeInfoRecord.TypeId; }
/***************************************************************************\ * * BamlReader.GetAssemblyAndPrefixAndXmlns * * Get a namespace prefix and the associated Xml namespace for a given type. * If none, return empty strings. * \***************************************************************************/ private void GetAssemblyAndPrefixAndXmlns( BamlTypeInfoRecord typeInfo, out string assemblyFullName, out string prefix, out string xmlns) { // If the typeInfo indicates the type is NOT a core Avalon type, then the // assembly should be in the Assembly table of the BamlMapTable. Otherwise // we have to get the Assembly information from the actual type. if (typeInfo.AssemblyId >= 0 || typeInfo.Type == null) { BamlAssemblyInfoRecord assyInfo = MapTable.GetAssemblyInfoFromId( typeInfo.AssemblyId); assemblyFullName = assyInfo.AssemblyFullName; } else { Assembly typeAssembly = typeInfo.Type.Assembly; assemblyFullName = typeAssembly.FullName; } // Look through the mapping table for an xml namespace that matches // the assembly and type namespace. // Note that it may be one of the known namespaces, such as the definition // namespace so check for that first. if (typeInfo.ClrNamespace == "System.Windows.Markup" && (assemblyFullName.StartsWith("PresentationFramework", StringComparison.Ordinal) || assemblyFullName.StartsWith("System.Xaml", StringComparison.Ordinal))) { xmlns = XamlReaderHelper.DefinitionNamespaceURI; } else { // XamlTypeMapper only stored MappingPI Xml Namesaces xmlns = _parserContext.XamlTypeMapper.GetXmlNamespace( typeInfo.ClrNamespace, assemblyFullName); // Now check our own private list for URI based Xml Namespaces if(String.IsNullOrEmpty(xmlns)) { List<String> xmlnsList = GetXmlNamespaceList(typeInfo.ClrNamespace, assemblyFullName); prefix = GetXmlnsPrefix(xmlnsList); return; } } prefix = GetXmlnsPrefix(xmlns); }