示例#1
0
        public override void WriteUnknownAttribute(XamlUnknownAttributeNode xamlUnknownAttributeNode)
        {
            bool   localAttrib      = false;
            string localTagFullName = string.Empty;
            string localAttribName  = xamlUnknownAttributeNode.Name;

            NamespaceMapEntry[] namespaceMaps = null;
            MemberInfo          miKnownEvent  = null;

            if (xamlUnknownAttributeNode.OwnerTypeFullName.Length > 0)
            {
                // These are attributes on a local tag ...
                localTagFullName = xamlUnknownAttributeNode.OwnerTypeFullName;
                localAttrib      = true;
            }
            else
            {
                //  These are attributes on a non-local tag ...
                namespaceMaps = XamlTypeMapper.GetNamespaceMapEntries(xamlUnknownAttributeNode.XmlNamespace);
                localAttrib   = namespaceMaps != null && namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly;
            }

            if (localAttrib && !_pass2)
            {
                // ... and if there are any periods in the attribute name, then ...
                int lastIndex = localAttribName.LastIndexOf(MarkupCompiler.DOTCHAR);

                if (-1 != lastIndex)
                {
                    // ... these might be attached props or events defined by a locally defined component,
                    // but being set on this non-local tag.

                    TypeAndSerializer typeAndSerializer = null;
                    string            ownerTagName      = localAttribName.Substring(0, lastIndex);

                    if (namespaceMaps != null)
                    {
                        if (namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly)
                        {
                            // local prop on a known tag
                            localTagFullName = namespaceMaps[0].ClrNamespace + MarkupCompiler.DOT + ownerTagName;
                        }
                    }
                    else
                    {
                        typeAndSerializer = XamlTypeMapper.GetTypeOnly(xamlUnknownAttributeNode.XmlNamespace,
                                                                       ownerTagName);

                        if (typeAndSerializer != null)
                        {
                            // known local attribute on a local tag

                            Type ownerTagType = typeAndSerializer.ObjectType;
                            localTagFullName = ownerTagType.FullName;
                            localAttribName  = localAttribName.Substring(lastIndex + 1);

                            // See if attached event first
                            miKnownEvent = ownerTagType.GetMethod(MarkupCompiler.ADD + localAttribName + MarkupCompiler.HANDLER,
                                                                  BindingFlags.Public | BindingFlags.Static |
                                                                  BindingFlags.FlattenHierarchy);

                            if (miKnownEvent == null)
                            {
                                // Not an attached event, so try for a clr event.
                                miKnownEvent = ownerTagType.GetEvent(localAttribName,
                                                                     BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
                            }

                            if (miKnownEvent != null)
                            {
                                if (_events == null)
                                {
                                    _events = new ArrayList();
                                }

                                _events.Add(new MarkupCompiler.MarkupEventInfo(xamlUnknownAttributeNode.Value,
                                                                               localAttribName,
                                                                               miKnownEvent,
                                                                               xamlUnknownAttributeNode.LineNumber));

                                WriteConnectionId();
                            }
                        }
                        else
                        {
                            namespaceMaps = XamlTypeMapper.GetNamespaceMapEntries(xamlUnknownAttributeNode.XmlNamespace);
                            if (namespaceMaps != null && namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly)
                            {
                                // local prop on local tag
                                localTagFullName = namespaceMaps[0].ClrNamespace + MarkupCompiler.DOT + ownerTagName;
                            }
                            else
                            {
                                // unknown prop on local tag -- Error!
                                localTagFullName = string.Empty;
                            }
                        }
                    }

                    if (typeAndSerializer == null)
                    {
                        localAttribName = localAttribName.Substring(lastIndex + 1);
                    }
                }
                // else if it is an unknown non-attached prop on a non-local tag -- instant error!
            }

            if (localTagFullName.Length > 0 && !_pass2)
            {
                if (xamlUnknownAttributeNode.AttributeUsage == BamlAttributeUsage.RuntimeName)
                {
                    string attributeValue = xamlUnknownAttributeNode.Value;

                    Debug.Assert(_name == null && _nameField == null, "Name has already been set");
                    _nameField = _compiler.AddNameField(attributeValue, xamlUnknownAttributeNode.LineNumber, xamlUnknownAttributeNode.LinePosition);
                    _name      = attributeValue;

                    if (_nameField != null)
                    {
                        WriteConnectionId();
                    }
                }
                else if (localAttribName.Equals(STARTUPURI) &&
                         _compiler.IsCompilingEntryPointClass)
                {
                    // if Application.StartuoUri property then don't bamlize, but gen code since
                    // this is better for perf as Application is not a DO.
                    PropertyInfo pi = KnownTypes.Types[(int)KnownElements.Application].GetProperty(localAttribName);
                    _compiler.AddApplicationProperty(pi,
                                                     xamlUnknownAttributeNode.Value,
                                                     xamlUnknownAttributeNode.LineNumber);
                    return;
                }
                else if (miKnownEvent == null)
                {
                    // This may or may not be a local event, but there is no way to know in Pass1.
                    // So we prepare for the worst case sceanrio and assume it may be one so that
                    // the Xaml compiler can generate the CreateDelegate code.
                    _compiler.HasLocalEvent = true;
                }
            }
            else
            {
                base.WriteUnknownAttribute(xamlUnknownAttributeNode);
            }

            _compiler.IsBamlNeeded = true;
        }
        public override void WriteUnknownAttribute(XamlUnknownAttributeNode xamlUnknownAttributeNode)
        {
            bool localAttrib = false;
            string localTagFullName = string.Empty;
            string localAttribName = xamlUnknownAttributeNode.Name;
            NamespaceMapEntry[] namespaceMaps = null;
            MemberInfo miKnownEvent = null;

            if (xamlUnknownAttributeNode.OwnerTypeFullName.Length > 0)
            {
                // These are attributes on a local tag ...
                localTagFullName = xamlUnknownAttributeNode.OwnerTypeFullName;
                localAttrib = true;
            }
            else
            {
                //  These are attributes on a non-local tag ...
                namespaceMaps = XamlTypeMapper.GetNamespaceMapEntries(xamlUnknownAttributeNode.XmlNamespace);
                localAttrib = namespaceMaps != null && namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly;
            }

            if (localAttrib && !_pass2)
            {
                // ... and if there are any periods in the attribute name, then ...
                int lastIndex = localAttribName.LastIndexOf(MarkupCompiler.DOTCHAR);

                if (-1 != lastIndex)
                {
                    // ... these might be attached props or events defined by a locally defined component,
                    // but being set on this non-local tag.

                    TypeAndSerializer typeAndSerializer = null;
                    string ownerTagName = localAttribName.Substring(0, lastIndex);

                    if (namespaceMaps != null)
                    {
                        if (namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly)
                        {
                            // local prop on a known tag
                            localTagFullName = namespaceMaps[0].ClrNamespace + MarkupCompiler.DOT + ownerTagName;
                        }
                    }
                    else
                    {
                        typeAndSerializer = XamlTypeMapper.GetTypeOnly(xamlUnknownAttributeNode.XmlNamespace, 
                                                               ownerTagName);

                        if (typeAndSerializer != null)
                        {
                            // known local attribute on a local tag

                            Type ownerTagType = typeAndSerializer.ObjectType;
                            localTagFullName = ownerTagType.FullName;
                            localAttribName = localAttribName.Substring(lastIndex + 1);

                            // See if attached event first
                            miKnownEvent = ownerTagType.GetMethod(MarkupCompiler.ADD + localAttribName + MarkupCompiler.HANDLER,
                                BindingFlags.Public | BindingFlags.Static  |
                                BindingFlags.FlattenHierarchy);

                            if (miKnownEvent == null)
                            {
                                // Not an attached event, so try for a clr event.
                                miKnownEvent = ownerTagType.GetEvent(localAttribName, 
                                    BindingFlags.Instance | BindingFlags.Public | BindingFlags.FlattenHierarchy);
                            }

                            if (miKnownEvent != null)
                            {
                                if (_events == null)
                                    _events = new ArrayList();

                                _events.Add(new MarkupCompiler.MarkupEventInfo(xamlUnknownAttributeNode.Value,
                                                                               localAttribName,
                                                                               miKnownEvent,
                                                                               xamlUnknownAttributeNode.LineNumber));

                                WriteConnectionId();
                            }
                        }
                        else
                        {
                            namespaceMaps = XamlTypeMapper.GetNamespaceMapEntries(xamlUnknownAttributeNode.XmlNamespace);
                            if (namespaceMaps != null && namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly)
                            {
                                // local prop on local tag
                                localTagFullName = namespaceMaps[0].ClrNamespace + MarkupCompiler.DOT + ownerTagName;
                            }
                            else
                            {
                                // unknown prop on local tag -- Error!
                                localTagFullName = string.Empty;
                            }
                        }
                    }

                    if (typeAndSerializer == null)
                    {
                        localAttribName = localAttribName.Substring(lastIndex + 1);
                    }
                }
                // else if it is an unknown non-attached prop on a non-local tag -- instant error!
            }

            if (localTagFullName.Length > 0 && !_pass2)
            {
                if (xamlUnknownAttributeNode.AttributeUsage == BamlAttributeUsage.RuntimeName)
                {
                    string attributeValue = xamlUnknownAttributeNode.Value;

                    Debug.Assert(_name == null && _nameField == null, "Name has already been set");
                    _nameField = _compiler.AddNameField(attributeValue, xamlUnknownAttributeNode.LineNumber, xamlUnknownAttributeNode.LinePosition);
                    _name = attributeValue;

                    if (_nameField != null)
                    {
                        WriteConnectionId();
                    }
                }
                else if (localAttribName.Equals(STARTUPURI) &&
                         _compiler.IsCompilingEntryPointClass)
                {
                    // if Application.StartuoUri property then don't bamlize, but gen code since
                    // this is better for perf as Application is not a DO.
                    PropertyInfo pi = KnownTypes.Types[(int)KnownElements.Application].GetProperty(localAttribName);
                    _compiler.AddApplicationProperty(pi,
                                                     xamlUnknownAttributeNode.Value,
                                                     xamlUnknownAttributeNode.LineNumber);
                    return;
                }
                else if (miKnownEvent == null)
                {
                    // This may or may not be a local event, but there is no way to know in Pass1.
                    // So we prepare for the worst case sceanrio and assume it may be one so that
                    // the Xaml compiler can generate the CreateDelegate code.
                    _compiler.HasLocalEvent = true;
                }
            }
            else
            {
                base.WriteUnknownAttribute(xamlUnknownAttributeNode);
            }

            _compiler.IsBamlNeeded = true;
        }
示例#3
0
        /// <summary>
        /// Write unknown attribute 
        /// </summary>
        /// <remarks> 
        /// For template parsing, the 'Set' tag is an unknown tag and contains properties that 
        /// are passed as UnknownAttributes.  Translate these into Property records.
        /// </remarks> 
        public override void WriteUnknownAttribute(XamlUnknownAttributeNode xamlUnknownAttributeNode)
        {
#if PBTCOMPILER
            bool localAttrib = false; 
            string localTagFullName = string.Empty;
            string localAttribName = xamlUnknownAttributeNode.Name; 
            NamespaceMapEntry[] namespaceMaps = null; 

            if (xamlUnknownAttributeNode.OwnerTypeFullName.Length > 0) 
            {
                // These are attributes on a local tag ...
                localTagFullName = xamlUnknownAttributeNode.OwnerTypeFullName;
                localAttrib = true; 
            }
            else 
            { 
                //  These are attributes on a non-local tag ...
                namespaceMaps = XamlTypeMapper.GetNamespaceMapEntries(xamlUnknownAttributeNode.XmlNamespace); 
                localAttrib = namespaceMaps != null && namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly;
            }

            if (localAttrib) 
            {
                // ... and if there are any periods in the attribute name, then ... 
                int lastIndex = localAttribName.LastIndexOf('.'); 

                if (-1 != lastIndex) 
                {
                    // ... these might be attached props or events defined by a locally defined component,
                    // but being set on this non-local tag.
 
                    string ownerTagName = localAttribName.Substring(0, lastIndex);
 
                    if (namespaceMaps != null) 
                    {
                        if (namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly) 
                        {
                            localTagFullName = namespaceMaps[0].ClrNamespace + "." + ownerTagName;
                        }
                    } 
                    else
                    { 
                        TypeAndSerializer typeAndSerializer = XamlTypeMapper.GetTypeOnly(xamlUnknownAttributeNode.XmlNamespace, 
                                                                                 ownerTagName);
 
                        if (typeAndSerializer != null)
                        {
                            Type ownerTagType = typeAndSerializer.ObjectType;
                            localTagFullName = ownerTagType.FullName; 
                        }
                        else 
                        { 
                            namespaceMaps = XamlTypeMapper.GetNamespaceMapEntries(xamlUnknownAttributeNode.XmlNamespace);
                            if (namespaceMaps != null && namespaceMaps.Length == 1 && namespaceMaps[0].LocalAssembly) 
                            {
                                localTagFullName = namespaceMaps[0].ClrNamespace + "." + ownerTagName;
                            }
                            else 
                            {
                                localTagFullName = string.Empty; 
                            } 
                        }
                    } 

                    localAttribName = localAttribName.Substring(lastIndex + 1);
                }
            } 

            if (localTagFullName.Length == 0 || !IsLocalPass1) 
            { 
#endif
                base.WriteUnknownAttribute(xamlUnknownAttributeNode); 
#if PBTCOMPILER
            }
#endif
        } 
示例#4
0
 /// <summary>
 /// Write unknown attribute
 /// </summary>
 public virtual void WriteUnknownAttribute(XamlUnknownAttributeNode xamlUnknownAttributeNode)
 {
     // The default action for unknown attributes is throw an exception.
     ThrowException(SRID.ParserUnknownAttribute ,
                 xamlUnknownAttributeNode.Name,
                 xamlUnknownAttributeNode.XmlNamespace,
                 xamlUnknownAttributeNode.LineNumber,
                 xamlUnknownAttributeNode.LinePosition);
 }