// Token: 0x060021C5 RID: 8645 RVA: 0x000A8FFC File Offset: 0x000A71FC
        private void CompileProperty(ArrayList xamlNodes, string name, string value, Type parentType, string parentTypeNamespaceUri, AttributeData data, int lineNumber, int linePosition, int depth)
        {
            MarkupExtensionParser.RemoveEscapes(ref name);
            MarkupExtensionParser.RemoveEscapes(ref value);
            int    num   = name.IndexOf(':');
            string text  = (num < 0) ? name : name.Substring(num + 1);
            string text2 = (num < 0) ? string.Empty : name.Substring(0, num);
            string text3 = this.ResolveAttributeNamespaceURI(text2, text, parentTypeNamespaceUri);

            if (string.IsNullOrEmpty(text3))
            {
                this.ThrowException("ParserPrefixNSProperty", text2, name, lineNumber, linePosition);
            }
            object           obj;
            string           assemblyName;
            string           typeFullName;
            Type             type;
            string           propertyName;
            AttributeContext attributeContext = this.GetAttributeContext(parentType, parentTypeNamespaceUri, text3, text, out obj, out assemblyName, out typeFullName, out type, out propertyName);

            if (attributeContext != AttributeContext.Property)
            {
                this.ThrowException("ParserMarkupExtensionUnknownAttr", text, parentType.FullName, lineNumber, linePosition);
            }
            MemberInfo memberInfo = obj as MemberInfo;

            if (data == null || !data.IsSimple)
            {
                XamlPropertyNode value2 = new XamlPropertyNode(lineNumber, linePosition, depth, obj, assemblyName, typeFullName, propertyName, value, BamlAttributeUsage.Default, true);
                xamlNodes.Add(value2);
                return;
            }
            if (data.IsTypeExtension)
            {
                string valueTypeFullName  = value;
                string valueAssemblyName  = null;
                Type   typeFromBaseString = this._parserContext.XamlTypeMapper.GetTypeFromBaseString(value, this._parserContext, true);
                if (typeFromBaseString != null)
                {
                    valueTypeFullName = typeFromBaseString.FullName;
                    valueAssemblyName = typeFromBaseString.Assembly.FullName;
                }
                XamlPropertyWithTypeNode value3 = new XamlPropertyWithTypeNode(data.LineNumber, data.LinePosition, data.Depth, obj, assemblyName, typeFullName, text, valueTypeFullName, valueAssemblyName, typeFromBaseString, string.Empty, string.Empty);
                xamlNodes.Add(value3);
                return;
            }
            XamlPropertyWithExtensionNode value4 = new XamlPropertyWithExtensionNode(data.LineNumber, data.LinePosition, data.Depth, obj, assemblyName, typeFullName, text, value, data.ExtensionTypeId, data.IsValueNestedExtension, data.IsValueTypeExtension);

            xamlNodes.Add(value4);
        }
        // Token: 0x060020EB RID: 8427 RVA: 0x000970C0 File Offset: 0x000952C0
        public void WriteProperty(string assemblyName, string ownerTypeFullName, string propName, string value, BamlAttributeUsage propUsage)
        {
            this.VerifyWriteState();
            BamlRecordType bamlRecordType = this.PeekRecordType();

            if (bamlRecordType != BamlRecordType.ElementStart)
            {
                throw new InvalidOperationException(SR.Get("BamlWriterNoInElement", new object[]
                {
                    "WriteProperty",
                    bamlRecordType.ToString()
                }));
            }
            object obj;
            Type   declaringType;

            this.GetDpOrPi(assemblyName, ownerTypeFullName, propName, out obj, out declaringType);
            AttributeData attributeData = this._extensionParser.IsMarkupExtensionAttribute(declaringType, propName, ref value, 0, 0, 0, obj);

            if (attributeData == null)
            {
                XamlPropertyNode xamlPropertyNode = new XamlPropertyNode(0, 0, this._depth, obj, assemblyName, ownerTypeFullName, propName, value, propUsage, false);
                Type             propertyType     = XamlTypeMapper.GetPropertyType(obj);
                if (propertyType == typeof(DependencyProperty))
                {
                    Type declaringType2 = null;
                    this._dpProperty = XamlTypeMapper.ParsePropertyName(this._parserContext, value, ref declaringType2);
                    if (this._bamlRecordWriter != null && this._dpProperty != null)
                    {
                        short valueId;
                        short attributeOrTypeId = this._parserContext.MapTable.GetAttributeOrTypeId(this._bamlRecordWriter.BinaryWriter, declaringType2, this._dpProperty.Name, out valueId);
                        if (attributeOrTypeId < 0)
                        {
                            xamlPropertyNode.ValueId    = attributeOrTypeId;
                            xamlPropertyNode.MemberName = null;
                        }
                        else
                        {
                            xamlPropertyNode.ValueId    = valueId;
                            xamlPropertyNode.MemberName = this._dpProperty.Name;
                        }
                    }
                }
                else if (this._dpProperty != null)
                {
                    xamlPropertyNode.ValuePropertyType   = this._dpProperty.PropertyType;
                    xamlPropertyNode.ValuePropertyMember = this._dpProperty;
                    xamlPropertyNode.ValuePropertyName   = this._dpProperty.Name;
                    xamlPropertyNode.ValueDeclaringType  = this._dpProperty.OwnerType;
                    string fullName = this._dpProperty.OwnerType.Assembly.FullName;
                    this._dpProperty = null;
                }
                this._bamlRecordWriter.WriteProperty(xamlPropertyNode);
                return;
            }
            if (!attributeData.IsSimple)
            {
                this._extensionParser.CompileAttribute(this._markupExtensionNodes, attributeData);
                return;
            }
            if (attributeData.IsTypeExtension)
            {
                Type typeFromBaseString = this._xamlTypeMapper.GetTypeFromBaseString(attributeData.Args, this._parserContext, true);
                XamlPropertyWithTypeNode xamlPropertyWithType = new XamlPropertyWithTypeNode(0, 0, this._depth, obj, assemblyName, ownerTypeFullName, propName, typeFromBaseString.FullName, typeFromBaseString.Assembly.FullName, typeFromBaseString, string.Empty, string.Empty);
                this._bamlRecordWriter.WritePropertyWithType(xamlPropertyWithType);
                return;
            }
            XamlPropertyWithExtensionNode xamlPropertyNode2 = new XamlPropertyWithExtensionNode(0, 0, this._depth, obj, assemblyName, ownerTypeFullName, propName, attributeData.Args, attributeData.ExtensionTypeId, attributeData.IsValueNestedExtension, attributeData.IsValueTypeExtension);

            this._bamlRecordWriter.WritePropertyWithExtension(xamlPropertyNode2);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Write simple property information to baml.
        /// </summary>
        /// <remarks>
        /// If the type of this property supports
        /// custom serialization using a XamlSerializer and custom serialization
        /// is chosen, then write out a 
        /// Custom serialization record.  Note that for custom serialization
        /// to work, the assembly that contains the property's type must be 
        /// loaded. If custom serialization is not chosen, then
        /// write out a 'normal' record, which will cause type conversion to happen
        /// at load time from the stored string.
        /// </remarks>
        public void WriteProperty(
            string             assemblyName,
            string             ownerTypeFullName,
            string             propName,
            string             value,
            BamlAttributeUsage propUsage)
        {
            VerifyWriteState();
            
            BamlRecordType parentType = PeekRecordType();
            if (parentType != BamlRecordType.ElementStart)
            {
                throw new InvalidOperationException(SR.Get(SRID.BamlWriterNoInElement,
                                                           "WriteProperty",
                                                           parentType.ToString()));
            }

            object dpOrPi;
            Type   declaringType;
            GetDpOrPi(assemblyName, ownerTypeFullName, propName, out dpOrPi, out declaringType);

            // Check if the value is a MarkupExtension.  If so it must be expanded into
            // a series of baml records.  Otherwise just write out the property.
            AttributeData data = _extensionParser.IsMarkupExtensionAttribute(
                                                        declaringType,    
                                                        propName,       
                                                    ref value,
                                                        0,       // No line numbers for baml
                                                        0,
                                                        0,
                                                        dpOrPi);

            if (data == null)
            {
                XamlPropertyNode propNode = new XamlPropertyNode(
                                            0,
                                            0,
                                            _depth,
                                            dpOrPi,   
                                            assemblyName,
                                            ownerTypeFullName,
                                            propName,
                                            value,
                                            propUsage,
                                            false);

                Type propType = XamlTypeMapper.GetPropertyType(dpOrPi);
                if (propType == typeof(DependencyProperty))
                {
                    Type ownerType = null;
                    _dpProperty = XamlTypeMapper.ParsePropertyName(_parserContext, value, ref ownerType);

                    if (_bamlRecordWriter != null && _dpProperty != null)
                    {
                        short typeId;
                        short propertyId = _parserContext.MapTable.GetAttributeOrTypeId(_bamlRecordWriter.BinaryWriter,
                                                                                        ownerType,
                                                                                        _dpProperty.Name,
                                                                                        out typeId);

                        if (propertyId < 0)
                        {
                            propNode.ValueId = propertyId;
                            propNode.MemberName = null;
                        }
                        else
                        {
                            propNode.ValueId = typeId;
                            propNode.MemberName = _dpProperty.Name;
                        }
                    }
                }
                else if (_dpProperty != null)
                {
                    propNode.ValuePropertyType = _dpProperty.PropertyType;
                    propNode.ValuePropertyMember = _dpProperty;
                    propNode.ValuePropertyName = _dpProperty.Name;
                    propNode.ValueDeclaringType = _dpProperty.OwnerType;
                    string propAssemblyName = _dpProperty.OwnerType.Assembly.FullName;
                    _dpProperty = null;
                }

                _bamlRecordWriter.WriteProperty(propNode);            
            }
            else
            {
                if (data.IsSimple)
                {
                    if (data.IsTypeExtension)
                    {
                        Type typeValue = _xamlTypeMapper.GetTypeFromBaseString(data.Args,
                                                                               _parserContext,
                                                                               true);
                        Debug.Assert(typeValue != null);

                        XamlPropertyWithTypeNode xamlPropertyWithTypeNode =
                            new XamlPropertyWithTypeNode(0,
                                                         0,
                                                         _depth,
                                                         dpOrPi,   
                                                         assemblyName,
                                                         ownerTypeFullName,
                                                         propName,
                                                         typeValue.FullName,
                                                         typeValue.Assembly.FullName,
                                                         typeValue,   
                                                         string.Empty,
                                                         string.Empty);

                        _bamlRecordWriter.WritePropertyWithType(xamlPropertyWithTypeNode);
                    }
                    else
                    {
                        XamlPropertyWithExtensionNode xamlPropertyWithExtensionNode =
                            new XamlPropertyWithExtensionNode(0,
                                                              0,
                                                              _depth,
                                                              dpOrPi,
                                                              assemblyName,
                                                              ownerTypeFullName,
                                                              propName,
                                                              data.Args,
                                                              data.ExtensionTypeId,
                                                              data.IsValueNestedExtension,
                                                              data.IsValueTypeExtension);

                        _bamlRecordWriter.WritePropertyWithExtension(xamlPropertyWithExtensionNode);
                    }
                }
                else
                {
                    _extensionParser.CompileAttribute(
                                            _markupExtensionNodes, data);
                }
            }
        }