Ejemplo n.º 1
0
 public override void WritePropertyWithExtension(XamlPropertyWithExtensionNode xamlPropertyWithExtensionNode) 
 {
     xamlPropertyWithExtensionNode.DefaultTargetType = TargetType; 
     base.WritePropertyWithExtension(xamlPropertyWithExtensionNode);
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Represent a single property for a MarkupExtension as a complex property.
        /// </summary>
        private void CompileProperty(
            ArrayList xamlNodes,
            string name,
            string value,
            Type parentType,
            string parentTypeNamespaceUri,
            AttributeData data,
            int lineNumber,
            int linePosition,
            int depth)
        {
            RemoveEscapes(ref name);
            RemoveEscapes(ref value);

            int nameIndex = name.IndexOf(':');
            string localName = (nameIndex < 0) ? name : name.Substring(nameIndex+1);
            string prefix = (nameIndex < 0) ? String.Empty : name.Substring(0, nameIndex);
            string attribNamespaceURI = ResolveAttributeNamespaceURI(prefix, localName, parentTypeNamespaceUri);

            object dynamicObject;
            string assemblyName;
            string typeFullName;
            Type   declaringType;
            string dynamicObjectName;

            if (String.IsNullOrEmpty(attribNamespaceURI))
            {
               ThrowException(SRID.ParserPrefixNSProperty, prefix, name, lineNumber, linePosition);
            }

            AttributeContext attributeContext = GetAttributeContext(
                                                    parentType,
                                                    parentTypeNamespaceUri,
                                                    attribNamespaceURI,
                                                    localName,
                                                out dynamicObject,
                                                out assemblyName,
                                                out typeFullName,
                                                out declaringType,
                                                out dynamicObjectName);

            if (attributeContext != AttributeContext.Property)
            {
                ThrowException(SRID.ParserMarkupExtensionUnknownAttr, localName,
                               parentType.FullName, lineNumber, linePosition);
            }

            MemberInfo info = dynamicObject as MemberInfo;

            Debug.Assert(null != info, "No property or method info for field Name");

            if (data != null && data.IsSimple)
            {
                if (data.IsTypeExtension)
                {
                    string typeValueFullName = value;  // set this to original value for error reporting if reqd.
                    string typeValueAssemblyFullName = null;
                    Type typeValue = _parserContext.XamlTypeMapper.GetTypeFromBaseString(value,
                                                                                         _parserContext,
                                                                                         true);
                    if (typeValue != null)
                    {
                        typeValueFullName = typeValue.FullName;
                        typeValueAssemblyFullName = typeValue.Assembly.FullName;
                    }

                    XamlPropertyWithTypeNode xamlPropertyWithTypeNode =
                        new XamlPropertyWithTypeNode(data.LineNumber,
                                                     data.LinePosition,
                                                     data.Depth,
                                                     dynamicObject,
                                                     assemblyName,
                                                     typeFullName,
                                                     localName,
                                                     typeValueFullName,
                                                     typeValueAssemblyFullName,
                                                     typeValue,
                                                     string.Empty,
                                                     string.Empty);

                    xamlNodes.Add(xamlPropertyWithTypeNode);
                }
                else
                {
                    XamlPropertyWithExtensionNode xamlPropertyWithExtensionNode =
                        new XamlPropertyWithExtensionNode(data.LineNumber,
                                                          data.LinePosition,
                                                          data.Depth,
                                                          dynamicObject,
                                                          assemblyName,
                                                          typeFullName,
                                                          localName,
                                                          value,
                                                          data.ExtensionTypeId,
                                                          data.IsValueNestedExtension,
                                                          data.IsValueTypeExtension);

                    xamlNodes.Add(xamlPropertyWithExtensionNode);
                }
            }
            else
            {
                XamlPropertyNode xamlPropertyNode =
                    new XamlPropertyNode(lineNumber,
                                         linePosition,
                                         depth,
                                         dynamicObject,
                                         assemblyName,
                                         typeFullName,
                                         dynamicObjectName,
                                         value,
                                         BamlAttributeUsage.Default,
                                         true);

                xamlNodes.Add(xamlPropertyNode);
            }
        }
Ejemplo n.º 3
0
 public virtual void WritePropertyWithExtension(XamlPropertyWithExtensionNode xamlPropertyWithExtensionNode)
 {
     if (BamlRecordWriter != null)
     {
         BamlRecordWriter.WritePropertyWithExtension(xamlPropertyWithExtensionNode);
     }
 }
        internal virtual void WritePropertyWithExtension(XamlPropertyWithExtensionNode xamlPropertyNode)
        {
            short valueId = 0;
            short extensionTypeId = xamlPropertyNode.ExtensionTypeId;
            bool isValueTypeExtension = false;
            bool isValueStaticExtension = false;
            Debug.Assert(extensionTypeId != (short)KnownElements.TypeExtension);

            // if the extension is a DynamicResourceExtension or a StaticResourceExtension
            // dig in to see if its param is a simple extension or just a string.
            if ((extensionTypeId == (short)KnownElements.DynamicResourceExtension) ||
                (extensionTypeId == (short)KnownElements.StaticResourceExtension))
            {
                // if the value is a simple nested extension
                if (xamlPropertyNode.IsValueNestedExtension)
                {
                    // Yes, see if it is a TypeExtension or StaticExtension
                    if (xamlPropertyNode.IsValueTypeExtension)
                    {
                        // nested TypeExtension value
                        Type typeValue = _xamlTypeMapper.GetTypeFromBaseString(xamlPropertyNode.Value,
                                                                               ParserContext,
                                                                               true);
                        Debug.Assert(typeValue != null);
                        if (!MapTable.GetTypeInfoId(BinaryWriter,
                                                    typeValue.Assembly.FullName,
                                                    typeValue.FullName,
                                                    out valueId))
                        {
                            valueId = MapTable.AddTypeInfoMap(BinaryWriter,
                                                              typeValue.Assembly.FullName,
                                                              typeValue.FullName,
                                                              typeValue,
                                                              string.Empty,
                                                              string.Empty);
                        }

                        isValueTypeExtension = true;
                    }
                    else
                    {
                        // nested StaticExtension value
                        valueId = MapTable.GetStaticMemberId(BinaryWriter,
                                                             ParserContext,
                                                             (short)KnownElements.StaticExtension,
                                                             xamlPropertyNode.Value,
                                                             xamlPropertyNode.DefaultTargetType);

                        isValueStaticExtension = true;
                    }
                }
                else
                {
                    // No, it is a string value.
                    // Store the string value in the string table, since these records
                    // are already used as the key for a [Static/Dynamic]Resource.
                    if (!MapTable.GetStringInfoId(xamlPropertyNode.Value, out valueId))
                    {
                        valueId = MapTable.AddStringInfoMap(BinaryWriter, xamlPropertyNode.Value);
                    }
                }
            }
            else
            {
                // toplevel StaticExtension or TemplateBindingExtension value
                valueId = MapTable.GetStaticMemberId(BinaryWriter,
                                                     ParserContext,
                                                     extensionTypeId,
                                                     xamlPropertyNode.Value,
                                                     xamlPropertyNode.DefaultTargetType);
            }

            short attributeId = MapTable.AddAttributeInfoMap(BinaryWriter,
                                                             xamlPropertyNode.AssemblyName,
                                                             xamlPropertyNode.TypeFullName,
                                                             xamlPropertyNode.PropDeclaringType,
                                                             xamlPropertyNode.PropName,
                                                             xamlPropertyNode.PropValidType,
                                                             BamlAttributeUsage.Default);

            if (_deferLoadingSupport && _deferElementDepth > 0 && CollectingValues &&
                extensionTypeId == (short)KnownElements.StaticResourceExtension)
            {
                // If we are currently processing a StaticResourceExtension
                // within a deferable content section then the information in
                // the xamlPropertyNode is distributed among two separate
                // BamlRecords viz. BamlOptimizedStaticResourceRecord which
                // belongs in the header of the deferred section and a
                // BamlPropertyWithStaticResourceIdRecord which is an inline
                // place holder for the same.


                // Create and populate the BamlOptimizedStaticResourceRecord that
                // is stored in the header of the deferred section.

                BamlOptimizedStaticResourceRecord bamlOptimizedStaticResource =
                    (BamlOptimizedStaticResourceRecord)BamlRecordManager.GetWriteRecord(BamlRecordType.OptimizedStaticResource);

                bamlOptimizedStaticResource.IsValueTypeExtension = isValueTypeExtension;
                bamlOptimizedStaticResource.IsValueStaticExtension = isValueStaticExtension;
                bamlOptimizedStaticResource.ValueId = valueId;

                _staticResourceRecordList = new List<ValueDeferRecord>(1);
                _staticResourceRecordList.Add(new ValueDeferRecord(
                    bamlOptimizedStaticResource,
                    xamlPropertyNode.LineNumber,
                    xamlPropertyNode.LinePosition));

                // Add the current StaticResource to the list on the current key record
                KeyDeferRecord keyDeferRecord = ((KeyDeferRecord)_deferKeys[_deferKeys.Count-1]);
                keyDeferRecord.StaticResourceRecordList.Add(_staticResourceRecordList);

                // Write a PropertyWithStaticResourceId to the values collection
                BamlPropertyWithStaticResourceIdRecord bamlPropertyWithStaticResourceId =
                    (BamlPropertyWithStaticResourceIdRecord) BamlRecordManager.GetWriteRecord(BamlRecordType.PropertyWithStaticResourceId);

                bamlPropertyWithStaticResourceId.AttributeId = attributeId;
                bamlPropertyWithStaticResourceId.StaticResourceId = (short)(keyDeferRecord.StaticResourceRecordList.Count-1);

                _deferValues.Add(new ValueDeferRecord(
                    bamlPropertyWithStaticResourceId,
                    xamlPropertyNode.LineNumber,
                    xamlPropertyNode.LinePosition));

                _staticResourceRecordList = null;
            }
            else
            {
                BamlPropertyWithExtensionRecord bamlPropertyWithExtension =
                    (BamlPropertyWithExtensionRecord)BamlRecordManager.GetWriteRecord(BamlRecordType.PropertyWithExtension);

                bamlPropertyWithExtension.AttributeId = attributeId;
                bamlPropertyWithExtension.ExtensionTypeId = extensionTypeId;
                bamlPropertyWithExtension.IsValueTypeExtension = isValueTypeExtension;
                bamlPropertyWithExtension.IsValueStaticExtension = isValueStaticExtension;
                bamlPropertyWithExtension.ValueId = valueId;

                WriteAndReleaseRecord(bamlPropertyWithExtension, xamlPropertyNode);
            }
        }