예제 #1
0
        private ICollection <XamlType> LookupAllTypes()
        {
            List <XamlType> list = new List <XamlType>();

            if (this.IsResolved)
            {
                foreach (AssemblyNamespacePair pair in this._assemblyNamespaces)
                {
                    Assembly assembly = pair.Assembly;
                    if (assembly != null)
                    {
                        string clrNamespace = pair.ClrNamespace;
                        foreach (Type type in assembly.GetTypes())
                        {
                            if (KS.Eq(type.Namespace, clrNamespace))
                            {
                                XamlType xamlType = this.SchemaContext.GetXamlType(type);
                                list.Add(xamlType);
                            }
                        }
                    }
                }
            }
            return(list.AsReadOnly());
        }
예제 #2
0
        private string GetPrefixForClrNs(string clrNs, string assemblyName)
        {
            if (string.IsNullOrEmpty(assemblyName))
            {
                return("local");
            }
            StringBuilder builder = new StringBuilder();

            foreach (string str in clrNs.Split(new char[] { '.' }))
            {
                if (!string.IsNullOrEmpty(str))
                {
                    builder.Append(char.ToLower(str[0], TypeConverterHelper.InvariantEnglishUS));
                }
            }
            if (builder.Length <= 0)
            {
                return("local");
            }
            string a = builder.ToString();

            if (KS.Eq(a, "x"))
            {
                return("p");
            }
            if (KS.Eq(a, "xml"))
            {
                return("p");
            }
            return(a);
        }
예제 #3
0
        private ICollection <XamlType> LookupAllTypes()
        {
            List <XamlType> xamlTypeList = new List <XamlType>();

            if (IsResolved)
            {
                foreach (AssemblyNamespacePair assemblyNamespacePair in _assemblyNamespaces)
                {
                    Assembly asm = assemblyNamespacePair.Assembly;
                    if (asm == null)
                    {
                        // This is a dynamic assembly that got unloaded; ignore it
                        continue;
                    }
                    string clrPrefix = assemblyNamespacePair.ClrNamespace;

                    Type[] types = asm.GetTypes();

                    foreach (Type t in types)
                    {
                        if (!KS.Eq(t.Namespace, clrPrefix))
                        {
                            continue;
                        }

                        XamlType xamlType = SchemaContext.GetXamlType(t);
                        xamlTypeList.Add(xamlType);
                    }
                }
            }
            return(xamlTypeList.AsReadOnly());
        }
예제 #4
0
        private void PreprocessForTypeArguments(List <XamlAttribute> attrList)
        {
            int typeArgsIdx = -1;

            for (int i = 0; i < attrList.Count; i++)
            {
                XamlAttribute attr = attrList[i];

                // Find x:TypeArguments if it was present.
                if (KS.Eq(attr.Name.Name, XamlLanguage.TypeArguments.Name))
                {
                    string     attrNamespace     = _parserContext.FindNamespaceByPrefix(attr.Name.Prefix);
                    XamlMember directiveProperty = _parserContext.ResolveDirectiveProperty(attrNamespace, attr.Name.Name);
                    if (directiveProperty != null)
                    {
                        typeArgsIdx            = i;
                        _typeArgumentAttribute = attr;
                        break;
                    }
                }
            }
            if (typeArgsIdx >= 0)
            {
                attrList.RemoveAt(typeArgsIdx);
            }
        }
예제 #5
0
파일: MeScanner.cs 프로젝트: redmcg/wpf
        private void ResolveTypeName(string longName)
        {
            string       error;
            XamlTypeName typeName = XamlTypeName.ParseInternal(longName, _context.FindNamespaceByPrefix, out error);

            if (typeName == null)
            {
                throw new XamlParseException(this, error);
            }

            // In curly form, we search for TypeName + 'Extension' before TypeName
            string bareTypeName = typeName.Name;

            typeName.Name = typeName.Name + KnownStrings.Extension;
            XamlType xamlType = _context.GetXamlType(typeName, false);

            // This would be cleaner if we moved the Extension fallback logic out of XSC
            if (xamlType == null ||
                // Guard against Extension getting added twice
                (xamlType.UnderlyingType != null &&
                 KS.Eq(xamlType.UnderlyingType.Name, typeName.Name + KnownStrings.Extension)))
            {
                typeName.Name = bareTypeName;
                xamlType      = _context.GetXamlType(typeName, true);
            }

            _tokenXamlType  = xamlType;
            _tokenNamespace = typeName.Namespace;
        }
예제 #6
0
        private static bool TryParseUri(string uriInput, out string clrNs, out string assemblyName, out string error, bool returnErrors)
        {
            clrNs        = null;
            assemblyName = null;
            error        = null;
            int index = KS.IndexOf(uriInput, ":");

            if (-1 == index)
            {
                if (returnErrors)
                {
                    error = System.Xaml.SR.Get("MissingTagInNamespace", new object[] { ":", uriInput });
                }
                return(false);
            }
            if (!KS.Eq(uriInput.Substring(0, index), "clr-namespace"))
            {
                if (returnErrors)
                {
                    error = System.Xaml.SR.Get("MissingTagInNamespace", new object[] { "clr-namespace", uriInput });
                }
                return(false);
            }
            int startIndex = index + 1;
            int num3       = KS.IndexOf(uriInput, ";");

            if (-1 == num3)
            {
                clrNs        = uriInput.Substring(startIndex);
                assemblyName = null;
                return(true);
            }
            int length = num3 - startIndex;

            clrNs = uriInput.Substring(startIndex, length);
            int num5 = num3 + 1;
            int num6 = KS.IndexOf(uriInput, "=");

            if (-1 == num6)
            {
                if (returnErrors)
                {
                    error = System.Xaml.SR.Get("MissingTagInNamespace", new object[] { "=", uriInput });
                }
                return(false);
            }
            if (!KS.Eq(uriInput.Substring(num5, num6 - num5), "assembly"))
            {
                if (returnErrors)
                {
                    error = System.Xaml.SR.Get("AssemblyTagMissing", new object[] { "assembly", uriInput });
                }
                return(false);
            }
            assemblyName = uriInput.Substring(num6 + 1);
            return(true);
        }
예제 #7
0
        public static bool TryParseUri(string uriInput, out string clrNs, out string assemblyName)
        {
            clrNs        = null;
            assemblyName = null;

            // xmlns:foo="clr-namespace:System.Windows;assembly=myassemblyname"
            // xmlns:bar="clr-namespace:MyAppsNs"
            // xmlns:spam="clr-namespace:MyAppsNs;assembly="

            int colonIdx = KS.IndexOf(uriInput, ":");

            if (colonIdx == -1)
            {
                return(false);
            }

            string keyword = uriInput.Substring(0, colonIdx);

            if (!KS.Eq(keyword, KnownStrings.UriClrNamespace))
            {
                return(false);
            }

            int clrNsStartIdx = colonIdx + 1;
            int semicolonIdx  = KS.IndexOf(uriInput, ";");

            if (semicolonIdx == -1)
            {
                clrNs        = uriInput.Substring(clrNsStartIdx);
                assemblyName = null;
                return(true);
            }
            else
            {
                int clrnsLength = semicolonIdx - clrNsStartIdx;
                clrNs = uriInput.Substring(clrNsStartIdx, clrnsLength);
            }

            int assemblyKeywordStartIdx = semicolonIdx + 1;
            int equalIdx = KS.IndexOf(uriInput, "=");

            if (equalIdx == -1)
            {
                return(false);
            }

            keyword = uriInput.Substring(assemblyKeywordStartIdx, equalIdx - assemblyKeywordStartIdx);
            if (!KS.Eq(keyword, KnownStrings.UriAssembly))
            {
                return(false);
            }

            assemblyName = uriInput.Substring(equalIdx + 1);
            return(true);
        }
예제 #8
0
 private void StripUidProperty()
 {
     for (int i = _attributes.Count - 1; i >= 0; i--)
     {
         if (KS.Eq(_attributes[i].Name.ScopedName, XamlLanguage.Uid.Name))
         {
             _attributes.RemoveAt(i);
         }
     }
     if (_attributes.Count == 0)
     {
         _attributes = null;
     }
 }
 internal bool CheckIsXmlNamespaceDefinition(out string definingPrefix, out string uri)
 {
     uri            = string.Empty;
     definingPrefix = string.Empty;
     if (KS.Eq(this.Name.Prefix, "xmlns"))
     {
         uri            = this.Value;
         definingPrefix = !this.Name.IsDotted ? this.Name.Name : (this.Name.OwnerName + "." + this.Name.Name);
         return(true);
     }
     if (string.IsNullOrEmpty(this.Name.Prefix) && KS.Eq(this.Name.Name, "xmlns"))
     {
         uri            = this.Value;
         definingPrefix = string.Empty;
         return(true);
     }
     return(false);
 }
예제 #10
0
 private void UpdatePreferredPrefixes(XmlNsInfo newNamespaces, ConcurrentDictionary <string, string> prefixDict)
 {
     foreach (KeyValuePair <string, string> pair in newNamespaces.Prefixes)
     {
         string str;
         string preferredPrefix = pair.Value;
         if (!prefixDict.TryGetValue(pair.Key, out str))
         {
             str = TryAdd <string, string>(prefixDict, pair.Key, preferredPrefix);
         }
         while (str != preferredPrefix)
         {
             preferredPrefix = XmlNsInfo.GetPreferredPrefix(str, preferredPrefix);
             if (!KS.Eq(preferredPrefix, str))
             {
                 str = TryUpdate <string, string>(prefixDict, pair.Key, preferredPrefix, str);
             }
         }
     }
 }
        private void ResolveTypeName(string longName)
        {
            string       str;
            XamlTypeName typeName = XamlTypeName.ParseInternal(longName, new Func <string, string>(this._context.FindNamespaceByPrefix), out str);

            if (typeName == null)
            {
                throw new XamlParseException(this, str);
            }
            string name = typeName.Name;

            typeName.Name = typeName.Name + "Extension";
            XamlType xamlType = this._context.GetXamlType(typeName, false);

            if ((xamlType == null) || ((xamlType.UnderlyingType != null) && KS.Eq(xamlType.UnderlyingType.Name, typeName.Name + "Extension")))
            {
                typeName.Name = name;
                xamlType      = this._context.GetXamlType(typeName, true);
            }
            this._tokenXamlType  = xamlType;
            this._tokenNamespace = typeName.Namespace;
        }
예제 #12
0
        //  ========================== internal ================================

        internal bool CheckIsXmlNamespaceDefinition(out string definingPrefix, out string uri)
        {
            uri            = string.Empty;
            definingPrefix = string.Empty;

            // case where:  xmlns:pre="ValueUri"
            if (KS.Eq(Name.Prefix, KnownStrings.XmlNsPrefix))
            {
                uri            = Value;
                definingPrefix = !Name.IsDotted
                    ? Name.Name
                    : Name.OwnerName + "." + Name.Name;
                return(true);
            }
            // case where:  xmlns="ValueUri"
            if (String.IsNullOrEmpty(Name.Prefix) && KS.Eq(Name.Name, KnownStrings.XmlNsPrefix))
            {
                uri            = Value;
                definingPrefix = string.Empty;
                return(true);
            }
            return(false);
        }
예제 #13
0
        private void PreprocessForTypeArguments(List <XamlAttribute> attrList)
        {
            int index = -1;

            for (int i = 0; i < attrList.Count; i++)
            {
                XamlAttribute attribute = attrList[i];
                if (KS.Eq(attribute.Name.Name, XamlLanguage.TypeArguments.Name))
                {
                    string xamlNS = this._parserContext.FindNamespaceByPrefix(attribute.Name.Prefix);
                    if (this._parserContext.ResolveDirectiveProperty(xamlNS, attribute.Name.Name) != null)
                    {
                        index = i;
                        this._typeArgumentAttribute = attribute;
                        break;
                    }
                }
            }
            if (index >= 0)
            {
                attrList.RemoveAt(index);
            }
        }
예제 #14
0
 private bool IsXDataElement(string xmlns, string name)
 {
     return
         (XamlLanguage.XamlNamespaces.Contains(xmlns) &&
          KS.Eq(XamlLanguage.XData.Name, name));
 }
예제 #15
0
        private void EnqueueAnotherAttribute(bool isEmptyTag)
        {
            XamlAttribute   attr = _attributes[_nextAttribute++];
            XamlScannerNode node = new XamlScannerNode(attr);

            switch (attr.Kind)
            {
            case ScannerAttributeKind.Directive:
            case ScannerAttributeKind.Name:
            case ScannerAttributeKind.CtorDirective:
                node.NodeType = ScannerNodeType.DIRECTIVE;
                break;

            case ScannerAttributeKind.XmlSpace:
                // Empty tags don't have a stack frame to write on.
                // Empty XML tags don't have content to process spaces.
                if (!isEmptyTag)
                {
                    if (KS.Eq(attr.Value, KnownStrings.Preserve))
                    {
                        _scannerStack.CurrentXmlSpacePreserve = true;
                    }
                    else
                    {
                        _scannerStack.CurrentXmlSpacePreserve = false;
                    }
                }
                node.NodeType = ScannerNodeType.DIRECTIVE;
                break;

            case ScannerAttributeKind.Event:
            case ScannerAttributeKind.Property:
                node.IsCtorForcingMember = true;
                node.NodeType            = ScannerNodeType.ATTRIBUTE;
                break;

            case ScannerAttributeKind.Unknown:
                XamlMember prop = attr.Property;
                Debug.Assert(prop.IsUnknown);
                // force use of Ctor for unknown simple properties only
                node.IsCtorForcingMember = !prop.IsAttachable && !prop.IsDirective;
                node.NodeType            = ScannerNodeType.ATTRIBUTE;
                break;

            case ScannerAttributeKind.AttachableProperty:
                node.NodeType = ScannerNodeType.ATTRIBUTE;
                break;

            default:
                throw new XamlInternalException(SR.Get(SRID.AttributeUnhandledKind));
            }

            // (GetFixedDocumentSequence raises Exception "UnicodeString property does not
            // contain enough characters to correspond to the contents of Indices property.")
            //
            // XamlText.Paste normally converts CRLF to LF, even in attribute values.
            // When the property is Glyphs.UnicodeString, disable this;
            // the length of the string must correspond to the number of entries in
            // the corresponding Glyphs.Indices property.
            XamlMember attrProperty    = attr.Property;
            bool       convertCRLFtoLF =
                !(attrProperty != null &&
                  attrProperty.Name == "UnicodeString" &&
                  attrProperty.DeclaringType.Name == "Glyphs");

            node.PropertyAttribute = attrProperty;
            XamlText xamlText = new XamlText(true);  // Don't collapse spaces in attributes

            xamlText.Paste(attr.Value, false, convertCRLFtoLF);
            node.PropertyAttributeText = xamlText;
            node.Prefix = attr.Name.Prefix;

            _readNodesQueue.Enqueue(node);

            if (_nextAttribute >= _attributes.Count)
            {
                _attributes    = null;
                _nextAttribute = -1;
            }
        }
예제 #16
0
        private void EnqueueAnotherAttribute(bool isEmptyTag)
        {
            XamlAttribute   attr = this._attributes[this._nextAttribute++];
            XamlScannerNode item = new XamlScannerNode(attr);

            switch (attr.Kind)
            {
            case ScannerAttributeKind.CtorDirective:
            case ScannerAttributeKind.Name:
            case ScannerAttributeKind.Directive:
                item.NodeType = ScannerNodeType.DIRECTIVE;
                goto Label_00F3;

            case ScannerAttributeKind.XmlSpace:
                if (!isEmptyTag)
                {
                    if (!KS.Eq(attr.Value, "preserve"))
                    {
                        this._scannerStack.CurrentXmlSpacePreserve = false;
                        break;
                    }
                    this._scannerStack.CurrentXmlSpacePreserve = true;
                }
                break;

            case ScannerAttributeKind.Event:
            case ScannerAttributeKind.Property:
                item.IsCtorForcingMember = true;
                item.NodeType            = ScannerNodeType.ATTRIBUTE;
                goto Label_00F3;

            case ScannerAttributeKind.AttachableProperty:
                item.NodeType = ScannerNodeType.ATTRIBUTE;
                goto Label_00F3;

            case ScannerAttributeKind.Unknown:
            {
                XamlMember property = attr.Property;
                item.IsCtorForcingMember = !property.IsAttachable && !property.IsDirective;
                item.NodeType            = ScannerNodeType.ATTRIBUTE;
                goto Label_00F3;
            }

            default:
                throw new XamlInternalException(System.Xaml.SR.Get("AttributeUnhandledKind"));
            }
            item.NodeType = ScannerNodeType.DIRECTIVE;
Label_00F3:
            item.PropertyAttribute = attr.Property;
            XamlText text = new XamlText(true);

            text.Paste(attr.Value, false);
            item.PropertyAttributeText = text;
            item.Prefix = attr.Name.Prefix;
            this._readNodesQueue.Enqueue(item);
            if (this._nextAttribute >= this._attributes.Count)
            {
                this._attributes    = null;
                this._nextAttribute = -1;
            }
        }
예제 #17
0
        private static bool TryParseUri(string uriInput, out string clrNs, out string assemblyName,
                                        out string error, bool returnErrors)
        {
            clrNs        = null;
            assemblyName = null;
            error        = null;

            // xmlns:foo="clr-namespace:System.Windows;assembly=myassemblyname"
            // xmlns:bar="clr-namespace:MyAppsNs"
            // xmlns:spam="clr-namespace:MyAppsNs;assembly="

            int colonIdx = KS.IndexOf(uriInput, ":");

            if (-1 == colonIdx)
            {
                if (returnErrors)
                {
                    error = SR.Get(SRID.MissingTagInNamespace, ":", uriInput);
                }
                return(false);
            }

            string keyword = uriInput.Substring(0, colonIdx);

            if (!KS.Eq(keyword, KnownStrings.UriClrNamespace))
            {
                if (returnErrors)
                {
                    error = SR.Get(SRID.MissingTagInNamespace, KnownStrings.UriClrNamespace, uriInput);
                }
                return(false);
            }

            int clrNsStartIdx = colonIdx + 1;
            int semicolonIdx  = KS.IndexOf(uriInput, ";");

            if (-1 == semicolonIdx)
            {
                clrNs        = uriInput.Substring(clrNsStartIdx);
                assemblyName = null;
                return(true);
            }
            else
            {
                int clrnsLength = semicolonIdx - clrNsStartIdx;
                clrNs = uriInput.Substring(clrNsStartIdx, clrnsLength);
            }

            int assemblyKeywordStartIdx = semicolonIdx + 1;
            int equalIdx = KS.IndexOf(uriInput, "=");

            if (-1 == equalIdx)
            {
                if (returnErrors)
                {
                    error = SR.Get(SRID.MissingTagInNamespace, "=", uriInput);
                }
                return(false);
            }
            keyword = uriInput.Substring(assemblyKeywordStartIdx, equalIdx - assemblyKeywordStartIdx);
            if (!KS.Eq(keyword, KnownStrings.UriAssembly))
            {
                if (returnErrors)
                {
                    error = SR.Get(SRID.AssemblyTagMissing, KnownStrings.UriAssembly, uriInput);
                }
                return(false);
            }
            assemblyName = uriInput.Substring(equalIdx + 1);
            return(true);
        }