Esempio n. 1
0
        // Token: 0x0600237C RID: 9084 RVA: 0x000AD4B8 File Offset: 0x000AB6B8
        internal override object GetDictionaryKey(BamlRecord startRecord, ParserContext parserContext)
        {
            object     obj        = null;
            int        num        = 0;
            BamlRecord bamlRecord = startRecord;
            short      num2       = 0;

            while (bamlRecord != null)
            {
                if (bamlRecord.RecordType == BamlRecordType.ElementStart)
                {
                    BamlElementStartRecord bamlElementStartRecord = bamlRecord as BamlElementStartRecord;
                    if (++num != 1)
                    {
                        break;
                    }
                    num2 = bamlElementStartRecord.TypeId;
                }
                else if (bamlRecord.RecordType == BamlRecordType.Property && num == 1)
                {
                    BamlPropertyRecord bamlPropertyRecord = bamlRecord as BamlPropertyRecord;
                    short              num3;
                    string             a;
                    BamlAttributeUsage bamlAttributeUsage;
                    parserContext.MapTable.GetAttributeInfoFromId(bamlPropertyRecord.AttributeId, out num3, out a, out bamlAttributeUsage);
                    if (num3 == num2)
                    {
                        if (a == "TargetType")
                        {
                            obj = parserContext.XamlTypeMapper.GetDictionaryKey(bamlPropertyRecord.Value, parserContext);
                        }
                        else if (a == "DataType")
                        {
                            object    dictionaryKey = parserContext.XamlTypeMapper.GetDictionaryKey(bamlPropertyRecord.Value, parserContext);
                            Exception ex            = TemplateKey.ValidateDataType(dictionaryKey, null);
                            if (ex != null)
                            {
                                this.ThrowException("TemplateBadDictionaryKey", parserContext.LineNumber, parserContext.LinePosition, ex);
                            }
                            obj = new DataTemplateKey(dictionaryKey);
                        }
                    }
                }
                else if (bamlRecord.RecordType == BamlRecordType.PropertyComplexStart || bamlRecord.RecordType == BamlRecordType.PropertyIListStart || bamlRecord.RecordType == BamlRecordType.ElementEnd)
                {
                    break;
                }
                bamlRecord = bamlRecord.Next;
            }
            if (obj == null)
            {
                this.ThrowException("StyleNoDictionaryKey", parserContext.LineNumber, parserContext.LinePosition, null);
            }
            return(obj);
        }
        /// <summary>
        ///   If the Template represented by a group of baml records is stored in a dictionary, this
        ///   method will extract the key used for this dictionary from the passed
        ///   collection of baml records.  For ControlTemplate, this is the styleTargetType.
        ///   For DataTemplate, this is the DataTemplateKey containing the DataType.
        /// </summary>
        //CASRemoval:[StrongNameIdentityPermission(SecurityAction.InheritanceDemand, PublicKey = Microsoft.Internal.BuildInfo.WCP_PUBLIC_KEY_STRING)]
        internal override object GetDictionaryKey(BamlRecord startRecord, ParserContext parserContext)
        {
            object     key = null;
            int        numberOfElements = 0;
            BamlRecord record           = startRecord;
            short      ownerTypeId      = 0;

            while (record != null)
            {
                if (record.RecordType == BamlRecordType.ElementStart)
                {
                    BamlElementStartRecord elementStart = record as BamlElementStartRecord;
                    if (++numberOfElements == 1)
                    {
                        // save the type ID of the first element (i.e. <ControlTemplate>)
                        ownerTypeId = elementStart.TypeId;
                    }
                    else
                    {
                        // We didn't find the key before a reading the
                        // VisualTree nodes of the template
                        break;
                    }
                }
                else if (record.RecordType == BamlRecordType.Property && numberOfElements == 1)
                {
                    // look for the TargetType property on the <ControlTemplate> element
                    // or the DataType property on the <DataTemplate> element
                    BamlPropertyRecord propertyRecord = record as BamlPropertyRecord;
                    short              attributeOwnerTypeId;
                    string             attributeName;
                    BamlAttributeUsage attributeUsage;
                    parserContext.MapTable.GetAttributeInfoFromId(propertyRecord.AttributeId, out attributeOwnerTypeId, out attributeName, out attributeUsage);
                    if (attributeOwnerTypeId == ownerTypeId)
                    {
                        if (attributeName == TargetTypePropertyName)
                        {
                            key = parserContext.XamlTypeMapper.GetDictionaryKey(propertyRecord.Value, parserContext);
                        }
                        else if (attributeName == DataTypePropertyName)
                        {
                            object    dataType = parserContext.XamlTypeMapper.GetDictionaryKey(propertyRecord.Value, parserContext);
                            Exception ex       = TemplateKey.ValidateDataType(dataType, null);
                            if (ex != null)
                            {
                                ThrowException(SRID.TemplateBadDictionaryKey,
                                               parserContext.LineNumber,
                                               parserContext.LinePosition,
                                               ex);
                            }
                            //
                            key = new DataTemplateKey(dataType);
                        }
                    }
                }
                else if (record.RecordType == BamlRecordType.PropertyComplexStart ||
                         record.RecordType == BamlRecordType.PropertyIListStart ||
                         record.RecordType == BamlRecordType.ElementEnd)
                {
                    // We didn't find the targetType before a complex property like
                    // FrameworkTemplate.VisualTree or the </ControlTemplate> tag or
                    // TableTemplate.Tree or the </TableTemplate> tag
                    break;
                }
                record = record.Next;
            }

            if (key == null)
            {
                ThrowException(SRID.StyleNoDictionaryKey,
                               parserContext.LineNumber,
                               parserContext.LinePosition,
                               null);
            }

            return(key);
        }