Browse Source

NetworkUtility:增加 Uri.Segmental 扩展方法。

master
王厅 6 days ago
parent
commit
9e7b30ef23
  1. 32
      Apewer/NetworkUtility.cs

32
Apewer/NetworkUtility.cs

@ -1,19 +1,16 @@
using Apewer.Network;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Globalization;
using System.Net;
using System.Net.NetworkInformation;
using System.Net.Sockets;
using System.Runtime.InteropServices;
using System.Text;
namespace Apewer
{
/// <summary></summary>
public class NetworkUtility
public static class NetworkUtility
{
#region UDP
@ -567,6 +564,33 @@ namespace Apewer
#endregion
#region URI
/// <summary>获取路径片段。</summary>
/// <param name="uri">URI</param>
/// <param name="index">Segmentals 的索引。索引 0 的位置为空(HOST 部分)。</param>
/// <param name="decode">解码 URL。</param>
public static string Segmental(this Uri uri, int index, bool decode = false)
{
if (uri == null) return null;
return Segmental(uri.Segments, index, decode);
}
/// <summary>获取路径片段。</summary>
/// <param name="segmentals">片段集合。</param>
/// <param name="index">Segmentals 的索引。索引 0 的位置为空(HOST 部分)。</param>
/// <param name="decode">解码 URL。</param>
internal static string Segmental(string[] segmentals, int index, bool decode = false)
{
if (segmentals == null || segmentals.Length < 1) return null;
if (index < 1 || index >= segmentals.Length) return null;
var segmental = segmentals[index];
if (decode) segmental = TextUtility.DecodeUrl(segmental);
return segmental;
}
#endregion
}
}

Loading…
Cancel
Save