InitializeUri() private method

private InitializeUri ( ParsingError err, UriKind uriKind, UriFormatException &e ) : void
err ParsingError
uriKind UriKind
e UriFormatException
return void
Example #1
0
        //
        // a Uri.TryCreate() method goes through here.
        //
        internal static Uri CreateHelper(string uriString, bool dontEscape, UriKind uriKind, ref UriFormatException e)
        {
            // if (!Enum.IsDefined(typeof(UriKind), uriKind)) -- We currently believe that Enum.IsDefined() is too slow
            // to be used here.
            if ((int)uriKind < (int)UriKind.RelativeOrAbsolute || (int)uriKind > (int)UriKind.Relative)
            {
#if MONO
                if (uriKind != DotNetRelativeOrAbsolute)
#endif
                throw new ArgumentException(SR.GetString(SR.net_uri_InvalidUriKind, uriKind));
            }

            UriParser    syntax = null;
            Flags        flags  = Flags.Zero;
            ParsingError err    = ParseScheme(uriString, ref flags, ref syntax);

            if (dontEscape)
            {
                flags |= Flags.UserEscaped;
            }

            // We won't use User factory for these errors
            if (err != ParsingError.None)
            {
                // If it looks as a relative Uri, custom factory is ignored
                if (uriKind != UriKind.Absolute && err <= ParsingError.LastRelativeUriOkErrIndex)
                {
                    return(new Uri((flags & Flags.UserEscaped), null, uriString));
                }

                return(null);
            }

            // Cannot be relative Uri if came here
            Uri result = new Uri(flags, syntax, uriString);

            // Validate instance using ether built in or a user Parser
            try
            {
                result.InitializeUri(err, uriKind, out e);

                if (e == null)
                {
                    return(result);
                }

                return(null);
            }
            catch (UriFormatException ee)
            {
                Debug.Assert(!syntax.IsSimple, "A UriPraser threw on InitializeAndValidate.");
                e = ee;
                // A precaution since custom Parser should never throw in this case.
                return(null);
            }
        }
Example #2
0
        //
        // a Uri.TryCreate() method goes through here.
        //
        internal static Uri CreateHelper(string uriString, bool dontEscape, UriKind uriKind, ref UriFormatException e)
        {
            // if (!Enum.IsDefined(typeof(UriKind), uriKind)) -- We currently believe that Enum.IsDefined() is too slow 
            // to be used here.
            if ((int)uriKind < (int)UriKind.RelativeOrAbsolute || (int)uriKind > (int)UriKind.Relative){
                throw new ArgumentException(SR.GetString(SR.net_uri_InvalidUriKind, uriKind));
            }

            UriParser syntax = null;
            Flags flags = Flags.Zero;
            ParsingError err = ParseScheme(uriString, ref flags, ref syntax);

            if (dontEscape)
                flags |= Flags.UserEscaped;

            // We won't use User factory for these errors
            if (err != ParsingError.None)
            {
                // If it looks as a relative Uri, custom factory is ignored
                if (uriKind != UriKind.Absolute && err <= ParsingError.LastRelativeUriOkErrIndex)
                    return new Uri((flags & Flags.UserEscaped), null, uriString);

                return null;
            }

            // Cannot be relative Uri if came here
            Uri result = new Uri(flags, syntax, uriString);

            // Validate instance using ether built in or a user Parser
            try
            {
                result.InitializeUri(err, uriKind, out e);

                if (e == null)
                    return result;

                return null;
            }
            catch (UriFormatException ee)
            {
                Debug.Assert(!syntax.IsSimple, "A UriPraser threw on InitializeAndValidate.");
                e = ee;
                // A precaution since custom Parser should never throw in this case.
                return null;
            }
        }
 internal static Uri CreateHelper(string uriString, bool dontEscape, UriKind uriKind, ref UriFormatException e)
 {
     if ((uriKind < UriKind.RelativeOrAbsolute) || (uriKind > UriKind.Relative))
     {
         throw new ArgumentException(System.SR.GetString("net_uri_InvalidUriKind", new object[] { uriKind }));
     }
     UriParser syntax = null;
     Flags hostNotParsed = Flags.HostNotParsed;
     ParsingError err = ParseScheme(uriString, ref hostNotParsed, ref syntax);
     if (dontEscape)
     {
         hostNotParsed |= Flags.HostNotParsed | Flags.UserEscaped;
     }
     if (err != ParsingError.None)
     {
         if ((uriKind != UriKind.Absolute) && (err <= ParsingError.EmptyUriString))
         {
             return new Uri(hostNotParsed & (Flags.HostNotParsed | Flags.UserEscaped), null, uriString);
         }
         return null;
     }
     Uri uri = new Uri(hostNotParsed, syntax, uriString);
     try
     {
         uri.InitializeUri(err, uriKind, out e);
         if (e == null)
         {
             return uri;
         }
         return null;
     }
     catch (UriFormatException exception)
     {
         e = exception;
         return null;
     }
 }