/***************************************************************************\ * * BamlReader.ReadPropertyRecordCore * * Read the property record and return the pertinent contents in a * BamlPropertyInfo record. * \***************************************************************************/ private BamlPropertyInfo ReadPropertyRecordCore(string value) { BamlPropertyInfo info = new BamlPropertyInfo(); SetCommonPropertyInfo(info, ((BamlPropertyRecord)_currentBamlRecord).AttributeId); info.RecordType = _currentBamlRecord.RecordType; info.Value = value; return info; }
private BamlPropertyInfo GetPropertyCustomRecordInfo() { BamlPropertyInfo info = new BamlPropertyInfo(); BamlAttributeInfoRecord attrInfo = SetCommonPropertyInfo(info, ((BamlPropertyCustomRecord)_currentBamlRecord).AttributeId); info.RecordType = _currentBamlRecord.RecordType; info.AttributeUsage = BamlAttributeUsage.Default; BamlPropertyCustomRecord bamlRecord = (BamlPropertyCustomRecord)_currentBamlRecord; // Reverse the binary data stored in the record into a string by first getting the // property. If it has not already been cached in the attribute info record, then // attempt to resolve it as a DependencyProperty or a PropertyInfo. if (attrInfo.DP == null && attrInfo.PropInfo == null) { attrInfo.DP = MapTable.GetDependencyProperty(attrInfo); if (attrInfo.OwnerType == null) { throw new InvalidOperationException(SR.Get(SRID.BamlReaderNoOwnerType, attrInfo.Name, AssemblyName)); } if (attrInfo.DP == null) { try { attrInfo.PropInfo = attrInfo.OwnerType.GetProperty(attrInfo.Name, BindingFlags.Instance | BindingFlags.Public); } catch (AmbiguousMatchException) { // Handle ambiguous match just like XamlTypeMapper.PropertyInfoFromName does. // This is for consistency, although it's probably wrong. // The doc for GetProperties says: // The GetProperties method does not return properties // in a particular order, such as alphabetical or // declaration order. Your code must not depend on the // order in which properties are returned, because that // order varies. // It's probably more correct to walk up the base class // tree calling GetProperty with the DeclaredOnly flag. PropertyInfo[] infos = attrInfo.OwnerType.GetProperties( BindingFlags.Instance | BindingFlags.Public); for (int i = 0; i < infos.Length; i++) { if (infos[i].Name == attrInfo.Name) { attrInfo.PropInfo = infos[i]; break; } } } if (attrInfo.PropInfo == null) { throw new InvalidOperationException(SR.Get(SRID.ParserCantGetDPOrPi, info.Name)); } } } // If we have a property, then get its type and call GetCustomValue, // which uses the XamlSerializer to turn the binary data into a // real object Type propertyType = attrInfo.GetPropertyType(); string propertyName = attrInfo.Name; short sid = bamlRecord.SerializerTypeId; // if a Setter of Trigger's Property property is being set, then its value is always // a DP. Get the attribInfo of this DP property from the ValueId read into the custom // property record and resolve it into an actual DP instance. if (sid == (short)KnownElements.DependencyPropertyConverter) { Type declaringType = null; _propertyDP = _bamlRecordReader.GetCustomDependencyPropertyValue(bamlRecord, out declaringType); declaringType = declaringType == null ? _propertyDP.OwnerType : declaringType; info.Value = declaringType.Name + "." + _propertyDP.Name; string xmlns = _parserContext.XamlTypeMapper.GetXmlNamespace(declaringType.Namespace, declaringType.Assembly.FullName); string prefix = GetXmlnsPrefix(xmlns); if (prefix != string.Empty) { info.Value = prefix + ":" + info.Value; } if (!_propertyDP.PropertyType.IsEnum) { _propertyDP = null; } } else { if (_propertyDP != null) { propertyType = _propertyDP.PropertyType; propertyName = _propertyDP.Name; _propertyDP = null; } object value = _bamlRecordReader.GetCustomValue(bamlRecord, propertyType, propertyName); // Once we have a real object, turn that back into a string, and store this // as the value for this property TypeConverter converter = TypeDescriptor.GetConverter(value.GetType()); info.Value = converter.ConvertToString(null, TypeConverterHelper.InvariantEnglishUS, value); } return info; }
private void ReadPropertyWithExtensionRecord() { BamlPropertyInfo info = new BamlPropertyInfo(); SetCommonPropertyInfo(info, ((BamlPropertyWithExtensionRecord)_currentBamlRecord).AttributeId); info.RecordType = _currentBamlRecord.RecordType; info.Value = GetExtensionValueString((IOptimizedMarkupExtension)_currentBamlRecord); info.AttributeUsage = BamlAttributeUsage.Default; AddToPropertyInfoCollection(info); }
private void ReadPropertyWithStaticResourceIdRecord() { BamlPropertyWithStaticResourceIdRecord bamlPropertyWithStaticResourceIdRecord = (BamlPropertyWithStaticResourceIdRecord)_currentBamlRecord; BamlPropertyInfo info = new BamlPropertyInfo(); SetCommonPropertyInfo(info, bamlPropertyWithStaticResourceIdRecord.AttributeId); info.RecordType = _currentBamlRecord.RecordType; BamlOptimizedStaticResourceRecord optimizedStaticResourceRecord = (BamlOptimizedStaticResourceRecord)_currentKeyInfo.StaticResources[bamlPropertyWithStaticResourceIdRecord.StaticResourceId][0]; info.Value = GetExtensionValueString((IOptimizedMarkupExtension)optimizedStaticResourceRecord); info.AttributeUsage = BamlAttributeUsage.Default; AddToPropertyInfoCollection(info); }
/***************************************************************************\ * * BamlReader.ReadXmlnsPropertyRecord * * Read the namespace record and update the namespace dictionary with the * key being the namespace prefix and the value being the namespace string. * Note that Xmlns properties are not the same as regular properties, since * prefix, xmlnamespace, clrnamespace and name have quite different meanings. * \***************************************************************************/ private void ReadXmlnsPropertyRecord() { BamlXmlnsPropertyRecord bamlRecord = (BamlXmlnsPropertyRecord)_currentBamlRecord; _parserContext.XmlnsDictionary[bamlRecord.Prefix] = bamlRecord.XmlNamespace; _prefixDictionary[bamlRecord.XmlNamespace] = bamlRecord.Prefix; BamlPropertyInfo info = new BamlPropertyInfo(); info.Value = bamlRecord.XmlNamespace; info.XmlNamespace = string.Empty; info.ClrNamespace = string.Empty; info.AssemblyName = string.Empty; info.Prefix = "xmlns"; info.LocalName = bamlRecord.Prefix == null ? string.Empty : bamlRecord.Prefix; info.Name = (bamlRecord.Prefix == null || bamlRecord.Prefix == string.Empty) ? "xmlns" : "xmlns:" + bamlRecord.Prefix; info.RecordType = BamlRecordType.XmlnsProperty; AddToPropertyInfoCollection(info); }
/***************************************************************************\ * * BamlReader.ReadPropertyTypeRecord * * Read the property record and store the pertinent contents in the * _properties array list. Convert the TypeId into a fully qualified type * name. * \***************************************************************************/ private void ReadPropertyTypeRecord() { BamlPropertyInfo info = new BamlPropertyInfo(); SetCommonPropertyInfo(info, ((BamlPropertyTypeReferenceRecord)_currentBamlRecord).AttributeId); info.RecordType = _currentBamlRecord.RecordType; info.Value = GetTypeValueString(((BamlPropertyTypeReferenceRecord)_currentBamlRecord).TypeId); info.AttributeUsage = BamlAttributeUsage.Default; AddToPropertyInfoCollection(info); }
/***************************************************************************\ * * BamlReader.InsertDeferedKey * * Search the _deferedKeys list for a dictionary key that has the same offset * as the current baml stream position. If one is found, generate a * def attribute record to simulate a dictionary key. * \***************************************************************************/ private void InsertDeferedKey(Int32 valueOffset) { if (_deferKeys == null) { return; } BamlKeyInfo keyInfo = _deferKeys[0]; while (keyInfo.Offset == valueOffset) { // Remember the _currentKeyInfo so that we can use it to resolve StaticResourceId // records that may occur within the corresponding value. _currentKeyInfo = keyInfo; BamlPropertyInfo info = new BamlPropertyInfo(); info.Value = keyInfo.Value; info.AssemblyName = string.Empty; info.Prefix = (string)_prefixDictionary[XamlReaderHelper.DefinitionNamespaceURI]; info.XmlNamespace = XamlReaderHelper.DefinitionNamespaceURI; info.ClrNamespace = string.Empty; info.Name = keyInfo.Name; info.LocalName = info.Name; info.RecordType = BamlRecordType.DefAttribute; AddToPropertyInfoCollection(info); // We no longer need this key record, so remove it to make subsequent // searches faster. _deferKeys.RemoveAt(0); if (_deferKeys.Count > 0) { keyInfo = _deferKeys[0]; } else { return; } } }
/***************************************************************************\ * * BamlReader.ReadDefAttributeKeyTypeRecord * * Read a x: record that contains the object to use as a key when inserting * the current element into a dictionary. * \***************************************************************************/ private void ReadDefAttributeKeyTypeRecord() { BamlDefAttributeKeyTypeRecord bamlRecord = (BamlDefAttributeKeyTypeRecord)_currentBamlRecord; BamlPropertyInfo info = new BamlPropertyInfo(); info.Value = GetTypeValueString(bamlRecord.TypeId); info.AssemblyName = string.Empty; info.Prefix = (string)_prefixDictionary[XamlReaderHelper.DefinitionNamespaceURI]; info.XmlNamespace = XamlReaderHelper.DefinitionNamespaceURI; info.ClrNamespace = string.Empty; info.Name = XamlReaderHelper.DefinitionName; info.LocalName = info.Name; info.RecordType = BamlRecordType.DefAttribute; AddToPropertyInfoCollection(info); }
/***************************************************************************\ * * BamlReader.ReadPresentationOptionsAttributeRecord * * Read a PresentationsOptions: record used for WPF-specific * parsing options (e.g., PresentationOptions:Freeze). * \***************************************************************************/ private void ReadPresentationOptionsAttributeRecord() { BamlPresentationOptionsAttributeRecord bamlRecord = (BamlPresentationOptionsAttributeRecord)_currentBamlRecord; bamlRecord.Name = MapTable.GetStringFromStringId(bamlRecord.NameId); BamlPropertyInfo info = new BamlPropertyInfo(); info.Value = bamlRecord.Value; info.AssemblyName = string.Empty; info.Prefix = (string)_prefixDictionary[XamlReaderHelper.PresentationOptionsNamespaceURI]; info.XmlNamespace = XamlReaderHelper.PresentationOptionsNamespaceURI; info.ClrNamespace = string.Empty; info.Name = bamlRecord.Name; info.LocalName = info.Name; info.RecordType = BamlRecordType.PresentationOptionsAttribute; AddToPropertyInfoCollection(info); }
internal PropertyNameMap(BamlPropertyInfo bamlNode, string name) { _bamlNode = bamlNode; _name = name; }
private BamlPropertyInfo GetPropertyCustomRecordInfo() { BamlPropertyInfo info = new BamlPropertyInfo(); BamlAttributeInfoRecord attrInfo = SetCommonPropertyInfo(info, ((BamlPropertyCustomRecord)_currentBamlRecord).AttributeId); info.RecordType = _currentBamlRecord.RecordType; info.AttributeUsage = BamlAttributeUsage.Default; BamlPropertyCustomRecord bamlRecord = (BamlPropertyCustomRecord)_currentBamlRecord; // Reverse the binary data stored in the record into a string by first getting the // property. If it has not already been cached in the attribute info record, then // attempt to resolve it as a DependencyProperty or a PropertyInfo. if (attrInfo.DP == null && attrInfo.PropInfo == null) { attrInfo.DP = MapTable.GetDependencyProperty(attrInfo); if (attrInfo.OwnerType == null) { throw new InvalidOperationException(SR.Get(SRID.BamlReaderNoOwnerType, attrInfo.Name, AssemblyName)); } if (attrInfo.DP == null) { attrInfo.PropInfo = attrInfo.OwnerType.GetProperty(attrInfo.Name, BindingFlags.Instance | BindingFlags.Public); if (attrInfo.PropInfo == null) { throw new InvalidOperationException(SR.Get(SRID.ParserCantGetDPOrPi, info.Name)); } } } // If we have a property, then get its type and call GetCustomValue, // which uses the XamlSerializer to turn the binary data into a // real object Type propertyType = attrInfo.GetPropertyType(); string propertyName = attrInfo.Name; short sid = bamlRecord.SerializerTypeId; // if a Setter of Trigger's Property property is being set, then its value is always // a DP. Get the attribInfo of this DP property from the ValueId read into the custom // property record and resolve it into an actual DP instance. if (sid == (short)KnownElements.DependencyPropertyConverter) { Type declaringType = null; _propertyDP = _bamlRecordReader.GetCustomDependencyPropertyValue(bamlRecord, out declaringType); declaringType = declaringType == null ? _propertyDP.OwnerType : declaringType; info.Value = declaringType.Name + "." + _propertyDP.Name; string xmlns = _parserContext.XamlTypeMapper.GetXmlNamespace(declaringType.Namespace, declaringType.Assembly.FullName); string prefix = GetXmlnsPrefix(xmlns); if (prefix != string.Empty) { info.Value = prefix + ":" + info.Value; } if (!_propertyDP.PropertyType.IsEnum) { _propertyDP = null; } } else { if (_propertyDP != null) { propertyType = _propertyDP.PropertyType; propertyName = _propertyDP.Name; _propertyDP = null; } object value = _bamlRecordReader.GetCustomValue(bamlRecord, propertyType, propertyName); // Once we have a real object, turn that back into a string, and store this // as the value for this property TypeConverter converter = TypeDescriptor.GetConverter(value.GetType()); info.Value = converter.ConvertToString(null, TypeConverterHelper.InvariantEnglishUS, value); } return info; }