• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# UriFormat类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中UriFormat的典型用法代码示例。如果您正苦于以下问题:C# UriFormat类的具体用法?C# UriFormat怎么用?C# UriFormat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



UriFormat类属于命名空间,在下文中一共展示了UriFormat类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: ConstructorsShouldSetExpectedProperties

        public void ConstructorsShouldSetExpectedProperties( UriComponents components, UriFormat format, bool ignoreCase )
        {
            // arrange
            var target = new UriComparer( components, format, ignoreCase );

            // act
            
            // assert
            Assert.Equal( components, target.UriComponents );
            Assert.Equal( format, target.UriFormat );
            Assert.Equal( ignoreCase, target.IgnoreCase );
        }
开发者ID:WaffleSquirrel,项目名称:More,代码行数:12,代码来源:UriComparerTest.cs


示例2: GetComponents

		// protected methods
		protected internal virtual string GetComponents (Uri uri, UriComponents components, UriFormat format)
		{
			if ((format < UriFormat.UriEscaped) || (format > UriFormat.SafeUnescaped))
				throw new ArgumentOutOfRangeException ("format");

			if ((components & UriComponents.SerializationInfoString) != 0) {
				if (components != UriComponents.SerializationInfoString)
					throw new ArgumentOutOfRangeException ("components", "UriComponents.SerializationInfoString must not be combined with other UriComponents.");

				if (!uri.IsAbsoluteUri)
					return UriHelper.FormatRelative (uri.OriginalString, "", format);

				components |= UriComponents.AbsoluteUri;
			}

			return GetComponentsHelper (uri, components, format);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:18,代码来源:UriParser.cs


示例3: GetComponentsHelper

        internal string GetComponentsHelper(Uri uri, UriComponents components, UriFormat format)
        {
            UriElements elements = UriParseComponents.ParseComponents(uri.OriginalString.Trim(), UriKind.Absolute);

            string scheme = scheme_name;
            int dp = default_port;

            if ((scheme == null) || (scheme == "*"))
            {
                scheme = elements.scheme;
                dp = Uri.GetDefaultPort(scheme);
            }
            else if (String.Compare(scheme.ToLower(), elements.scheme.ToLower()) != 0)
            {
                throw new SystemException("URI Parser: scheme mismatch: " + scheme + " vs. " + elements.scheme);
            }

            var formatFlags = UriHelper.FormatFlags.None;
            if (UriHelper.HasCharactersToNormalize(uri.OriginalString))
                formatFlags |= UriHelper.FormatFlags.HasUriCharactersToNormalize;

            if (uri.UserEscaped)
                formatFlags |= UriHelper.FormatFlags.UserEscaped;

            if (!StringUtilities.IsNullOrEmpty(elements.host))
                formatFlags |= UriHelper.FormatFlags.HasHost;

            // it's easier to answer some case directly (as the output isn't identical
            // when mixed with others components, e.g. leading slash, # ...)
            switch (components)
            {
                case UriComponents.Scheme:
                    return scheme;
                case UriComponents.UserInfo:
                    return elements.user ?? "";
                case UriComponents.Host:
                    return elements.host;
                case UriComponents.Port:
                    {
                        int p = elements.port;
                        if (p >= 0 && p != dp)
                            return p.ToString();
                        return String.Empty;
                    }
                case UriComponents.Path:
                    var path = elements.path;
                    if (scheme != Uri.UriSchemeMailto && scheme != Uri.UriSchemeNews)
                        path = IgnoreFirstCharIf(elements.path, '/');
                    return UriHelper.FormatAbsolute(path, scheme, UriComponents.Path, format, formatFlags);
                case UriComponents.Query:
                    return UriHelper.FormatAbsolute(elements.query, scheme, UriComponents.Query, format, formatFlags);
                case UriComponents.Fragment:
                    return UriHelper.FormatAbsolute(elements.fragment, scheme, UriComponents.Fragment, format, formatFlags);
                case UriComponents.StrongPort:
                    {
                        return elements.port >= 0
                        ? elements.port.ToString()
                        : dp.ToString();
                    }
                case UriComponents.SerializationInfoString:
                    components = UriComponents.AbsoluteUri;
                    break;
            }

            // now we deal with multiple flags...

            StringBuilder sb = new StringBuilder();

            if ((components & UriComponents.Scheme) != 0)
            {
                sb.Append(scheme);
                sb.Append(elements.delimiter);
            }

            if ((components & UriComponents.UserInfo) != 0)
            {
                string userinfo = elements.user;
                if (userinfo != null)
                {
                    sb.Append(elements.user);
                    sb.Append('@');
                }
            }

            if ((components & UriComponents.Host) != 0)
                sb.Append(elements.host);

            // for StrongPort always show port - even if -1
            // otherwise only display if ut's not the default port
            if ((components & UriComponents.StrongPort) != 0)
            {
                sb.Append(":");
                if (elements.port >= 0)
                {
                    sb.Append(elements.port);
                }
                else
                {
                    sb.Append(dp);
                }
//.........这里部分代码省略.........
开发者ID:T-REX-XP,项目名称:serialwifi,代码行数:101,代码来源:UriParser.cs


示例4: GetComponents

		public string GetComponents (UriComponents components, UriFormat format)
		{
			return Parser.GetComponents (this, components, format);
		}
开发者ID:rmartinho,项目名称:mono,代码行数:4,代码来源:Uri.cs


示例5: Compare

        //
        //
        // This is for languages that do not support == != operators overloading
        //
        // Note that Uri.Equals will get an optimized path but is limited to true/fasle result only
        //
        public static int Compare(Uri uri1, Uri uri2, UriComponents partsToCompare, UriFormat compareFormat, 
            StringComparison comparisonType)
        {

            if ((object) uri1 == null)
            {
                if (uri2 == null)
                    return 0; // Equal
                return -1;    // null < non-null
            }
            if ((object) uri2 == null)
                return 1;     // non-null > null

            // a relative uri is always less than an absolute one
            if (!uri1.IsAbsoluteUri || !uri2.IsAbsoluteUri)
                return uri1.IsAbsoluteUri? 1: uri2.IsAbsoluteUri? -1: string.Compare(uri1.OriginalString, 
                    uri2.OriginalString, comparisonType);

            return string.Compare(
                                    uri1.GetParts(partsToCompare, compareFormat),
                                    uri2.GetParts(partsToCompare, compareFormat),
                                    comparisonType
                                  );
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:30,代码来源:UriExt.cs


示例6: GetComponentsHelper

        //
        // UriParser helpers methods
        //
        internal string GetComponentsHelper(UriComponents uriComponents, UriFormat uriFormat)
        {
            if (uriComponents == UriComponents.Scheme)
                return m_Syntax.SchemeName;

            // A serialzation info is "almost" the same as AbsoluteUri except for IPv6 + ScopeID hostname case
            if ((uriComponents & UriComponents.SerializationInfoString) != 0)
                uriComponents |= UriComponents.AbsoluteUri;

            //This will get all the offsets, HostString will be created below if needed
            EnsureParseRemaining();

            if ((uriComponents & UriComponents.NormalizedHost) != 0)
            {
                // Down the path we rely on Host to be ON for NormalizedHost
                uriComponents |= UriComponents.Host;
            }

            //Check to see if we need the host/authotity string
            if ((uriComponents & UriComponents.Host) != 0)
                EnsureHostString(true);

            //This, single Port request is always processed here
            if (uriComponents == UriComponents.Port || uriComponents == UriComponents.StrongPort)
            {
                if (((m_Flags & Flags.NotDefaultPort) != 0) || (uriComponents == UriComponents.StrongPort 
                    && m_Syntax.DefaultPort != UriParser.NoDefaultPort))
                {
                    // recreate string from the port value
                    return m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture);
                }
                return string.Empty;
            }

            if ((uriComponents & UriComponents.StrongPort) != 0)
            {
                // Down the path we rely on Port to be ON for StrongPort
                uriComponents |= UriComponents.Port;
            }

            //This request sometime is faster to process here
            if (uriComponents == UriComponents.Host && (uriFormat == UriFormat.UriEscaped 
                || (( m_Flags & (Flags.HostNotCanonical | Flags.E_HostNotCanonical)) == 0)))
            {
                EnsureHostString(false);
                return m_Info.Host;
            }

            switch (uriFormat)
            {
                case UriFormat.UriEscaped:
                    return GetEscapedParts(uriComponents);

                case V1ToStringUnescape:
                case UriFormat.SafeUnescaped:
                case UriFormat.Unescaped:
                    return GetUnescapedParts(uriComponents, uriFormat);

                default:
                    throw new ArgumentOutOfRangeException("uriFormat");
            }
        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:65,代码来源:UriExt.cs


示例7: GetComponents

		public string GetComponents (UriComponents components, UriFormat format)
		{
			if ((components & UriComponents.SerializationInfoString) == 0)
				EnsureAbsoluteUri ();

			return Parser.GetComponents (this, components, format);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:7,代码来源:Uri.cs


示例8: ReCreateParts

        private string ReCreateParts(UriComponents parts, ushort nonCanonical, UriFormat formatAs)
        {
            ushort num3;
            this.EnsureHostString(false);
            string input = ((parts & UriComponents.Host) == 0) ? string.Empty : this.m_Info.Host;
            int destinationIndex = (this.m_Info.Offset.End - this.m_Info.Offset.User) * ((formatAs == UriFormat.UriEscaped) ? 12 : 1);
            char[] destination = new char[(((input.Length + destinationIndex) + this.m_Syntax.SchemeName.Length) + 3) + 1];
            destinationIndex = 0;
            if ((parts & UriComponents.Scheme) != 0)
            {
                this.m_Syntax.SchemeName.CopyTo(0, destination, destinationIndex, this.m_Syntax.SchemeName.Length);
                destinationIndex += this.m_Syntax.SchemeName.Length;
                if (parts != UriComponents.Scheme)
                {
                    destination[destinationIndex++] = ':';
                    if (this.InFact(Flags.AuthorityFound))
                    {
                        destination[destinationIndex++] = '/';
                        destination[destinationIndex++] = '/';
                    }
                }
            }
            if (((parts & UriComponents.UserInfo) != 0) && this.InFact(Flags.HasUserInfo))
            {
                if ((nonCanonical & 2) == 0)
                {
                    UnescapeString(this.m_String, this.m_Info.Offset.User, this.m_Info.Offset.Host, destination, ref destinationIndex, 0xffff, 0xffff, 0xffff, UnescapeMode.CopyOnly, this.m_Syntax, false, false);
                }
                else
                {
                    switch (formatAs)
                    {
                        case UriFormat.UriEscaped:
                            if (!this.NotAny(Flags.HostNotParsed | Flags.UserEscaped))
                            {
                                this.InFact(Flags.E_UserNotCanonical);
                                this.m_String.CopyTo(this.m_Info.Offset.User, destination, destinationIndex, this.m_Info.Offset.Host - this.m_Info.Offset.User);
                                destinationIndex += this.m_Info.Offset.Host - this.m_Info.Offset.User;
                                break;
                            }
                            destination = EscapeString(this.m_String, this.m_Info.Offset.User, this.m_Info.Offset.Host, destination, ref destinationIndex, true, '?', '#', '%');
                            break;

                        case UriFormat.Unescaped:
                            destination = UnescapeString(this.m_String, this.m_Info.Offset.User, this.m_Info.Offset.Host, destination, ref destinationIndex, 0xffff, 0xffff, 0xffff, UnescapeMode.UnescapeAll | UnescapeMode.Unescape, this.m_Syntax, false, false);
                            break;

                        case UriFormat.SafeUnescaped:
                            destination = UnescapeString(this.m_String, this.m_Info.Offset.User, this.m_Info.Offset.Host - 1, destination, ref destinationIndex, '@', '/', '\\', this.InFact(Flags.HostNotParsed | Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape, this.m_Syntax, false, false);
                            destination[destinationIndex++] = '@';
                            break;

                        default:
                            destination = UnescapeString(this.m_String, this.m_Info.Offset.User, this.m_Info.Offset.Host, destination, ref destinationIndex, 0xffff, 0xffff, 0xffff, UnescapeMode.CopyOnly, this.m_Syntax, false, false);
                            break;
                    }
                }
                if (parts == UriComponents.UserInfo)
                {
                    destinationIndex--;
                }
            }
            if (((parts & UriComponents.Host) != 0) && (input.Length != 0))
            {
                UnescapeMode copyOnly;
                if (((formatAs != UriFormat.UriEscaped) && (this.HostType == Flags.BasicHostType)) && ((nonCanonical & 4) != 0))
                {
                    copyOnly = (formatAs == UriFormat.Unescaped) ? (UnescapeMode.UnescapeAll | UnescapeMode.Unescape) : (this.InFact(Flags.HostNotParsed | Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape);
                }
                else
                {
                    copyOnly = UnescapeMode.CopyOnly;
                }
                destination = UnescapeString(input, 0, input.Length, destination, ref destinationIndex, '/', '?', '#', copyOnly, this.m_Syntax, false, false);
                if ((((parts & UriComponents.SerializationInfoString) != 0) && (this.HostType == (Flags.HostNotParsed | Flags.IPv6HostType))) && (this.m_Info.ScopeId != null))
                {
                    this.m_Info.ScopeId.CopyTo(0, destination, destinationIndex - 1, this.m_Info.ScopeId.Length);
                    destinationIndex += this.m_Info.ScopeId.Length;
                    destination[destinationIndex - 1] = ']';
                }
            }
            if ((parts & UriComponents.Port) != 0)
            {
                if ((nonCanonical & 8) == 0)
                {
                    if (this.InFact(Flags.HostNotParsed | Flags.NotDefaultPort))
                    {
                        ushort path = this.m_Info.Offset.Path;
                        while (this.m_String[path = (ushort) (path - 1)] != ':')
                        {
                        }
                        this.m_String.CopyTo(path, destination, destinationIndex, this.m_Info.Offset.Path - path);
                        destinationIndex += this.m_Info.Offset.Path - path;
                    }
                    else if (((parts & UriComponents.StrongPort) != 0) && (this.m_Syntax.DefaultPort != -1))
                    {
                        destination[destinationIndex++] = ':';
                        input = this.m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture);
                        input.CopyTo(0, destination, destinationIndex, input.Length);
                        destinationIndex += input.Length;
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:Uri.cs


示例9: NeedToUnescape

		private static bool NeedToUnescape (char c, UriSchemes scheme, UriComponents component, UriKind uriKind,
			UriFormat uriFormat, FormatFlags formatFlags)
		{
			if ((formatFlags & FormatFlags.IPv6Host) != 0)
				return false;

			if (uriFormat == UriFormat.Unescaped)
				return true;

			UriSchemes sDecoders = UriSchemes.NetPipe | UriSchemes.NetTcp;

			if (!IriParsing)
				sDecoders |= UriSchemes.Http | UriSchemes.Https;

			if (c == '/' || c == '\\') {
				if (!IriParsing && uriKind == UriKind.Absolute && uriFormat != UriFormat.UriEscaped &&
					uriFormat != UriFormat.SafeUnescaped)
					return true;

				if (SchemeContains (scheme, UriSchemes.File)) {
					return component != UriComponents.Fragment &&
						   (component != UriComponents.Query || !IriParsing);
				}

				return component != UriComponents.Query && component != UriComponents.Fragment &&
					   SchemeContains (scheme, sDecoders);
			}

			if (c == '?') {
				//Avoid creating new query
				if (SupportsQuery (scheme) && component == UriComponents.Path)
					return false;

				if (!IriParsing && uriFormat == ToStringUnescape) {
					if (SupportsQuery (scheme))
						return component == UriComponents.Query || component == UriComponents.Fragment;

					return component == UriComponents.Fragment;
				}

				return false;
			}

			if (c == '#')
				return false;

			if (uriFormat == ToStringUnescape && !IriParsing) {
				if (uriKind == UriKind.Relative)
					return false;

				switch (c) {
				case '$':
				case '&':
				case '+':
				case ',':
				case ';':
				case '=':
				case '@':
					return true;
				}

				if (c < 0x20 || c == 0x7f)
					return true;
			}

			if (uriFormat == UriFormat.SafeUnescaped || uriFormat == ToStringUnescape) {
				switch (c) {
				case '-':
				case '.':
				case '_':
				case '~':
					return true;
				case ' ':
				case '!':
				case '"':
				case '\'':
				case '(':
				case ')':
				case '*':
				case '<':
				case '>':
				case '^':
				case '`':
				case '{':
				case '}':
				case '|':
					return uriKind != UriKind.Relative ||
						(IriParsing && (formatFlags & FormatFlags.HasUriCharactersToNormalize) != 0);
				case ':':
				case '[':
				case ']':
					return uriKind != UriKind.Relative;
				}

				if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))
					return true;

				if (c > 0x7f)
					return true;

//.........这里部分代码省略.........
开发者ID:Profit0004,项目名称:mono,代码行数:101,代码来源:UriHelper.cs


示例10: FormatChar

		private static string FormatChar (char c, char surrogate, string cStr, UriSchemes scheme, UriKind uriKind,
			UriComponents component, UriFormat uriFormat, FormatFlags formatFlags)
		{
			var isEscaped = cStr.Length != 1;

			var userEscaped = (formatFlags & FormatFlags.UserEscaped) != 0;
			if (!isEscaped && !userEscaped && NeedToEscape (c, scheme, component, uriKind, uriFormat, formatFlags))
				return HexEscapeMultiByte (c);

			if (isEscaped && (
				(userEscaped && c < 0xFF) ||
				!NeedToUnescape (c, scheme, component, uriKind, uriFormat, formatFlags))) {
				if (IriParsing &&
					(c == '<' || c == '>' || c == '^' || c == '{' || c == '|' || c ==  '}' || c > 0x7F) &&
					(formatFlags & FormatFlags.HasUriCharactersToNormalize) != 0)
					return cStr.ToUpperInvariant (); //Upper case escape

				return cStr; //Keep original case
			}

			if ((formatFlags & FormatFlags.NoSlashReplace) == 0 &&
				c == '\\' && component == UriComponents.Path) {
				if (!IriParsing && uriFormat != UriFormat.UriEscaped &&
					SchemeContains (scheme, UriSchemes.Http | UriSchemes.Https))
					return "/";

				if (SchemeContains (scheme, UriSchemes.Http | UriSchemes.Https | UriSchemes.Ftp | UriSchemes.CustomWithHost))
					return (isEscaped && uriFormat != UriFormat.UriEscaped) ? "\\" : "/";

				if (SchemeContains (scheme, UriSchemes.NetPipe | UriSchemes.NetTcp | UriSchemes.File))
					return "/";

				if (SchemeContains (scheme, UriSchemes.Custom) &&
					(formatFlags & FormatFlags.HasWindowsPath) == 0)
					return "/";
			}

			var ret = c.ToString (CultureInfo.InvariantCulture);
			if (surrogate != char.MinValue)
				ret += surrogate.ToString (CultureInfo.InvariantCulture);

			return ret;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:43,代码来源:UriHelper.cs


示例11: FormatString

		private static string FormatString (string str, UriSchemes scheme, UriKind uriKind,
			UriComponents component, UriFormat uriFormat, FormatFlags formatFlags)
		{
			var s = new StringBuilder ();
			int len = str.Length;
			for (int i = 0; i < len; i++) {
				char c = str [i];
				if (c == '%') {
					int iStart = i;
					char surrogate;
					bool invalidUnescape;
					char x = Uri.HexUnescapeMultiByte (str, ref i, out surrogate, out invalidUnescape);


					if (invalidUnescape
					) {
						s.Append (c);
						i = iStart;
						continue;
					}

					string cStr = str.Substring (iStart, i-iStart);
					s.Append (FormatChar (x, surrogate, cStr, scheme, uriKind, component, uriFormat, formatFlags));

					i--;
				} else
					s.Append (FormatChar (c, char.MinValue, "" + c, scheme, uriKind, component, uriFormat, formatFlags));
			}
			
			return s.ToString ();
		}
开发者ID:Profit0004,项目名称:mono,代码行数:31,代码来源:UriHelper.cs


示例12: Format

		private static string Format (string str, string schemeName, UriKind uriKind,
			UriComponents component, UriFormat uriFormat, FormatFlags formatFlags)
		{
			if (string.IsNullOrEmpty (str))
				return "";

			if (UriHelper.HasCharactersToNormalize (str))
				formatFlags |= UriHelper.FormatFlags.HasComponentCharactersToNormalize | FormatFlags.HasUriCharactersToNormalize;

			if (component == UriComponents.Fragment && UriHelper.HasPercentage (str))
				formatFlags |= UriHelper.FormatFlags.HasFragmentPercentage;

			if (component == UriComponents.Host &&
				str.Length > 1 && str [0] == '[' && str [str.Length - 1] == ']')
				 formatFlags |= UriHelper.FormatFlags.IPv6Host;

			if (component == UriComponents.Path &&
				str.Length >= 2 && str [1] != ':' &&
				('a' <= str [0] && str [0] <= 'z') || ('A' <= str [0] && str [0] <= 'Z'))
				formatFlags |= UriHelper.FormatFlags.HasWindowsPath;

			UriSchemes scheme = GetScheme (schemeName);

			if (scheme == UriSchemes.Custom && (formatFlags & FormatFlags.HasHost) != 0)
				scheme = UriSchemes.CustomWithHost;

			var reduceAfter = UriSchemes.Http | UriSchemes.Https | UriSchemes.File | UriSchemes.NetPipe | UriSchemes.NetTcp;

			if (IriParsing) {
				reduceAfter |= UriSchemes.Ftp;
			} else if (component == UriComponents.Path &&
				(formatFlags & FormatFlags.NoSlashReplace) == 0) {
				if (scheme == UriSchemes.Ftp)
					str = Reduce (str.Replace ('\\', '/'), !IriParsing);
				if (scheme == UriSchemes.CustomWithHost)
					str = Reduce (str.Replace ('\\', '/'), false);
			}

			str = FormatString (str, scheme, uriKind, component, uriFormat, formatFlags);

			if (component == UriComponents.Path &&
				(formatFlags & FormatFlags.NoReduce) == 0) {
				if (SchemeContains (scheme, reduceAfter))
					str = Reduce (str, !IriParsing);
				if (IriParsing && scheme == UriSchemes.CustomWithHost)
					str = Reduce (str, false);
			}

			return str;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:50,代码来源:UriHelper.cs


示例13: FormatRelative

		internal static string FormatRelative (string str, string schemeName, UriFormat uriFormat)
		{
			return Format (str, schemeName, UriKind.Relative, UriComponents.Path, uriFormat, FormatFlags.None);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:4,代码来源:UriHelper.cs


示例14: FormatAbsolute

		internal static string FormatAbsolute (string str, string schemeName,
			UriComponents component, UriFormat uriFormat, FormatFlags formatFlags = FormatFlags.None)
		{
			return Format (str, schemeName, UriKind.Absolute, component, uriFormat, formatFlags);
		}
开发者ID:Profit0004,项目名称:mono,代码行数:5,代码来源:UriHelper.cs


示例15: GetRelativeSerializationString

 private string GetRelativeSerializationString(UriFormat format)
 {
     if (format == UriFormat.UriEscaped)
     {
         if (this.m_String.Length == 0)
         {
             return string.Empty;
         }
         int destPos = 0;
         char[] chArray = EscapeString(this.m_String, 0, this.m_String.Length, null, ref destPos, true, 0xffff, 0xffff, '%');
         if (chArray == null)
         {
             return this.m_String;
         }
         return new string(chArray, 0, destPos);
     }
     if (format == UriFormat.Unescaped)
     {
         return UnescapeDataString(this.m_String);
     }
     if (format != UriFormat.SafeUnescaped)
     {
         throw new ArgumentOutOfRangeException("format");
     }
     if (this.m_String.Length == 0)
     {
         return string.Empty;
     }
     char[] dest = new char[this.m_String.Length];
     int length = 0;
     return new string(UnescapeString(this.m_String, 0, this.m_String.Length, dest, ref length, 0xffff, 0xffff, 0xffff, UnescapeMode.EscapeUnescape, null, false, true), 0, length);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:32,代码来源:Uri.cs


示例16: GetUnescapedParts

 private string GetUnescapedParts(UriComponents uriParts, UriFormat formatAs)
 {
     ushort nonCanonical = (ushort) (((ushort) this.m_Flags) & 0x7f);
     if ((uriParts & UriComponents.Path) != 0)
     {
         if ((this.m_Flags & (Flags.BackslashInPath | Flags.FirstSlashAbsent | Flags.ShouldBeCompressed)) != Flags.HostNotParsed)
         {
             nonCanonical = (ushort) (nonCanonical | 0x10);
         }
         else if (this.IsDosPath && (this.m_String[(this.m_Info.Offset.Path + this.SecuredPathIndex) - 1] == '|'))
         {
             nonCanonical = (ushort) (nonCanonical | 0x10);
         }
     }
     if ((((ushort) uriParts) & nonCanonical) == 0)
     {
         string uriPartsFromUserString = this.GetUriPartsFromUserString(uriParts);
         if (uriPartsFromUserString != null)
         {
             return uriPartsFromUserString;
         }
     }
     return this.ReCreateParts(uriParts, nonCanonical, formatAs);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:24,代码来源:Uri.cs


示例17: NeedToEscape

		private static bool NeedToEscape (char c, UriSchemes scheme, UriComponents component, UriKind uriKind,
			UriFormat uriFormat, FormatFlags formatFlags)
		{
			if ((formatFlags & FormatFlags.IPv6Host) != 0)
				return false;

			if (c == '?') {
				if (uriFormat == UriFormat.Unescaped)
					return false;

				if (!SupportsQuery (scheme))
					return component != UriComponents.Fragment;

				return false;
			}

			if (c == '#') {
				//Avoid removing fragment
				if (component == UriComponents.Path || component == UriComponents.Query)
					return false;

				if (component == UriComponents.Fragment &&
					(uriFormat == ToStringUnescape || uriFormat == UriFormat.SafeUnescaped) &&
					(formatFlags & FormatFlags.HasFragmentPercentage) != 0)
					return true;

				return false;
			}

			if (uriFormat == UriFormat.SafeUnescaped || uriFormat == ToStringUnescape) {
				if (c == '%')
					return uriKind != UriKind.Relative;
			}

			if (uriFormat == UriFormat.SafeUnescaped) {
				if (c < 0x20 || c == 0x7F)
					return true;
			}

			if (uriFormat == UriFormat.UriEscaped) {
				if (c < 0x20 || c >= 0x7F)
					return component != UriComponents.Host;

				switch (c) {
				case ' ':
				case '"':
				case '%':
				case '<':
				case '>':
				case '^':
				case '`':
				case '{':
				case '}':
				case '|':
					return true;
				case '[':
				case ']':
					return !IriParsing;
				case '\\':
					return component != UriComponents.Path ||
						   SchemeContains (scheme,
							   UriSchemes.Gopher | UriSchemes.Ldap | UriSchemes.Mailto | UriSchemes.Nntp |
							   UriSchemes.Telnet | UriSchemes.News | UriSchemes.Custom);
				}
			}

			return false;
		}
开发者ID:Profit0004,项目名称:mono,代码行数:68,代码来源:UriHelper.cs


示例18: GetComponents

        //
        // This method is invoked to allow a custom parser to override the
        // internal parser when serving application with Uri component strings.
        // The output format depends on the "format" parameter
        //
        // Parameters:
        //  uriComponents   - Which components are to be retrieved.
        //  uriFormat       - The requested output format.
        //
        // This method returns:
        // The final result. The base implementation could be invoked to get a suggested value
        //
        protected virtual string GetComponents(Uri uri, UriComponents components, UriFormat format)
        {
            if (((components & UriComponents.SerializationInfoString) != 0) && components != UriComponents.SerializationInfoString)
                throw new ArgumentOutOfRangeException(nameof(components), components, SR.net_uri_NotJustSerialization);

            if ((format & ~UriFormat.SafeUnescaped) != 0)
                throw new ArgumentOutOfRangeException(nameof(format));

            if (uri.UserDrivenParsing)
                throw new InvalidOperationException(SR.Format(SR.net_uri_UserDrivenParsing, this.GetType().ToString()));

            if (!uri.IsAbsoluteUri)
                throw new InvalidOperationException(SR.net_uri_NotAbsolute);

            return uri.GetComponentsHelper(components, format);
        }
开发者ID:Corillian,项目名称:corefx,代码行数:28,代码来源:UriScheme.cs


示例19: CombineUri

 private static string CombineUri(Uri basePart, string relativePart, UriFormat uriFormat)
 {
     string parts;
     int length;
     char[] chArray;
     char ch = relativePart[0];
     if ((basePart.IsDosPath && ((ch == '/') || (ch == '\\'))) && ((relativePart.Length == 1) || ((relativePart[1] != '/') && (relativePart[1] != '\\'))))
     {
         int index = basePart.OriginalString.IndexOf(':');
         if (!basePart.IsImplicitFile)
         {
             index = basePart.OriginalString.IndexOf(':', index + 1);
         }
         return (basePart.OriginalString.Substring(0, index + 1) + relativePart);
     }
     if (!StaticIsFile(basePart.Syntax) || ((ch != '\\') && (ch != '/')))
     {
         bool flag = basePart.Syntax.InFact(UriSyntaxFlags.ConvertPathSlashes);
         parts = null;
         if ((ch == '/') || ((ch == '\\') && flag))
         {
             if ((relativePart.Length >= 2) && (relativePart[1] == '/'))
             {
                 return (basePart.Scheme + ':' + relativePart);
             }
             if (basePart.HostType == (Flags.HostNotParsed | Flags.IPv6HostType))
             {
                 parts = string.Concat(new object[] { basePart.GetParts(UriComponents.UserInfo | UriComponents.Scheme, uriFormat), '[', basePart.DnsSafeHost, ']', basePart.GetParts(UriComponents.KeepDelimiter | UriComponents.Port, uriFormat) });
             }
             else
             {
                 parts = basePart.GetParts(UriComponents.SchemeAndServer | UriComponents.UserInfo, uriFormat);
             }
             if (flag && (ch == '\\'))
             {
                 relativePart = '/' + relativePart.Substring(1);
             }
             return (parts + relativePart);
         }
         parts = basePart.GetParts(UriComponents.KeepDelimiter | UriComponents.Path, basePart.IsImplicitFile ? UriFormat.Unescaped : uriFormat);
         length = parts.Length;
         chArray = new char[length + relativePart.Length];
         if (length > 0)
         {
             parts.CopyTo(0, chArray, 0, length);
             while (length > 0)
             {
                 if (chArray[--length] == '/')
                 {
                     length++;
                     break;
                 }
             }
         }
     }
     else
     {
         if ((relativePart.Length >= 2) && ((relativePart[1] == '\\') || (relativePart[1] == '/')))
         {
             if (!basePart.IsImplicitFile)
             {
                 return ("file:" + relativePart);
             }
             return relativePart;
         }
         if (!basePart.IsUnc)
         {
             return ("file://" + relativePart);
         }
         string str = basePart.GetParts(UriComponents.KeepDelimiter | UriComponents.Path, UriFormat.Unescaped);
         for (int i = 1; i < str.Length; i++)
         {
             if (str[i] == '/')
             {
                 str = str.Substring(0, i);
                 break;
             }
         }
         if (basePart.IsImplicitFile)
         {
             return (@"\\" + basePart.GetParts(UriComponents.Host, UriFormat.Unescaped) + str + relativePart);
         }
         return ("file://" + basePart.GetParts(UriComponents.Host, uriFormat) + str + relativePart);
     }
     relativePart.CopyTo(0, chArray, length, relativePart.Length);
     ch = basePart.Syntax.InFact(UriSyntaxFlags.MayHaveQuery) ? '?' : ((char) 0xffff);
     char ch2 = (!basePart.IsImplicitFile && basePart.Syntax.InFact(UriSyntaxFlags.MayHaveFragment)) ? '#' : ((char) 0xffff);
     string str3 = string.Empty;
     if ((ch == 0xffff) && (ch2 == 0xffff))
     {
         length += relativePart.Length;
     }
     else
     {
         int startIndex = 0;
         while (startIndex < relativePart.Length)
         {
             if ((chArray[length + startIndex] == ch) || (chArray[length + startIndex] == ch2))
             {
                 break;
//.........这里部分代码省略.........
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:101,代码来源:Uri.cs


示例20: GetRelativeSerializationString

        private unsafe string GetRelativeSerializationString(UriFormat format)
        {
            if (format == UriFormat.UriEscaped)
            {
                if (m_String.Length == 0)
                    return string.Empty;
                int position = 0;
                char[] dest = UriHelper.EscapeString(m_String, 0, m_String.Length, null, ref position, true, 
                    c_DummyChar, c_DummyChar, '%');
                if ((object)dest == null)
                    return m_String;
                return new string(dest, 0, position);
            }

            else if (format == UriFormat.Unescaped)
                return UnescapeDataString(m_String);

            else if (format == UriFormat.SafeUnescaped)
            {
                if (m_String.Length == 0)
                    return string.Empty;

                char[] dest = new char[m_String.Length];
                int position = 0;
                dest = UriHelper.UnescapeString(m_String, 0, m_String.Length, dest, ref position, c_DummyChar, 
                    c_DummyChar, c_DummyChar, UnescapeMode.EscapeUnescape, null, false);
                return new string(dest, 0, position);
            }
            else
                throw new ArgumentOutOfRangeException("format");

        }
开发者ID:nlh774,项目名称:DotNetReferenceSource,代码行数:32,代码来源:UriExt.cs



注:本文中的UriFormat类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# UriKind类代码示例发布时间:2022-05-24
下一篇:
C# UriComponents类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap