// Token: 0x060020BE RID: 8382 RVA: 0x00096A54 File Offset: 0x00094C54
        internal override void Copy(BamlRecord record)
        {
            base.Copy(record);
            BamlContentPropertyRecord bamlContentPropertyRecord = (BamlContentPropertyRecord)record;

            bamlContentPropertyRecord._attributeId = this._attributeId;
        }
Esempio n. 2
0
        // Read the content property record and set the ContentProperty in the context.
        internal virtual void ReadContentPropertyRecord( 
            BamlContentPropertyRecord bamlContentPropertyRecord)
        {
            object contentProperty = null;
 
            short attributeId = bamlContentPropertyRecord.AttributeId;
 
            // Try KnownTypes Optimization: When the property is known use generated code for accessing it 
            object parent = GetCurrentObjectData();
            if (parent != null) 
            {
                short elementId = BamlMapTable.GetKnownTypeIdFromType(parent.GetType());
                if (elementId < 0)
                { 
                    contentProperty = KnownTypes.GetCollectionForCPA(parent, (KnownElements)(-elementId));
                } 
            } 

            if (contentProperty == null) 
            {
                WpfPropertyDefinition propertyDefinition = new WpfPropertyDefinition(this, attributeId, parent is DependencyObject);

                // Try DependencyProperty Optimization: When a DP exists for the property, use it for accessing the property 
                if (propertyDefinition.DependencyProperty != null)
                { 
                    Debug.Assert(parent is DependencyObject); 

                    if (typeof(IList).IsAssignableFrom(propertyDefinition.PropertyType)) 
                    {
                        contentProperty = ((DependencyObject)parent).GetValue(propertyDefinition.DependencyProperty) as IList;
                        // We assume that the contentProperty will become a collection now.
                        // However, in case when the DP is implemented incorrectly it may return null even if the clr property has non-null value. 
                        // So leaving contentProperty==null will drive us to general clr case below, which must do better job.
                    } 
                    else 
                    {
                        // When the property is not a IList store a DP itself as a contentProperty for assigning a simple value 
                        contentProperty = propertyDefinition.DependencyProperty;
                    }
                }
 
                if (contentProperty == null)
                { 
                    // We consider only PropertyInfo case here. 
                    // We do not consider AttachedPropertySetter in this case because content property cannot be attached.
                    if (propertyDefinition.PropertyInfo != null) 
                    {
                        // Try to treat the content property as IList
                        if (propertyDefinition.IsInternal)
                        { 
                            contentProperty = XamlTypeMapper.GetInternalPropertyValue(ParserContext,
                                                                                      ParserContext.RootElement, 
                                                                                      propertyDefinition.PropertyInfo, 
                                                                                      parent) as IList;
 
                            // if Content Property does not support IList, then see if it is
                            // accessible\allowed as a regular setter.
                            //
                            if (contentProperty == null) 
                            {
                                bool isPublicProperty; 
                                bool allowProtected = 
                                    (ParserContext.RootElement is IComponentConnector) &&
                                    (ParserContext.RootElement == parent); 
                                if (!XamlTypeMapper.IsAllowedPropertySet(propertyDefinition.PropertyInfo, allowProtected, out isPublicProperty))
                                {
                                    ThrowException(SRID.ParserCantSetContentProperty, propertyDefinition.Name, propertyDefinition.PropertyInfo.ReflectedType.Name);
                                } 
                            }
                        } 
                        else 
                        {
                            contentProperty = propertyDefinition.PropertyInfo.GetValue( 
                                parent,
                                BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy,
                                null, null, TypeConverterHelper.InvariantEnglishUS)
                                as IList; 
                        }
 
                        if (contentProperty == null) 
                        {
                            // The property returned null, try setting it directly. 
                            contentProperty = propertyDefinition.PropertyInfo;
                        }
                    }
                } 
            }
 
            if (contentProperty == null) 
            {
                ThrowException(SRID.ParserCantGetDPOrPi, GetPropertyNameFromAttributeId(attributeId)); 
            }

            CurrentContext.ContentProperty = contentProperty;
        }