Beispiel #1
0
 /// <summary>
 /// Write out a key to a dictionary that has been resolved at compile or parse
 /// time to a Type object.
 /// </summary>
 public virtual void WriteDefAttributeKeyType(XamlDefAttributeKeyTypeNode xamlDefNode)
 {
     if (BamlRecordWriter != null)
     {
         BamlRecordWriter.WriteDefAttributeKeyType(xamlDefNode);
     }
 }
 /// <summary>
 /// Write out a key to a dictionary that has been resolved at compile or parse 
 /// time to a Type object.
 /// </summary>
 public override void WriteDefAttributeKeyType(XamlDefAttributeKeyTypeNode xamlDefNode)
 { 
     // Remember that x:Key was read in, since this key has precedence over
     // the TargetType="{x:Type SomeType}" key that may also be present. 
     if (_styleModeStack.Mode == StyleMode.Base) 
     {
         _defNameFound = true; 
     }
     base.WriteDefAttributeKeyType(xamlDefNode);
 }
        // Write an x:Key="value" where value has been resolved to a Type object
        // at compile or parse time.  This means less reflection at runtime.
        internal void WriteDefAttributeKeyType(XamlDefAttributeKeyTypeNode xamlDefNode)
        {
            Debug.Assert(!InStaticResourceSection, "We do not support x:Key within a StaticResource Section");

            // If we do not already have a type record for the type of this key,
            // then add a new TypeInfo record to the map table.
            short typeId;
            if (!MapTable.GetTypeInfoId(BinaryWriter,
                                        xamlDefNode.AssemblyName,
                                        xamlDefNode.Value,
                                        out typeId))
            {
                typeId = MapTable.AddTypeInfoMap(BinaryWriter,
                                                 xamlDefNode.AssemblyName,
                                                 xamlDefNode.Value,
                                                 xamlDefNode.ValueType,
                                                 string.Empty,
                                                 string.Empty);
            }


            BamlDefAttributeKeyTypeRecord bamlDefRecord = BamlRecordManager.GetWriteRecord(
                                                          BamlRecordType.DefAttributeKeyType)
                                                          as BamlDefAttributeKeyTypeRecord;

            bamlDefRecord.TypeId = typeId;
            ((IBamlDictionaryKey)bamlDefRecord).KeyObject = xamlDefNode.ValueType;

            // If we are currently parsing a deferable content section then store it
            // in the keys collection.
            if (_deferLoadingSupport &&
                _deferElementDepth == 2)
            {
                KeyDeferRecord keyRecord = (KeyDeferRecord)(_deferKeys[_deferKeys.Count-1]);

                TransferOldSharedData(keyRecord.Record as IBamlDictionaryKey, bamlDefRecord as IBamlDictionaryKey);
                keyRecord.Record = bamlDefRecord;

                keyRecord.LineNumber = xamlDefNode.LineNumber;
                keyRecord.LinePosition = xamlDefNode.LinePosition;
                return;
            }

            if (_deferLoadingSupport && _deferElementDepth > 0)
            {
                _deferValues.Add(new ValueDeferRecord(bamlDefRecord,
                                            xamlDefNode.LineNumber,
                                            xamlDefNode.LinePosition));
            }
            else
            {
                WriteBamlRecord(bamlDefRecord, xamlDefNode.LineNumber,
                                    xamlDefNode.LinePosition);

                BamlRecordManager.ReleaseWriteRecord(bamlDefRecord);
            }
        }