Пример #1
0
 public XObjectsNamespaceList(string namespaces, string targetNamespace)
 {
     this.targetNamespace = targetNamespace;
     this.namespaces      = namespaces;
     if (namespaces == "##any" || namespaces.Length == 0)
     {
         type = ListType.Any;
     }
     else if (namespaces == "##other")
     {
         type = ListType.Other;
     }
     else
     {
         type = ListType.Set;
         set  = new Hashtable();
         foreach (string ns in XmlConvertExt.SplitString(namespaces))
         {
             if (ns == "##local")
             {
                 set[string.Empty] = string.Empty;
             }
             else if (ns == "##targetNamespace")
             {
                 set[targetNamespace] = targetNamespace;
             }
             else
             {
                 XmlConvertExt.ToUri(ns); // can throw
                 set[ns] = ns;
             }
         }
     }
 }
Пример #2
0
        internal static Uri ToUri(string s)
        {
            Uri uri;

            if ((s == null ? false : s.Length > 0))
            {
                s = XmlConvertExt.TrimString(s);
                if ((s.Length == 0 ? true : s.IndexOf("##", StringComparison.Ordinal) != -1))
                {
                    throw new FormatException();
                }
            }
            if (!Uri.TryCreate(s, UriKind.RelativeOrAbsolute, out uri))
            {
                throw new FormatException();
            }
            return(uri);
        }
 public XObjectsNamespaceList(string namespaces, string targetNamespace)
 {
     this.targetNamespace = targetNamespace;
     this.namespaces      = namespaces;
     if (!(namespaces == "##any" ? false : namespaces.Length != 0))
     {
         this.type = XObjectsNamespaceList.ListType.Any;
     }
     else if (!(namespaces == "##other"))
     {
         this.type = XObjectsNamespaceList.ListType.Set;
         this.@set = new Hashtable();
         string[] strArrays = XmlConvertExt.SplitString(namespaces);
         for (int i = 0; i < (int)strArrays.Length; i++)
         {
             string ns = strArrays[i];
             if (ns == "##local")
             {
                 this.@set[string.Empty] = string.Empty;
             }
             else if (!(ns == "##targetNamespace"))
             {
                 XmlConvertExt.ToUri(ns);
                 this.@set[ns] = ns;
             }
             else
             {
                 this.@set[targetNamespace] = targetNamespace;
             }
         }
     }
     else
     {
         this.type = XObjectsNamespaceList.ListType.Other;
     }
 }
Пример #4
0
        internal static Exception TryToUri(string s, out Uri result)
        {
            Exception formatException;

            result = null;
            if ((s == null ? false : s.Length > 0))
            {
                s = XmlConvertExt.TrimString(s);
                if ((s.Length == 0 ? true : s.IndexOf("##", StringComparison.Ordinal) != -1))
                {
                    formatException = new FormatException();
                    return(formatException);
                }
            }
            if (Uri.TryCreate(s, UriKind.RelativeOrAbsolute, out result))
            {
                formatException = null;
            }
            else
            {
                formatException = new FormatException();
            }
            return(formatException);
        }
        private Exception CheckBuiltInFacets(string s, XmlTypeCode typeCode, bool verifyUri)
        {
            Exception exception = null;

            switch (typeCode)
            {
            case XmlTypeCode.AnyUri:

                if (verifyUri)
                {
                    Uri uri = null;
                    exception = XmlConvertExt.TryToUri(s, out uri);
                }
                break;

            case XmlTypeCode.NormalizedString:
                exception = XmlConvertExt.VerifyNormalizedString(s);
                break;

            case XmlTypeCode.Token:
                try
                {
                    XmlConvert.VerifyTOKEN(s);
                }
                catch (Exception e)
                {
                    exception = e;
                }
                break;

            case XmlTypeCode.Language:
                if (s == null || s.Length == 0)
                {
                    exception = new LinqToXsdException();
                }
                if (!LanguagePattern.IsMatch(s))
                {
                    exception = new LinqToXsdException();
                }
                break;

            case XmlTypeCode.NmToken:
                try
                {
                    XmlConvert.VerifyNMTOKEN(s);
                }
                catch (Exception e)
                {
                    exception = e;
                }
                break;

            case XmlTypeCode.Name:
                try
                {
                    XmlConvert.VerifyName(s);
                }
                catch (Exception e) {
                    exception = e;
                }

                break;

            case XmlTypeCode.NCName:
            case XmlTypeCode.Id:
            case XmlTypeCode.Idref:
            case XmlTypeCode.Entity:
                try
                {
                    XmlConvert.VerifyNCName(s);
                }
                catch (Exception e)
                {
                    exception = e;
                }
                break;

            default:
                break;
            }
            return(exception);
        }
        private Exception CheckBuiltInFacets(string s, XmlTypeCode typeCode, bool verifyUri)
        {
            Exception exception = null;

            switch (typeCode)
            {
            case XmlTypeCode.AnyUri:
            {
                if (verifyUri)
                {
                    Uri uri = null;
                    exception = XmlConvertExt.TryToUri(s, out uri);
                }
                break;
            }

            case XmlTypeCode.QName:
            case XmlTypeCode.Notation:
            {
                break;
            }

            case XmlTypeCode.NormalizedString:
            {
                exception = XmlConvertExt.VerifyNormalizedString(s);
                break;
            }

            case XmlTypeCode.Token:
            {
                try
                {
                    XmlConvert.VerifyTOKEN(s);
                }
                catch (Exception exception1)
                {
                    exception = exception1;
                }
                break;
            }

            case XmlTypeCode.Language:
            {
                if ((s == null ? true : s.Length == 0))
                {
                    exception = new LinqToXsdException();
                }
                if (!Xml.Schema.Linq.StringFacetsChecker.LanguagePattern.IsMatch(s))
                {
                    exception = new LinqToXsdException();
                }
                break;
            }

            case XmlTypeCode.NmToken:
            {
                try
                {
                    XmlConvert.VerifyNMTOKEN(s);
                }
                catch (Exception exception2)
                {
                    exception = exception2;
                }
                break;
            }

            case XmlTypeCode.Name:
            {
                try
                {
                    XmlConvert.VerifyName(s);
                }
                catch (Exception exception3)
                {
                    exception = exception3;
                }
                break;
            }

            case XmlTypeCode.NCName:
            case XmlTypeCode.Id:
            case XmlTypeCode.Idref:
            case XmlTypeCode.Entity:
            {
                try
                {
                    XmlConvert.VerifyNCName(s);
                }
                catch (Exception exception4)
                {
                    exception = exception4;
                }
                break;
            }

            default:
            {
                goto case XmlTypeCode.Notation;
            }
            }
            return(exception);
        }