예제 #1
0
 internal void GetAttributeInfoFromId(short id, out short ownerTypeId, out string name, out BamlAttributeUsage attributeUsage) 
 {
     if (id < 0) 
     { 
         KnownProperties knownId = (KnownProperties)(-id);
         name = GetAttributeNameFromKnownId(knownId); 
         ownerTypeId = (short)-(short)KnownTypes.GetKnownElementFromKnownCommonProperty(knownId);
         attributeUsage = GetAttributeUsageFromKnownAttribute(knownId);
     }
     else 
     {
         BamlAttributeInfoRecord record = (BamlAttributeInfoRecord)AttributeIdMap[id]; 
         name = record.Name; 
         ownerTypeId = record.OwnerTypeId;
         attributeUsage = record.AttributeUsage; 
     }
 }
예제 #2
0
        internal short AddAttributeInfoMap(
            BinaryWriter binaryWriter,
            string assemblyFullName,                // Name of assembly for owning or declaring type 
            string typeFullName,                    // Type name of object that owns or declares this attribute
            Type owningType,                        // Actual type of the object the owns or declares this attribute 
            string fieldName,                       // Name of the attribute 
            Type attributeType,                     // Type of the attribute or property itself; not its owner type
            BamlAttributeUsage attributeUsage,      // Special flags for how this attribute is used. 
            out BamlAttributeInfoRecord bamlAttributeInfoRecord)     // Record if not a known DP
        {
            short typeId;
            // If we do not already have a type record for the type associated with 
            // this attribute, then recurse and write out the TypeInfo first.
            if (!GetTypeInfoId(binaryWriter, assemblyFullName, typeFullName, out typeId)) 
            { 
                // Get id for Type that owns or has this attribute declared on it.  This is
                // refered to in the attribute info record and is also part of the key for 
                // seeing if we already have an attribute info record for this attribute.
                Type serializerType = XamlTypeMapper.GetXamlSerializerForType(owningType);
                string serializerTypeAssemblyName = serializerType == null ?
                                         string.Empty : serializerType.Assembly.FullName; 
                string serializerTypeName = serializerType == null ?
                                         string.Empty : serializerType.FullName; 
 
                typeId = AddTypeInfoMap(binaryWriter, assemblyFullName, typeFullName,
                                        owningType, serializerTypeAssemblyName, 
                                        serializerTypeName);
            }
            else if (typeId < 0)
            { 
                // Only known types will have known properties
                short attributeId = (short)-KnownTypes.GetKnownPropertyAttributeId((KnownElements)(-typeId), fieldName); 
                if (attributeId < 0) 
                {
                    // The property is known and doesn't need a record created. 
                    bamlAttributeInfoRecord = null;
                    return attributeId;
                }
            } 

            object key = GetAttributeInfoKey(typeFullName, fieldName); 
 
            bamlAttributeInfoRecord = (BamlAttributeInfoRecord)GetHashTableData(key);
            if (null == bamlAttributeInfoRecord) 
            {
                // The property is new and needs a record created.
                bamlAttributeInfoRecord = new BamlAttributeInfoRecord();
 
                bamlAttributeInfoRecord.Name = fieldName;
                bamlAttributeInfoRecord.OwnerTypeId = typeId; 
 
                bamlAttributeInfoRecord.AttributeId = (short)AttributeIdMap.Add(bamlAttributeInfoRecord);
                bamlAttributeInfoRecord.AttributeUsage = attributeUsage; 

                // add to the hash
                ObjectHashTable.Add(key, bamlAttributeInfoRecord);
 
                // Write to BAML
                bamlAttributeInfoRecord.Write(binaryWriter); 
            } 

            return bamlAttributeInfoRecord.AttributeId; 
        }
예제 #3
0
 internal bool DoesAttributeMatch(short id, BamlAttributeUsage attributeUsage) 
 {
     if (id < 0)
     {
         return attributeUsage == GetAttributeUsageFromKnownAttribute((KnownProperties)(-id)); 
     }
     else 
     { 
         BamlAttributeInfoRecord record = (BamlAttributeInfoRecord)AttributeIdMap[id];
         return attributeUsage == record.AttributeUsage; 
     }
 }
예제 #4
0
 internal XamlPropertyNode( 
     int lineNumber, 
     int linePosition,
     int depth, 
     object propertyMember,    // DependencyProperty, MethodInfo or PropertyInfo
     string assemblyName,
     string typeFullName,
     string propertyName, 
     string value,
     BamlAttributeUsage attributeUsage, 
     bool complexAsSimple, 
     bool isDefinitionName) : this(lineNumber,
                                   linePosition, 
                                   depth,
                                   propertyMember,
                                   assemblyName,
                                   typeFullName, 
                                   propertyName,
                                   value, 
                                   attributeUsage, 
                                   complexAsSimple)
 { 
     _isDefinitionName = isDefinitionName;
 }
예제 #5
0
 // Return the attribute info record that corresponds to the passed type and field name.
 // If one does not already exist, then create a new one.  This can involve first creating 
 // a type info record that corresponds to the owner type and the attribute type.
 // This method also checks if the attributeType is custom serializable or convertible. 
 internal short AddAttributeInfoMap( 
     BinaryWriter binaryWriter,
     string assemblyFullName,                // Name of assembly for owning or declaring type 
     string typeFullName,                    // Type name of object that owns or declares this attribute
     Type   owningType,                      // Actual type of the object the owns or declares this attribute
     string fieldName,                       // Name of the attribute
     Type attributeType,                     // Type of the attribute or property itself; not its owner type 
     BamlAttributeUsage attributeUsage)      // Special flags for how this attribute is used.
 { 
     BamlAttributeInfoRecord record; 
     return AddAttributeInfoMap(binaryWriter, assemblyFullName, typeFullName, owningType, fieldName, attributeType, attributeUsage, out record);
 } 
예제 #6
0
 /// <summary>
 /// Constructor
 /// </summary> 
 internal XamlDefAttributeNode(
     int    lineNumber, 
     int    linePosition, 
     int    depth,
     string name, 
     string value,
     BamlAttributeUsage bamlAttributeUsage)
     : base (XamlNodeType.DefAttribute,lineNumber,linePosition,depth,value)
 { 
     _attributeUsage = bamlAttributeUsage;
     _name = name; 
 } 
예제 #7
0
 /// <summary> 
 /// Constructor 
 /// </summary>
 internal XamlPropertyNode( 
     int                lineNumber,
     int                linePosition,
     int                depth,
     object             propertyMember,    // DependencyProperty, MethodInfo or PropertyInfo 
     string             assemblyName,
     string             typeFullName, 
     string             propertyName, 
     string             value,
     BamlAttributeUsage attributeUsage, 
     bool               complexAsSimple) : base (XamlNodeType.Property,
                                                 lineNumber,
                                                 linePosition,
                                                 depth, 
                                                 propertyMember,
                                                 assemblyName, 
                                                 typeFullName, 
                                                 propertyName)
 { 
     _value = value;
     _attributeUsage = attributeUsage;
     _complexAsSimple = complexAsSimple;
 } 
예제 #8
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);
                }
            }
        }
예제 #9
0
 /// <summary> 
 /// Constructor
 /// </summary>
 internal XamlUnknownAttributeNode(
     int          lineNumber, 
     int          linePosition,
     int          depth, 
     string       xmlNamespace, 
     string       name,
     string       value, 
     BamlAttributeUsage attributeUsage)
     : base(XamlNodeType.UnknownAttribute,lineNumber,linePosition,
            depth,value)
 { 
     _xmlNamespace = xmlNamespace;
     _name = name; 
     _attributeUsage = attributeUsage; 
 }
        /// <summary>
        /// Write out a property that is represented as a complex property as if it were
        /// a regular attribute.
        /// </summary>
        void WriteComplexAsSimpleProperty(
            string propertyName,            // String name of the property in xaml markup
            string propertyNamespaceUri,    // Namespace corresponding to the property name
            object propertyMember,          // DependencyProperty, PropertyInfo or MethodInfo for static setter
            string assemblyName,            // Assembly where type of the CLR property is defined
            Type declaringType,           // Type that corresponds to declaringTypeFullName (where the property is declared)
            string declaringTypeFullName,   // Full name of the type where the property is declared
            string value,                   // String value of the property
            BamlAttributeUsage usage)       // Defines special usage for this property, such as xml:lang
        {
            CheckDuplicateProperty(ParentProperties, propertyName, propertyMember);

            // Validate that enum values aren't pure digits.
            Type propType = XamlTypeMapper.GetPropertyType(propertyMember);
            XamlTypeMapper.ValidateEnums(propertyName, propType, value);

            // See if this is the property that maps to x:Name, and if so, set the usage flag.
            string parentName = declaringType != null ? declaringType.Name : string.Empty;
            if (IsNameProperty(value, parentName, propertyName, propertyNamespaceUri, GetRuntimeNamePropertyName(declaringType)))
            {
                usage = BamlAttributeUsage.RuntimeName;
            }


            AddNodeToCollection(new XamlPropertyNode(
                LineNumber, LinePosition, XmlReader.Depth, propertyMember,
                assemblyName, declaringTypeFullName, propertyName, value, usage, true));
        }
예제 #11
0
 internal BamlPropertyNode(
     string             assemblyName,
     string             ownerTypeFullName,
     string             propertyName,
     string             value,
     BamlAttributeUsage usage            
     ): base(assemblyName, ownerTypeFullName, propertyName)
 {
     _value              = value;
     _attributeUsage     = usage;
     _nodeType           = BamlNodeType.Property;
 }
 /// <summary>
 /// Write out a property that is represented as an attribute on a tag.
 /// </summary>
 void WriteProperty(
     string propertyName,            // String name of the property in xaml markup
     object propertyMember,          // DependencyProperty, PropertyInfo or MethodInfo for static setter
     string assemblyName,            // Assembly of the type where the property is declared
     string declaringTypeFullName,   // Full name of the type where the property is declared
     string value,                   // String value of the property
     BamlAttributeUsage usage)       // Defines special usage for this property, such as xml:lang
 {
     bool isName = usage == BamlAttributeUsage.RuntimeName;
     AddNodeToCollection(new XamlPropertyNode(
         LineNumber, LinePosition, XmlReader.Depth, propertyMember,
         assemblyName, declaringTypeFullName, propertyName, value, usage, false), isName, isName);
 }
 /// <summary>
 /// Write out an attribute in the definition namespace
 /// </summary>
 void WriteDefAttribute(string name, string value, BamlAttributeUsage bamlAttributeUsage)
 {
     AddNodeToCollection(new XamlDefAttributeNode(LineNumber, LinePosition, XmlReader.Depth,
             name, value, bamlAttributeUsage));
 }
 // Token: 0x06006E81 RID: 28289 RVA: 0x001FC15C File Offset: 0x001FA35C
 internal BamlPropertyNode(string assemblyName, string ownerTypeFullName, string propertyName, string value, BamlAttributeUsage usage) : base(assemblyName, ownerTypeFullName, propertyName)
 {
     this._value          = value;
     this._attributeUsage = usage;
     this._nodeType       = BamlNodeType.Property;
 }
예제 #15
0
 // Token: 0x060022B8 RID: 8888 RVA: 0x000AC148 File Offset: 0x000AA348
 internal XamlPropertyNode(int lineNumber, int linePosition, int depth, object propertyMember, string assemblyName, string typeFullName, string propertyName, string value, BamlAttributeUsage attributeUsage, bool complexAsSimple) : base(XamlNodeType.Property, lineNumber, linePosition, depth, propertyMember, assemblyName, typeFullName, propertyName)
 {
     this._value           = value;
     this._attributeUsage  = attributeUsage;
     this._complexAsSimple = complexAsSimple;
 }
예제 #16
0
 // Token: 0x060022B9 RID: 8889 RVA: 0x000AC180 File Offset: 0x000AA380
 internal XamlPropertyNode(int lineNumber, int linePosition, int depth, object propertyMember, string assemblyName, string typeFullName, string propertyName, string value, BamlAttributeUsage attributeUsage, bool complexAsSimple, bool isDefinitionName) : this(lineNumber, linePosition, depth, propertyMember, assemblyName, typeFullName, propertyName, value, attributeUsage, complexAsSimple)
 {
     this._isDefinitionName = isDefinitionName;
 }