mscorlib(4.0.0.0) API with additions
Uri.cs
1 using Microsoft.Win32;
2 using System.Collections;
6 using System.Net;
10 using System.Text;
11 using System.Threading;
12 
13 namespace System
14 {
16  [Serializable]
17  [TypeConverter(typeof(UriTypeConverter))]
18  [global::__DynamicallyInvokable]
19  public class Uri : ISerializable
20  {
21  [Flags]
22  private enum Flags : ulong
23  {
24  Zero = 0x0,
25  SchemeNotCanonical = 0x1,
26  UserNotCanonical = 0x2,
27  HostNotCanonical = 0x4,
28  PortNotCanonical = 0x8,
29  PathNotCanonical = 0x10,
30  QueryNotCanonical = 0x20,
31  FragmentNotCanonical = 0x40,
32  CannotDisplayCanonical = 0x7F,
33  E_UserNotCanonical = 0x80,
34  E_HostNotCanonical = 0x100,
35  E_PortNotCanonical = 0x200,
36  E_PathNotCanonical = 0x400,
37  E_QueryNotCanonical = 0x800,
38  E_FragmentNotCanonical = 0x1000,
39  E_CannotDisplayCanonical = 0x1F80,
40  ShouldBeCompressed = 0x2000,
41  FirstSlashAbsent = 0x4000,
42  BackslashInPath = 0x8000,
43  IndexMask = 0xFFFF,
44  HostTypeMask = 0x70000,
45  HostNotParsed = 0x0,
46  IPv6HostType = 0x10000,
47  IPv4HostType = 0x20000,
48  DnsHostType = 0x30000,
49  UncHostType = 0x40000,
50  BasicHostType = 0x50000,
51  UnusedHostType = 0x60000,
52  UnknownHostType = 0x70000,
53  UserEscaped = 0x80000,
54  AuthorityFound = 0x100000,
55  HasUserInfo = 0x200000,
56  LoopbackHost = 0x400000,
57  NotDefaultPort = 0x800000,
58  UserDrivenParsing = 0x1000000,
59  CanonicalDnsHost = 0x2000000,
60  ErrorOrParsingRecursion = 0x4000000,
61  DosPath = 0x8000000,
62  UncPath = 0x10000000,
63  ImplicitFile = 0x20000000,
64  MinimalUriInfoSet = 0x40000000,
65  AllUriInfoSet = 0x80000000,
66  IdnHost = 0x100000000,
67  HasUnicode = 0x200000000,
68  HostUnicodeNormalized = 0x400000000,
69  RestUnicodeNormalized = 0x800000000,
70  UnicodeHost = 0x1000000000,
71  IntranetUri = 0x2000000000,
72  UseOrigUncdStrOffset = 0x4000000000,
73  UserIriCanonical = 0x8000000000,
74  PathIriCanonical = 0x10000000000,
75  QueryIriCanonical = 0x20000000000,
76  FragmentIriCanonical = 0x40000000000,
77  IriCanonical = 0x78000000000
78  }
79 
80  private class UriInfo
81  {
82  public string Host;
83 
84  public string ScopeId;
85 
86  public string String;
87 
88  public Offset Offset;
89 
90  public string DnsSafeHost;
91 
92  public MoreInfo MoreInfo;
93  }
94 
95  [StructLayout(LayoutKind.Sequential, Pack = 1)]
96  private struct Offset
97  {
98  public ushort Scheme;
99 
100  public ushort User;
101 
102  public ushort Host;
103 
104  public ushort PortValue;
105 
106  public ushort Path;
107 
108  public ushort Query;
109 
110  public ushort Fragment;
111 
112  public ushort End;
113  }
114 
115  private class MoreInfo
116  {
117  public string Path;
118 
119  public string Query;
120 
121  public string Fragment;
122 
123  public string AbsoluteUri;
124 
125  public int Hash;
126 
127  public string RemoteUrl;
128  }
129 
130  [Flags]
131  private enum Check
132  {
133  None = 0x0,
134  EscapedCanonical = 0x1,
135  DisplayCanonical = 0x2,
136  DotSlashAttn = 0x4,
137  DotSlashEscaped = 0x80,
138  BackslashInPath = 0x10,
139  ReservedFound = 0x20,
140  NotIriCanonical = 0x40,
141  FoundNonAscii = 0x8
142  }
143 
145  public static readonly string UriSchemeFile = UriParser.FileUri.SchemeName;
146 
148  public static readonly string UriSchemeFtp = UriParser.FtpUri.SchemeName;
149 
151  public static readonly string UriSchemeGopher = UriParser.GopherUri.SchemeName;
152 
154  public static readonly string UriSchemeHttp = UriParser.HttpUri.SchemeName;
155 
157  public static readonly string UriSchemeHttps = UriParser.HttpsUri.SchemeName;
158 
159  internal static readonly string UriSchemeWs = UriParser.WsUri.SchemeName;
160 
161  internal static readonly string UriSchemeWss = UriParser.WssUri.SchemeName;
162 
164  public static readonly string UriSchemeMailto = UriParser.MailToUri.SchemeName;
165 
167  public static readonly string UriSchemeNews = UriParser.NewsUri.SchemeName;
168 
170  public static readonly string UriSchemeNntp = UriParser.NntpUri.SchemeName;
171 
173  public static readonly string UriSchemeNetTcp = UriParser.NetTcpUri.SchemeName;
174 
176  public static readonly string UriSchemeNetPipe = UriParser.NetPipeUri.SchemeName;
177 
179  public static readonly string SchemeDelimiter = "://";
180 
181  private const int c_Max16BitUtf8SequenceLength = 12;
182 
183  internal const int c_MaxUriBufferSize = 65520;
184 
185  private const int c_MaxUriSchemeName = 1024;
186 
187  private string m_String;
188 
189  private string m_originalUnicodeString;
190 
191  private UriParser m_Syntax;
192 
193  private string m_DnsSafeHost;
194 
195  private Flags m_Flags;
196 
197  private UriInfo m_Info;
198 
199  private bool m_iriParsing;
200 
201  private static volatile IInternetSecurityManager s_ManagerRef = null;
202 
203  private static object s_IntranetLock = new object();
204 
205  private static volatile bool s_ConfigInitialized;
206 
207  private static volatile bool s_ConfigInitializing;
208 
209  private static volatile UriIdnScope s_IdnScope = UriIdnScope.None;
210 
211  private static volatile bool s_IriParsing = (!UriParser.ShouldUseLegacyV2Quirks) ? true : false;
212 
213  private static object s_initLock;
214 
215  private const UriFormat V1ToStringUnescape = (UriFormat)32767;
216 
217  internal const char c_DummyChar = '\uffff';
218 
219  internal const char c_EOL = '\ufffe';
220 
221  internal static readonly char[] HexLowerChars = new char[16]
222  {
223  '0',
224  '1',
225  '2',
226  '3',
227  '4',
228  '5',
229  '6',
230  '7',
231  '8',
232  '9',
233  'a',
234  'b',
235  'c',
236  'd',
237  'e',
238  'f'
239  };
240 
241  private static readonly char[] _WSchars = new char[4]
242  {
243  ' ',
244  '\n',
245  '\r',
246  '\t'
247  };
248 
249  private bool IsImplicitFile => (m_Flags & Flags.ImplicitFile) != Flags.Zero;
250 
251  private bool IsUncOrDosPath => (m_Flags & (Flags.DosPath | Flags.UncPath)) != Flags.Zero;
252 
253  private bool IsDosPath => (m_Flags & Flags.DosPath) != Flags.Zero;
254 
255  private bool IsUncPath => (m_Flags & Flags.UncPath) != Flags.Zero;
256 
257  private Flags HostType => m_Flags & Flags.HostTypeMask;
258 
259  private UriParser Syntax => m_Syntax;
260 
261  private bool IsNotAbsoluteUri => m_Syntax == null;
262 
263  private bool AllowIdn
264  {
265  get
266  {
267  if (m_Syntax != null && (m_Syntax.Flags & UriSyntaxFlags.AllowIdn) != 0)
268  {
269  if (s_IdnScope != UriIdnScope.All)
270  {
271  if (s_IdnScope == UriIdnScope.AllExceptIntranet)
272  {
273  return NotAny(Flags.IntranetUri);
274  }
275  return false;
276  }
277  return true;
278  }
279  return false;
280  }
281  }
282 
283  internal bool UserDrivenParsing => (m_Flags & Flags.UserDrivenParsing) != Flags.Zero;
284 
285  private ushort SecuredPathIndex
286  {
287  get
288  {
289  if (IsDosPath)
290  {
291  char c = m_String[m_Info.Offset.Path];
292  return (ushort)((c == '/' || c == '\\') ? 3 : 2);
293  }
294  return 0;
295  }
296  }
297 
301  [global::__DynamicallyInvokable]
302  public string AbsolutePath
303  {
304  [global::__DynamicallyInvokable]
305  get
306  {
307  if (IsNotAbsoluteUri)
308  {
309  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
310  }
311  string text = PrivateAbsolutePath;
312  if (IsDosPath && text[0] == '/')
313  {
314  text = text.Substring(1);
315  }
316  return text;
317  }
318  }
319 
320  private string PrivateAbsolutePath
321  {
322  get
323  {
324  UriInfo uriInfo = EnsureUriInfo();
325  if (uriInfo.MoreInfo == null)
326  {
327  uriInfo.MoreInfo = new MoreInfo();
328  }
329  string text = uriInfo.MoreInfo.Path;
330  if (text == null)
331  {
332  text = GetParts(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.UriEscaped);
333  uriInfo.MoreInfo.Path = text;
334  }
335  return text;
336  }
337  }
338 
342  [global::__DynamicallyInvokable]
343  public string AbsoluteUri
344  {
345  [global::__DynamicallyInvokable]
346  get
347  {
348  if (m_Syntax == null)
349  {
350  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
351  }
352  UriInfo uriInfo = EnsureUriInfo();
353  if (uriInfo.MoreInfo == null)
354  {
355  uriInfo.MoreInfo = new MoreInfo();
356  }
357  string text = uriInfo.MoreInfo.AbsoluteUri;
358  if (text == null)
359  {
360  text = GetParts(UriComponents.AbsoluteUri, UriFormat.UriEscaped);
361  uriInfo.MoreInfo.AbsoluteUri = text;
362  }
363  return text;
364  }
365  }
366 
370  [global::__DynamicallyInvokable]
371  public string LocalPath
372  {
373  [global::__DynamicallyInvokable]
374  get
375  {
376  if (IsNotAbsoluteUri)
377  {
378  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
379  }
380  return GetLocalPath();
381  }
382  }
383 
387  [global::__DynamicallyInvokable]
388  public string Authority
389  {
390  [global::__DynamicallyInvokable]
391  get
392  {
393  if (IsNotAbsoluteUri)
394  {
395  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
396  }
397  return GetParts(UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped);
398  }
399  }
400 
404  [global::__DynamicallyInvokable]
405  public UriHostNameType HostNameType
406  {
407  [global::__DynamicallyInvokable]
408  get
409  {
410  if (IsNotAbsoluteUri)
411  {
412  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
413  }
414  if (m_Syntax.IsSimple)
415  {
416  EnsureUriInfo();
417  }
418  else
419  {
420  EnsureHostString(allowDnsOptimization: false);
421  }
422  switch (HostType)
423  {
424  case Flags.DnsHostType:
425  return UriHostNameType.Dns;
426  case Flags.IPv4HostType:
427  return UriHostNameType.IPv4;
428  case Flags.IPv6HostType:
429  return UriHostNameType.IPv6;
430  case Flags.BasicHostType:
431  return UriHostNameType.Basic;
432  case Flags.UncHostType:
433  return UriHostNameType.Basic;
434  case Flags.HostTypeMask:
435  return UriHostNameType.Unknown;
436  default:
437  return UriHostNameType.Unknown;
438  }
439  }
440  }
441 
445  [global::__DynamicallyInvokable]
446  public bool IsDefaultPort
447  {
448  [global::__DynamicallyInvokable]
449  get
450  {
451  if (IsNotAbsoluteUri)
452  {
453  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
454  }
455  if (m_Syntax.IsSimple)
456  {
457  EnsureUriInfo();
458  }
459  else
460  {
461  EnsureHostString(allowDnsOptimization: false);
462  }
463  return NotAny(Flags.NotDefaultPort);
464  }
465  }
466 
470  [global::__DynamicallyInvokable]
471  public bool IsFile
472  {
473  [global::__DynamicallyInvokable]
474  get
475  {
476  if (IsNotAbsoluteUri)
477  {
478  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
479  }
480  return (object)m_Syntax.SchemeName == UriSchemeFile;
481  }
482  }
483 
487  [global::__DynamicallyInvokable]
488  public bool IsLoopback
489  {
490  [global::__DynamicallyInvokable]
491  get
492  {
493  if (IsNotAbsoluteUri)
494  {
495  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
496  }
497  EnsureHostString(allowDnsOptimization: false);
498  return InFact(Flags.LoopbackHost);
499  }
500  }
501 
505  [global::__DynamicallyInvokable]
506  public string PathAndQuery
507  {
508  [global::__DynamicallyInvokable]
509  get
510  {
511  if (IsNotAbsoluteUri)
512  {
513  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
514  }
515  string text = GetParts(UriComponents.PathAndQuery, UriFormat.UriEscaped);
516  if (IsDosPath && text[0] == '/')
517  {
518  text = text.Substring(1);
519  }
520  return text;
521  }
522  }
523 
527  [global::__DynamicallyInvokable]
528  public string[] Segments
529  {
530  [global::__DynamicallyInvokable]
531  get
532  {
533  if (IsNotAbsoluteUri)
534  {
535  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
536  }
537  string[] array = null;
538  if (array == null)
539  {
540  string privateAbsolutePath = PrivateAbsolutePath;
541  if (privateAbsolutePath.Length == 0)
542  {
543  array = new string[0];
544  }
545  else
546  {
547  ArrayList arrayList = new ArrayList();
548  int num2;
549  for (int num = 0; num < privateAbsolutePath.Length; num = num2 + 1)
550  {
551  num2 = privateAbsolutePath.IndexOf('/', num);
552  if (num2 == -1)
553  {
554  num2 = privateAbsolutePath.Length - 1;
555  }
556  arrayList.Add(privateAbsolutePath.Substring(num, num2 - num + 1));
557  }
558  array = (string[])arrayList.ToArray(typeof(string));
559  }
560  }
561  return array;
562  }
563  }
564 
568  [global::__DynamicallyInvokable]
569  public bool IsUnc
570  {
571  [global::__DynamicallyInvokable]
572  get
573  {
574  if (IsNotAbsoluteUri)
575  {
576  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
577  }
578  return IsUncPath;
579  }
580  }
581 
585  [global::__DynamicallyInvokable]
586  public string Host
587  {
588  [global::__DynamicallyInvokable]
589  get
590  {
591  if (IsNotAbsoluteUri)
592  {
593  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
594  }
595  return GetParts(UriComponents.Host, UriFormat.UriEscaped);
596  }
597  }
598 
599  private static object InitializeLock
600  {
601  get
602  {
603  if (s_initLock == null)
604  {
605  object value = new object();
606  Interlocked.CompareExchange(ref s_initLock, value, null);
607  }
608  return s_initLock;
609  }
610  }
611 
615  [global::__DynamicallyInvokable]
616  public int Port
617  {
618  [global::__DynamicallyInvokable]
619  get
620  {
621  if (IsNotAbsoluteUri)
622  {
623  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
624  }
625  if (m_Syntax.IsSimple)
626  {
627  EnsureUriInfo();
628  }
629  else
630  {
631  EnsureHostString(allowDnsOptimization: false);
632  }
633  if (InFact(Flags.NotDefaultPort))
634  {
635  return m_Info.Offset.PortValue;
636  }
637  return m_Syntax.DefaultPort;
638  }
639  }
640 
644  [global::__DynamicallyInvokable]
645  public string Query
646  {
647  [global::__DynamicallyInvokable]
648  get
649  {
650  if (IsNotAbsoluteUri)
651  {
652  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
653  }
654  UriInfo uriInfo = EnsureUriInfo();
655  if (uriInfo.MoreInfo == null)
656  {
657  uriInfo.MoreInfo = new MoreInfo();
658  }
659  string text = uriInfo.MoreInfo.Query;
660  if (text == null)
661  {
662  text = GetParts(UriComponents.Query | UriComponents.KeepDelimiter, UriFormat.UriEscaped);
663  uriInfo.MoreInfo.Query = text;
664  }
665  return text;
666  }
667  }
668 
672  [global::__DynamicallyInvokable]
673  public string Fragment
674  {
675  [global::__DynamicallyInvokable]
676  get
677  {
678  if (IsNotAbsoluteUri)
679  {
680  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
681  }
682  UriInfo uriInfo = EnsureUriInfo();
683  if (uriInfo.MoreInfo == null)
684  {
685  uriInfo.MoreInfo = new MoreInfo();
686  }
687  string text = uriInfo.MoreInfo.Fragment;
688  if (text == null)
689  {
690  text = GetParts(UriComponents.Fragment | UriComponents.KeepDelimiter, UriFormat.UriEscaped);
691  uriInfo.MoreInfo.Fragment = text;
692  }
693  return text;
694  }
695  }
696 
700  [global::__DynamicallyInvokable]
701  public string Scheme
702  {
703  [global::__DynamicallyInvokable]
704  get
705  {
706  if (IsNotAbsoluteUri)
707  {
708  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
709  }
710  return m_Syntax.SchemeName;
711  }
712  }
713 
714  private bool OriginalStringSwitched
715  {
716  get
717  {
718  if (!m_iriParsing || !InFact(Flags.HasUnicode))
719  {
720  if (AllowIdn)
721  {
722  if (!InFact(Flags.IdnHost))
723  {
724  return InFact(Flags.UnicodeHost);
725  }
726  return true;
727  }
728  return false;
729  }
730  return true;
731  }
732  }
733 
737  [global::__DynamicallyInvokable]
738  public string OriginalString
739  {
740  [global::__DynamicallyInvokable]
741  get
742  {
743  if (!OriginalStringSwitched)
744  {
745  return m_String;
746  }
747  return m_originalUnicodeString;
748  }
749  }
750 
754  [global::__DynamicallyInvokable]
755  public string DnsSafeHost
756  {
757  [global::__DynamicallyInvokable]
758  get
759  {
760  if (IsNotAbsoluteUri)
761  {
762  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
763  }
764  if (AllowIdn && ((m_Flags & Flags.IdnHost) != Flags.Zero || (m_Flags & Flags.UnicodeHost) != Flags.Zero))
765  {
766  EnsureUriInfo();
767  return m_Info.DnsSafeHost;
768  }
769  EnsureHostString(allowDnsOptimization: false);
770  if (!string.IsNullOrEmpty(m_Info.DnsSafeHost))
771  {
772  return m_Info.DnsSafeHost;
773  }
774  if (m_Info.Host.Length == 0)
775  {
776  return string.Empty;
777  }
778  string text = m_Info.Host;
779  if (HostType == Flags.IPv6HostType)
780  {
781  text = text.Substring(1, text.Length - 2);
782  if (m_Info.ScopeId != null)
783  {
784  text += m_Info.ScopeId;
785  }
786  }
787  else if (HostType == Flags.BasicHostType && InFact(Flags.HostNotCanonical | Flags.E_HostNotCanonical))
788  {
789  char[] array = new char[text.Length];
790  int destPosition = 0;
791  UriHelper.UnescapeString(text, 0, text.Length, array, ref destPosition, '\uffff', '\uffff', '\uffff', UnescapeMode.Unescape | UnescapeMode.UnescapeAll, m_Syntax, isQuery: false);
792  text = new string(array, 0, destPosition);
793  }
794  m_Info.DnsSafeHost = text;
795  return text;
796  }
797  }
798 
801  [global::__DynamicallyInvokable]
802  public string IdnHost
803  {
804  [global::__DynamicallyInvokable]
805  get
806  {
807  string text = DnsSafeHost;
808  if (HostType == Flags.DnsHostType)
809  {
810  text = DomainNameHelper.IdnEquivalent(text);
811  }
812  return text;
813  }
814  }
815 
818  [global::__DynamicallyInvokable]
819  public bool IsAbsoluteUri
820  {
821  [global::__DynamicallyInvokable]
822  get
823  {
824  return m_Syntax != null;
825  }
826  }
827 
830  [global::__DynamicallyInvokable]
831  public bool UserEscaped
832  {
833  [global::__DynamicallyInvokable]
834  get
835  {
836  return InFact(Flags.UserEscaped);
837  }
838  }
839 
843  [global::__DynamicallyInvokable]
844  public string UserInfo
845  {
846  [global::__DynamicallyInvokable]
847  get
848  {
849  if (IsNotAbsoluteUri)
850  {
851  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
852  }
853  return GetParts(UriComponents.UserInfo, UriFormat.UriEscaped);
854  }
855  }
856 
857  internal bool HasAuthority => InFact(Flags.AuthorityFound);
858 
859  internal static bool IriParsingStatic(UriParser syntax)
860  {
861  if (s_IriParsing)
862  {
863  if (syntax == null || !syntax.InFact(UriSyntaxFlags.AllowIriParsing))
864  {
865  return syntax == null;
866  }
867  return true;
868  }
869  return false;
870  }
871 
872  private bool AllowIdnStatic(UriParser syntax, Flags flags)
873  {
874  if (syntax != null && (syntax.Flags & UriSyntaxFlags.AllowIdn) != 0)
875  {
876  if (s_IdnScope != UriIdnScope.All)
877  {
878  if (s_IdnScope == UriIdnScope.AllExceptIntranet)
879  {
880  return StaticNotAny(flags, Flags.IntranetUri);
881  }
882  return false;
883  }
884  return true;
885  }
886  return false;
887  }
888 
889  private bool IsIntranet(string schemeHost)
890  {
891  bool flag = false;
892  int pdwZone = -1;
893  int num = -2147467259;
894  if (m_Syntax.SchemeName.Length > 32)
895  {
896  return false;
897  }
898  if (s_ManagerRef == null)
899  {
900  lock (s_IntranetLock)
901  {
902  if (s_ManagerRef == null)
903  {
904  Guid clsid = typeof(InternetSecurityManager).GUID;
905  Guid iid = typeof(IInternetSecurityManager).GUID;
906  UnsafeNclNativeMethods.CoCreateInstance(ref clsid, IntPtr.Zero, 21, ref iid, out object o);
907  s_ManagerRef = (o as IInternetSecurityManager);
908  }
909  }
910  }
911  try
912  {
913  s_ManagerRef.MapUrlToZone(schemeHost.TrimStart(_WSchars), out pdwZone, 0);
914  }
915  catch (COMException ex)
916  {
917  if (ex.ErrorCode == num)
918  {
919  flag = true;
920  }
921  }
923  {
924  flag = true;
925  }
926  int num2;
927  switch (pdwZone)
928  {
929  case 1:
930  return true;
931  default:
932  num2 = ((pdwZone == 4) ? 1 : 0);
933  break;
934  case 2:
935  num2 = 1;
936  break;
937  }
938  if ((num2 | (flag ? 1 : 0)) != 0)
939  {
940  for (int i = 0; i < schemeHost.Length; i++)
941  {
942  if (schemeHost[i] == '.')
943  {
944  return false;
945  }
946  }
947  return true;
948  }
949  return false;
950  }
951 
952  private void SetUserDrivenParsing()
953  {
954  m_Flags = (Flags.UserDrivenParsing | (m_Flags & Flags.UserEscaped));
955  }
956 
957  private bool NotAny(Flags flags)
958  {
959  return (m_Flags & flags) == Flags.Zero;
960  }
961 
962  private bool InFact(Flags flags)
963  {
964  return (m_Flags & flags) != Flags.Zero;
965  }
966 
967  private static bool StaticNotAny(Flags allFlags, Flags checkFlags)
968  {
969  return (allFlags & checkFlags) == Flags.Zero;
970  }
971 
972  private static bool StaticInFact(Flags allFlags, Flags checkFlags)
973  {
974  return (allFlags & checkFlags) != Flags.Zero;
975  }
976 
977  private UriInfo EnsureUriInfo()
978  {
979  Flags flags = m_Flags;
980  if ((m_Flags & Flags.MinimalUriInfoSet) == Flags.Zero)
981  {
982  CreateUriInfo(flags);
983  }
984  return m_Info;
985  }
986 
987  private void EnsureParseRemaining()
988  {
989  if ((m_Flags & Flags.AllUriInfoSet) == Flags.Zero)
990  {
991  ParseRemaining();
992  }
993  }
994 
995  private void EnsureHostString(bool allowDnsOptimization)
996  {
997  EnsureUriInfo();
998  if (m_Info.Host == null && (!allowDnsOptimization || !InFact(Flags.CanonicalDnsHost)))
999  {
1000  CreateHostString();
1001  }
1002  }
1003 
1012  [global::__DynamicallyInvokable]
1013  public Uri(string uriString)
1014  {
1015  if (uriString == null)
1016  {
1017  throw new ArgumentNullException("uriString");
1018  }
1019  CreateThis(uriString, dontEscape: false, UriKind.Absolute);
1020  }
1021 
1031  [Obsolete("The constructor has been deprecated. Please use new Uri(string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")]
1032  public Uri(string uriString, bool dontEscape)
1033  {
1034  if (uriString == null)
1035  {
1036  throw new ArgumentNullException("uriString");
1037  }
1038  CreateThis(uriString, dontEscape, UriKind.Absolute);
1039  }
1040 
1051  [Obsolete("The constructor has been deprecated. Please new Uri(Uri, string). The dontEscape parameter is deprecated and is always false. http://go.microsoft.com/fwlink/?linkid=14202")]
1052  public Uri(Uri baseUri, string relativeUri, bool dontEscape)
1053  {
1054  if ((object)baseUri == null)
1055  {
1056  throw new ArgumentNullException("baseUri");
1057  }
1058  if (!baseUri.IsAbsoluteUri)
1059  {
1060  throw new ArgumentOutOfRangeException("baseUri");
1061  }
1062  CreateUri(baseUri, relativeUri, dontEscape);
1063  }
1064 
1078  [global::__DynamicallyInvokable]
1079  public Uri(string uriString, UriKind uriKind)
1080  {
1081  if (uriString == null)
1082  {
1083  throw new ArgumentNullException("uriString");
1084  }
1085  CreateThis(uriString, dontEscape: false, uriKind);
1086  }
1087 
1097  [global::__DynamicallyInvokable]
1098  public Uri(Uri baseUri, string relativeUri)
1099  {
1100  if ((object)baseUri == null)
1101  {
1102  throw new ArgumentNullException("baseUri");
1103  }
1104  if (!baseUri.IsAbsoluteUri)
1105  {
1106  throw new ArgumentOutOfRangeException("baseUri");
1107  }
1108  CreateUri(baseUri, relativeUri, dontEscape: false);
1109  }
1110 
1111  private void CreateUri(Uri baseUri, string relativeUri, bool dontEscape)
1112  {
1113  CreateThis(relativeUri, dontEscape, UriKind.RelativeOrAbsolute);
1115  if (baseUri.Syntax.IsSimple)
1116  {
1117  Uri uri = ResolveHelper(baseUri, this, ref relativeUri, ref dontEscape, out e);
1118  if (e != null)
1119  {
1120  throw e;
1121  }
1122  if (uri != null)
1123  {
1124  if ((object)uri != this)
1125  {
1126  CreateThisFromUri(uri);
1127  }
1128  return;
1129  }
1130  }
1131  else
1132  {
1133  dontEscape = false;
1134  relativeUri = baseUri.Syntax.InternalResolve(baseUri, this, out e);
1135  if (e != null)
1136  {
1137  throw e;
1138  }
1139  }
1140  m_Flags = Flags.Zero;
1141  m_Info = null;
1142  m_Syntax = null;
1143  CreateThis(relativeUri, dontEscape, UriKind.Absolute);
1144  }
1145 
1157  [global::__DynamicallyInvokable]
1158  public Uri(Uri baseUri, Uri relativeUri)
1159  {
1160  if ((object)baseUri == null)
1161  {
1162  throw new ArgumentNullException("baseUri");
1163  }
1164  if (!baseUri.IsAbsoluteUri)
1165  {
1166  throw new ArgumentOutOfRangeException("baseUri");
1167  }
1168  CreateThisFromUri(relativeUri);
1169  string newUriString = null;
1170  bool userEscaped;
1172  if (baseUri.Syntax.IsSimple)
1173  {
1174  userEscaped = InFact(Flags.UserEscaped);
1175  relativeUri = ResolveHelper(baseUri, this, ref newUriString, ref userEscaped, out e);
1176  if (e != null)
1177  {
1178  throw e;
1179  }
1180  if (relativeUri != null)
1181  {
1182  if ((object)relativeUri != this)
1183  {
1184  CreateThisFromUri(relativeUri);
1185  }
1186  return;
1187  }
1188  }
1189  else
1190  {
1191  userEscaped = false;
1192  newUriString = baseUri.Syntax.InternalResolve(baseUri, this, out e);
1193  if (e != null)
1194  {
1195  throw e;
1196  }
1197  }
1198  m_Flags = Flags.Zero;
1199  m_Info = null;
1200  m_Syntax = null;
1201  CreateThis(newUriString, userEscaped, UriKind.Absolute);
1202  }
1203 
1204  private unsafe static ParsingError GetCombinedString(Uri baseUri, string relativeStr, bool dontEscape, ref string result)
1205  {
1206  for (int i = 0; i < relativeStr.Length && relativeStr[i] != '/' && relativeStr[i] != '\\' && relativeStr[i] != '?' && relativeStr[i] != '#'; i++)
1207  {
1208  if (relativeStr[i] == ':')
1209  {
1210  if (i >= 2)
1211  {
1212  string text = relativeStr.Substring(0, i);
1213  fixed (char* ptr = text)
1214  {
1215  UriParser syntax = null;
1216  if (CheckSchemeSyntax(ptr, (ushort)text.Length, ref syntax) == ParsingError.None)
1217  {
1218  if (baseUri.Syntax != syntax)
1219  {
1220  result = relativeStr;
1221  return ParsingError.None;
1222  }
1223  relativeStr = ((i + 1 >= relativeStr.Length) ? string.Empty : relativeStr.Substring(i + 1));
1224  }
1225  }
1226  }
1227  break;
1228  }
1229  }
1230  if (relativeStr.Length == 0)
1231  {
1232  result = baseUri.OriginalString;
1233  return ParsingError.None;
1234  }
1235  result = CombineUri(baseUri, relativeStr, dontEscape ? UriFormat.UriEscaped : UriFormat.SafeUnescaped);
1236  return ParsingError.None;
1237  }
1238 
1239  private static UriFormatException GetException(ParsingError err)
1240  {
1241  switch (err)
1242  {
1243  case ParsingError.None:
1244  return null;
1245  case ParsingError.BadFormat:
1246  return new UriFormatException(SR.GetString("net_uri_BadFormat"));
1247  case ParsingError.BadScheme:
1248  return new UriFormatException(SR.GetString("net_uri_BadScheme"));
1249  case ParsingError.BadAuthority:
1250  return new UriFormatException(SR.GetString("net_uri_BadAuthority"));
1251  case ParsingError.EmptyUriString:
1252  return new UriFormatException(SR.GetString("net_uri_EmptyUri"));
1253  case ParsingError.SchemeLimit:
1254  return new UriFormatException(SR.GetString("net_uri_SchemeLimit"));
1255  case ParsingError.SizeLimit:
1256  return new UriFormatException(SR.GetString("net_uri_SizeLimit"));
1257  case ParsingError.MustRootedPath:
1258  return new UriFormatException(SR.GetString("net_uri_MustRootedPath"));
1259  case ParsingError.BadHostName:
1260  return new UriFormatException(SR.GetString("net_uri_BadHostName"));
1261  case ParsingError.NonEmptyHost:
1262  return new UriFormatException(SR.GetString("net_uri_BadFormat"));
1263  case ParsingError.BadPort:
1264  return new UriFormatException(SR.GetString("net_uri_BadPort"));
1265  case ParsingError.BadAuthorityTerminator:
1266  return new UriFormatException(SR.GetString("net_uri_BadAuthorityTerminator"));
1267  case ParsingError.CannotCreateRelative:
1268  return new UriFormatException(SR.GetString("net_uri_CannotCreateRelative"));
1269  default:
1270  return new UriFormatException(SR.GetString("net_uri_BadFormat"));
1271  }
1272  }
1273 
1279  protected Uri(SerializationInfo serializationInfo, StreamingContext streamingContext)
1280  {
1281  string @string = serializationInfo.GetString("AbsoluteUri");
1282  if (@string.Length != 0)
1283  {
1284  CreateThis(@string, dontEscape: false, UriKind.Absolute);
1285  return;
1286  }
1287  @string = serializationInfo.GetString("RelativeUri");
1288  if (@string == null)
1289  {
1290  throw new ArgumentNullException("uriString");
1291  }
1292  CreateThis(@string, dontEscape: false, UriKind.Relative);
1293  }
1294 
1298  [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter = true)]
1299  void ISerializable.GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
1300  {
1301  GetObjectData(serializationInfo, streamingContext);
1302  }
1303 
1307  [SecurityPermission(SecurityAction.LinkDemand, SerializationFormatter = true)]
1308  protected void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
1309  {
1310  if (IsAbsoluteUri)
1311  {
1312  serializationInfo.AddValue("AbsoluteUri", GetParts(UriComponents.SerializationInfoString, UriFormat.UriEscaped));
1313  return;
1314  }
1315  serializationInfo.AddValue("AbsoluteUri", string.Empty);
1316  serializationInfo.AddValue("RelativeUri", GetParts(UriComponents.SerializationInfoString, UriFormat.UriEscaped));
1317  }
1318 
1319  private static bool StaticIsFile(UriParser syntax)
1320  {
1321  return syntax.InFact(UriSyntaxFlags.FileLikeUri);
1322  }
1323 
1324  private static void InitializeUriConfig()
1325  {
1326  if (!s_ConfigInitialized)
1327  {
1328  lock (InitializeLock)
1329  {
1330  if (!s_ConfigInitialized && !s_ConfigInitializing)
1331  {
1332  s_ConfigInitializing = true;
1333  UriSectionInternal section = UriSectionInternal.GetSection();
1334  if (section != null)
1335  {
1336  s_IdnScope = section.IdnScope;
1337  if (UriParser.ShouldUseLegacyV2Quirks)
1338  {
1339  s_IriParsing = section.IriParsing;
1340  }
1341  SetEscapedDotSlashSettings(section, "http");
1342  SetEscapedDotSlashSettings(section, "https");
1343  SetEscapedDotSlashSettings(section, UriSchemeWs);
1344  SetEscapedDotSlashSettings(section, UriSchemeWss);
1345  }
1346  s_ConfigInitialized = true;
1347  s_ConfigInitializing = false;
1348  }
1349  }
1350  }
1351  }
1352 
1353  private static void SetEscapedDotSlashSettings(UriSectionInternal uriSection, string scheme)
1354  {
1355  SchemeSettingInternal schemeSetting = uriSection.GetSchemeSetting(scheme);
1356  if (schemeSetting != null && schemeSetting.Options == GenericUriParserOptions.DontUnescapePathDotsAndSlashes)
1357  {
1358  UriParser syntax = UriParser.GetSyntax(scheme);
1359  syntax.SetUpdatableFlags(UriSyntaxFlags.None);
1360  }
1361  }
1362 
1363  private string GetLocalPath()
1364  {
1365  EnsureParseRemaining();
1366  if (IsUncOrDosPath)
1367  {
1368  EnsureHostString(allowDnsOptimization: false);
1369  int num;
1370  if (NotAny(Flags.HostNotCanonical | Flags.PathNotCanonical | Flags.ShouldBeCompressed))
1371  {
1372  num = (IsUncPath ? (m_Info.Offset.Host - 2) : m_Info.Offset.Path);
1373  string text = (IsImplicitFile && m_Info.Offset.Host == ((!IsDosPath) ? 2 : 0) && m_Info.Offset.Query == m_Info.Offset.End) ? m_String : ((IsDosPath && (m_String[num] == '/' || m_String[num] == '\\')) ? m_String.Substring(num + 1, m_Info.Offset.Query - num - 1) : m_String.Substring(num, m_Info.Offset.Query - num));
1374  if (IsDosPath && text[1] == '|')
1375  {
1376  text = text.Remove(1, 1);
1377  text = text.Insert(1, ":");
1378  }
1379  for (int i = 0; i < text.Length; i++)
1380  {
1381  if (text[i] == '/')
1382  {
1383  text = text.Replace('/', '\\');
1384  break;
1385  }
1386  }
1387  return text;
1388  }
1389  int destPosition = 0;
1390  num = m_Info.Offset.Path;
1391  string host = m_Info.Host;
1392  char[] array = new char[host.Length + 3 + m_Info.Offset.Fragment - m_Info.Offset.Path];
1393  if (IsUncPath)
1394  {
1395  array[0] = '\\';
1396  array[1] = '\\';
1397  destPosition = 2;
1398  UriHelper.UnescapeString(host, 0, host.Length, array, ref destPosition, '\uffff', '\uffff', '\uffff', UnescapeMode.CopyOnly, m_Syntax, isQuery: false);
1399  }
1400  else if (m_String[num] == '/' || m_String[num] == '\\')
1401  {
1402  num++;
1403  }
1404  ushort num2 = (ushort)destPosition;
1405  UnescapeMode unescapeMode = (InFact(Flags.PathNotCanonical) && !IsImplicitFile) ? (UnescapeMode.Unescape | UnescapeMode.UnescapeAll) : UnescapeMode.CopyOnly;
1406  UriHelper.UnescapeString(m_String, num, m_Info.Offset.Query, array, ref destPosition, '\uffff', '\uffff', '\uffff', unescapeMode, m_Syntax, isQuery: true);
1407  if (array[1] == '|')
1408  {
1409  array[1] = ':';
1410  }
1411  if (InFact(Flags.ShouldBeCompressed))
1412  {
1413  array = Compress(array, (ushort)(IsDosPath ? (num2 + 2) : num2), ref destPosition, m_Syntax);
1414  }
1415  for (ushort num3 = 0; num3 < (ushort)destPosition; num3 = (ushort)(num3 + 1))
1416  {
1417  if (array[num3] == '/')
1418  {
1419  array[num3] = '\\';
1420  }
1421  }
1422  return new string(array, 0, destPosition);
1423  }
1424  return GetUnescapedParts(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.Unescaped);
1425  }
1426 
1430  [global::__DynamicallyInvokable]
1431  public unsafe static UriHostNameType CheckHostName(string name)
1432  {
1433  if (name == null || name.Length == 0 || name.Length > 32767)
1434  {
1435  return UriHostNameType.Unknown;
1436  }
1437  int end = name.Length;
1438  fixed (char* name2 = name)
1439  {
1440  if (name[0] == '[' && name[name.Length - 1] == ']' && IPv6AddressHelper.IsValid(name2, 1, ref end) && end == name.Length)
1441  {
1442  return UriHostNameType.IPv6;
1443  }
1444  end = name.Length;
1445  if (IPv4AddressHelper.IsValid(name2, 0, ref end, allowIPv6: false, notImplicitFile: false, unknownScheme: false) && end == name.Length)
1446  {
1447  return UriHostNameType.IPv4;
1448  }
1449  end = name.Length;
1450  bool notCanonical = false;
1451  if (DomainNameHelper.IsValid(name2, 0, ref end, ref notCanonical, notImplicitFile: false) && end == name.Length)
1452  {
1453  return UriHostNameType.Dns;
1454  }
1455  end = name.Length;
1456  notCanonical = false;
1457  if (DomainNameHelper.IsValidByIri(name2, 0, ref end, ref notCanonical, notImplicitFile: false) && end == name.Length)
1458  {
1459  return UriHostNameType.Dns;
1460  }
1461  }
1462  end = name.Length + 2;
1463  name = "[" + name + "]";
1464  fixed (char* name3 = name)
1465  {
1466  if (IPv6AddressHelper.IsValid(name3, 1, ref end) && end == name.Length)
1467  {
1468  return UriHostNameType.IPv6;
1469  }
1470  }
1471  return UriHostNameType.Unknown;
1472  }
1473 
1479  public string GetLeftPart(UriPartial part)
1480  {
1481  if (IsNotAbsoluteUri)
1482  {
1483  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
1484  }
1485  EnsureUriInfo();
1486  switch (part)
1487  {
1488  case UriPartial.Scheme:
1489  return GetParts(UriComponents.Scheme | UriComponents.KeepDelimiter, UriFormat.UriEscaped);
1490  case UriPartial.Authority:
1491  if (NotAny(Flags.AuthorityFound) || IsDosPath)
1492  {
1493  return string.Empty;
1494  }
1495  return GetParts(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port, UriFormat.UriEscaped);
1496  case UriPartial.Path:
1497  return GetParts(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.UriEscaped);
1498  case UriPartial.Query:
1499  return GetParts(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port | UriComponents.Path | UriComponents.Query, UriFormat.UriEscaped);
1500  default:
1501  throw new ArgumentException("part");
1502  }
1503  }
1504 
1510  public static string HexEscape(char character)
1511  {
1512  if (character > 'ÿ')
1513  {
1514  throw new ArgumentOutOfRangeException("character");
1515  }
1516  char[] array = new char[3];
1517  int pos = 0;
1518  UriHelper.EscapeAsciiChar(character, array, ref pos);
1519  return new string(array);
1520  }
1521 
1528  public static char HexUnescape(string pattern, ref int index)
1529  {
1530  if (index < 0 || index >= pattern.Length)
1531  {
1532  throw new ArgumentOutOfRangeException("index");
1533  }
1534  if (pattern[index] == '%' && pattern.Length - index >= 3)
1535  {
1536  char c = UriHelper.EscapedAscii(pattern[index + 1], pattern[index + 2]);
1537  if (c != '\uffff')
1538  {
1539  index += 3;
1540  return c;
1541  }
1542  }
1543  return pattern[index++];
1544  }
1545 
1550  public static bool IsHexEncoding(string pattern, int index)
1551  {
1552  if (pattern.Length - index < 3)
1553  {
1554  return false;
1555  }
1556  if (pattern[index] == '%' && UriHelper.EscapedAscii(pattern[index + 1], pattern[index + 2]) != '\uffff')
1557  {
1558  return true;
1559  }
1560  return false;
1561  }
1562 
1563  internal static bool IsGenDelim(char ch)
1564  {
1565  if (ch != ':' && ch != '/' && ch != '?' && ch != '#' && ch != '[' && ch != ']')
1566  {
1567  return ch == '@';
1568  }
1569  return true;
1570  }
1571 
1575  [global::__DynamicallyInvokable]
1576  public static bool CheckSchemeName(string schemeName)
1577  {
1578  if (schemeName == null || schemeName.Length == 0 || !IsAsciiLetter(schemeName[0]))
1579  {
1580  return false;
1581  }
1582  for (int num = schemeName.Length - 1; num > 0; num--)
1583  {
1584  if (!IsAsciiLetterOrDigit(schemeName[num]) && schemeName[num] != '+' && schemeName[num] != '-' && schemeName[num] != '.')
1585  {
1586  return false;
1587  }
1588  }
1589  return true;
1590  }
1591 
1595  public static bool IsHexDigit(char character)
1596  {
1597  if ((character < '0' || character > '9') && (character < 'A' || character > 'F'))
1598  {
1599  if (character >= 'a')
1600  {
1601  return character <= 'f';
1602  }
1603  return false;
1604  }
1605  return true;
1606  }
1607 
1613  public static int FromHex(char digit)
1614  {
1615  if ((digit >= '0' && digit <= '9') || (digit >= 'A' && digit <= 'F') || (digit >= 'a' && digit <= 'f'))
1616  {
1617  if (digit > '9')
1618  {
1619  return ((digit <= 'F') ? (digit - 65) : (digit - 97)) + 10;
1620  }
1621  return digit - 48;
1622  }
1623  throw new ArgumentException("digit");
1624  }
1625 
1628  [global::__DynamicallyInvokable]
1629  [SecurityPermission(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
1630  public override int GetHashCode()
1631  {
1632  if (IsNotAbsoluteUri)
1633  {
1634  return CalculateCaseInsensitiveHashCode(OriginalString);
1635  }
1636  UriInfo uriInfo = EnsureUriInfo();
1637  if (uriInfo.MoreInfo == null)
1638  {
1639  uriInfo.MoreInfo = new MoreInfo();
1640  }
1641  int num = uriInfo.MoreInfo.Hash;
1642  if (num == 0)
1643  {
1644  string text = uriInfo.MoreInfo.RemoteUrl;
1645  if (text == null)
1646  {
1647  text = GetParts(UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped);
1648  }
1649  num = CalculateCaseInsensitiveHashCode(text);
1650  if (num == 0)
1651  {
1652  num = 16777216;
1653  }
1654  uriInfo.MoreInfo.Hash = num;
1655  }
1656  return num;
1657  }
1658 
1661  [global::__DynamicallyInvokable]
1662  [SecurityPermission(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
1663  public override string ToString()
1664  {
1665  if (m_Syntax == null)
1666  {
1667  if (!m_iriParsing || !InFact(Flags.HasUnicode))
1668  {
1669  return OriginalString;
1670  }
1671  return m_String;
1672  }
1673  EnsureUriInfo();
1674  if (m_Info.String == null)
1675  {
1676  if (Syntax.IsSimple)
1677  {
1678  m_Info.String = GetComponentsHelper(UriComponents.AbsoluteUri, (UriFormat)32767);
1679  }
1680  else
1681  {
1682  m_Info.String = GetParts(UriComponents.AbsoluteUri, UriFormat.SafeUnescaped);
1683  }
1684  }
1685  return m_Info.String;
1686  }
1687 
1692  [global::__DynamicallyInvokable]
1693  [SecurityPermission(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
1694  public static bool operator ==(Uri uri1, Uri uri2)
1695  {
1696  if ((object)uri1 == uri2)
1697  {
1698  return true;
1699  }
1700  if ((object)uri1 == null || (object)uri2 == null)
1701  {
1702  return false;
1703  }
1704  return uri2.Equals(uri1);
1705  }
1706 
1711  [global::__DynamicallyInvokable]
1712  [SecurityPermission(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
1713  public static bool operator !=(Uri uri1, Uri uri2)
1714  {
1715  if ((object)uri1 == uri2)
1716  {
1717  return false;
1718  }
1719  if ((object)uri1 == null || (object)uri2 == null)
1720  {
1721  return true;
1722  }
1723  return !uri2.Equals(uri1);
1724  }
1725 
1729  [global::__DynamicallyInvokable]
1730  [SecurityPermission(SecurityAction.InheritanceDemand, Flags = SecurityPermissionFlag.Infrastructure)]
1731  public unsafe override bool Equals(object comparand)
1732  {
1733  if (comparand == null)
1734  {
1735  return false;
1736  }
1737  if (this == comparand)
1738  {
1739  return true;
1740  }
1741  Uri result = comparand as Uri;
1742  if ((object)result == null)
1743  {
1744  string text = comparand as string;
1745  if (text == null)
1746  {
1747  return false;
1748  }
1749  if (!TryCreate(text, UriKind.RelativeOrAbsolute, out result))
1750  {
1751  return false;
1752  }
1753  }
1754  if ((object)m_String == result.m_String)
1755  {
1756  return true;
1757  }
1758  if (IsAbsoluteUri != result.IsAbsoluteUri)
1759  {
1760  return false;
1761  }
1762  if (IsNotAbsoluteUri)
1763  {
1764  return OriginalString.Equals(result.OriginalString);
1765  }
1766  if (NotAny(Flags.AllUriInfoSet) || result.NotAny(Flags.AllUriInfoSet))
1767  {
1768  if (!IsUncOrDosPath)
1769  {
1770  if (m_String.Length == result.m_String.Length)
1771  {
1772  fixed (char* ptr = m_String)
1773  {
1774  fixed (char* ptr2 = result.m_String)
1775  {
1776  int num = m_String.Length - 1;
1777  while (num >= 0 && ptr[num] == ptr2[num])
1778  {
1779  num--;
1780  }
1781  if (num == -1)
1782  {
1783  return true;
1784  }
1785  }
1786  }
1787  }
1788  }
1789  else if (string.Compare(m_String, result.m_String, StringComparison.OrdinalIgnoreCase) == 0)
1790  {
1791  return true;
1792  }
1793  }
1794  EnsureUriInfo();
1795  result.EnsureUriInfo();
1796  if (!UserDrivenParsing && !result.UserDrivenParsing && Syntax.IsSimple && result.Syntax.IsSimple)
1797  {
1798  if (InFact(Flags.CanonicalDnsHost) && result.InFact(Flags.CanonicalDnsHost))
1799  {
1800  ushort num2 = m_Info.Offset.Host;
1801  ushort num3 = m_Info.Offset.Path;
1802  ushort num4 = result.m_Info.Offset.Host;
1803  ushort path = result.m_Info.Offset.Path;
1804  string @string = result.m_String;
1805  if (num3 - num2 > path - num4)
1806  {
1807  num3 = (ushort)(num2 + path - num4);
1808  }
1809  while (num2 < num3)
1810  {
1811  if (m_String[num2] != @string[num4])
1812  {
1813  return false;
1814  }
1815  if (@string[num4] == ':')
1816  {
1817  break;
1818  }
1819  num2 = (ushort)(num2 + 1);
1820  num4 = (ushort)(num4 + 1);
1821  }
1822  if (num2 < m_Info.Offset.Path && m_String[num2] != ':')
1823  {
1824  return false;
1825  }
1826  if (num4 < path && @string[num4] != ':')
1827  {
1828  return false;
1829  }
1830  }
1831  else
1832  {
1833  EnsureHostString(allowDnsOptimization: false);
1834  result.EnsureHostString(allowDnsOptimization: false);
1835  if (!m_Info.Host.Equals(result.m_Info.Host))
1836  {
1837  return false;
1838  }
1839  }
1840  if (Port != result.Port)
1841  {
1842  return false;
1843  }
1844  }
1845  UriInfo info = m_Info;
1846  UriInfo info2 = result.m_Info;
1847  if (info.MoreInfo == null)
1848  {
1849  info.MoreInfo = new MoreInfo();
1850  }
1851  if (info2.MoreInfo == null)
1852  {
1853  info2.MoreInfo = new MoreInfo();
1854  }
1855  string text2 = info.MoreInfo.RemoteUrl;
1856  if (text2 == null)
1857  {
1858  text2 = GetParts(UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped);
1859  info.MoreInfo.RemoteUrl = text2;
1860  }
1861  string text3 = info2.MoreInfo.RemoteUrl;
1862  if (text3 == null)
1863  {
1864  text3 = result.GetParts(UriComponents.HttpRequestUrl, UriFormat.SafeUnescaped);
1865  info2.MoreInfo.RemoteUrl = text3;
1866  }
1867  if (!IsUncOrDosPath)
1868  {
1869  if (text2.Length != text3.Length)
1870  {
1871  return false;
1872  }
1873  fixed (char* ptr3 = text2)
1874  {
1875  fixed (char* ptr5 = text3)
1876  {
1877  char* ptr4 = ptr3 + text2.Length;
1878  char* ptr6 = ptr5 + text2.Length;
1879  while (ptr4 != ptr3)
1880  {
1881  if (*(--ptr4) != *(--ptr6))
1882  {
1883  return false;
1884  }
1885  }
1886  return true;
1887  }
1888  }
1889  }
1890  return string.Compare(info.MoreInfo.RemoteUrl, info2.MoreInfo.RemoteUrl, IsUncOrDosPath ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) == 0;
1891  }
1892 
1899  [global::__DynamicallyInvokable]
1901  {
1902  if ((object)uri == null)
1903  {
1904  throw new ArgumentNullException("uri");
1905  }
1906  if (IsNotAbsoluteUri || uri.IsNotAbsoluteUri)
1907  {
1908  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
1909  }
1910  if (Scheme == uri.Scheme && Host == uri.Host && Port == uri.Port)
1911  {
1912  string absolutePath = uri.AbsolutePath;
1913  string text = PathDifference(AbsolutePath, absolutePath, !IsUncOrDosPath);
1914  if (CheckForColonInFirstPathSegment(text) && (!uri.IsDosPath || !absolutePath.Equals(text, StringComparison.Ordinal)))
1915  {
1916  text = "./" + text;
1917  }
1918  text += uri.GetParts(UriComponents.Query | UriComponents.Fragment, UriFormat.UriEscaped);
1919  return new Uri(text, UriKind.Relative);
1920  }
1921  return uri;
1922  }
1923 
1924  private static bool CheckForColonInFirstPathSegment(string uriString)
1925  {
1926  char[] anyOf = new char[5]
1927  {
1928  ':',
1929  '\\',
1930  '/',
1931  '?',
1932  '#'
1933  };
1934  int num = uriString.IndexOfAny(anyOf);
1935  if (num >= 0)
1936  {
1937  return uriString[num] == ':';
1938  }
1939  return false;
1940  }
1941 
1942  internal static string InternalEscapeString(string rawString)
1943  {
1944  if (rawString == null)
1945  {
1946  return string.Empty;
1947  }
1948  int destPos = 0;
1949  char[] array = UriHelper.EscapeString(rawString, 0, rawString.Length, null, ref destPos, isUriString: true, '?', '#', '%');
1950  if (array == null)
1951  {
1952  return rawString;
1953  }
1954  return new string(array, 0, destPos);
1955  }
1956 
1957  private unsafe static ParsingError ParseScheme(string uriString, ref Flags flags, ref UriParser syntax)
1958  {
1959  int length = uriString.Length;
1960  if (length == 0)
1961  {
1962  return ParsingError.EmptyUriString;
1963  }
1964  if (length >= 65520)
1965  {
1966  return ParsingError.SizeLimit;
1967  }
1968  fixed (char* uriString2 = uriString)
1969  {
1970  ParsingError err = ParsingError.None;
1971  ushort num = ParseSchemeCheckImplicitFile(uriString2, (ushort)length, ref err, ref flags, ref syntax);
1972  if (err != 0)
1973  {
1974  return err;
1975  }
1976  flags |= (Flags)num;
1977  }
1978  return ParsingError.None;
1979  }
1980 
1981  internal UriFormatException ParseMinimal()
1982  {
1983  ParsingError parsingError = PrivateParseMinimal();
1984  if (parsingError == ParsingError.None)
1985  {
1986  return null;
1987  }
1988  m_Flags |= Flags.ErrorOrParsingRecursion;
1989  return GetException(parsingError);
1990  }
1991 
1992  private unsafe ParsingError PrivateParseMinimal()
1993  {
1994  ushort num = (ushort)(m_Flags & Flags.IndexMask);
1995  ushort num2 = (ushort)m_String.Length;
1996  string newHost = null;
1997  m_Flags &= ~(Flags.SchemeNotCanonical | Flags.UserNotCanonical | Flags.HostNotCanonical | Flags.PortNotCanonical | Flags.PathNotCanonical | Flags.QueryNotCanonical | Flags.FragmentNotCanonical | Flags.E_UserNotCanonical | Flags.E_HostNotCanonical | Flags.E_PortNotCanonical | Flags.E_PathNotCanonical | Flags.E_QueryNotCanonical | Flags.E_FragmentNotCanonical | Flags.ShouldBeCompressed | Flags.FirstSlashAbsent | Flags.BackslashInPath | Flags.UserDrivenParsing);
1998  fixed (char* ptr = (m_iriParsing && (m_Flags & Flags.HasUnicode) != Flags.Zero && (m_Flags & Flags.HostUnicodeNormalized) == Flags.Zero) ? m_originalUnicodeString : m_String)
1999  {
2000  if (num2 > num && IsLWS(ptr[num2 - 1]))
2001  {
2002  num2 = (ushort)(num2 - 1);
2003  while (num2 != num && IsLWS(ptr[(int)(num2 = (ushort)(num2 - 1))]))
2004  {
2005  }
2006  num2 = (ushort)(num2 + 1);
2007  }
2008  if (m_Syntax.IsAllSet(UriSyntaxFlags.AllowEmptyHost | UriSyntaxFlags.AllowDOSPath) && NotAny(Flags.ImplicitFile) && num + 1 < num2)
2009  {
2010  ushort num3 = num;
2011  char c;
2012  while (num3 < num2 && ((c = ptr[(int)num3]) == '\\' || c == '/'))
2013  {
2014  num3 = (ushort)(num3 + 1);
2015  }
2016  if (m_Syntax.InFact(UriSyntaxFlags.FileLikeUri) || num3 - num <= 3)
2017  {
2018  if (num3 - num >= 2)
2019  {
2020  m_Flags |= Flags.AuthorityFound;
2021  }
2022  if (num3 + 1 < num2 && ((c = ptr[num3 + 1]) == ':' || c == '|') && IsAsciiLetter(ptr[(int)num3]))
2023  {
2024  if (num3 + 2 >= num2 || ((c = ptr[num3 + 2]) != '\\' && c != '/'))
2025  {
2026  if (m_Syntax.InFact(UriSyntaxFlags.FileLikeUri))
2027  {
2028  return ParsingError.MustRootedPath;
2029  }
2030  }
2031  else
2032  {
2033  m_Flags |= Flags.DosPath;
2034  if (m_Syntax.InFact(UriSyntaxFlags.MustHaveAuthority))
2035  {
2036  m_Flags |= Flags.AuthorityFound;
2037  }
2038  num = ((num3 == num || num3 - num == 2) ? num3 : ((ushort)(num3 - 1)));
2039  }
2040  }
2041  else if (m_Syntax.InFact(UriSyntaxFlags.FileLikeUri) && num3 - num >= 2 && num3 - num != 3 && num3 < num2 && ptr[(int)num3] != '?' && ptr[(int)num3] != '#')
2042  {
2043  m_Flags |= Flags.UncPath;
2044  num = num3;
2045  }
2046  }
2047  }
2048  if ((m_Flags & (Flags.DosPath | Flags.UncPath)) == Flags.Zero)
2049  {
2050  if (num + 2 <= num2)
2051  {
2052  char c2 = ptr[(int)num];
2053  char c3 = ptr[num + 1];
2054  if (m_Syntax.InFact(UriSyntaxFlags.MustHaveAuthority))
2055  {
2056  if ((c2 != '/' && c2 != '\\') || (c3 != '/' && c3 != '\\'))
2057  {
2058  return ParsingError.BadAuthority;
2059  }
2060  m_Flags |= Flags.AuthorityFound;
2061  num = (ushort)(num + 2);
2062  }
2063  else if (m_Syntax.InFact(UriSyntaxFlags.OptionalAuthority) && (InFact(Flags.AuthorityFound) || (c2 == '/' && c3 == '/')))
2064  {
2065  m_Flags |= Flags.AuthorityFound;
2066  num = (ushort)(num + 2);
2067  }
2068  else if (m_Syntax.NotAny(UriSyntaxFlags.MailToLikeUri))
2069  {
2070  m_Flags |= (Flags)((long)num | 458752L);
2071  return ParsingError.None;
2072  }
2073  }
2074  else
2075  {
2076  if (m_Syntax.InFact(UriSyntaxFlags.MustHaveAuthority))
2077  {
2078  return ParsingError.BadAuthority;
2079  }
2080  if (m_Syntax.NotAny(UriSyntaxFlags.MailToLikeUri))
2081  {
2082  m_Flags |= (Flags)((long)num | 458752L);
2083  return ParsingError.None;
2084  }
2085  }
2086  }
2087  if (InFact(Flags.DosPath))
2088  {
2089  m_Flags |= (Flags)(((m_Flags & Flags.AuthorityFound) != Flags.Zero) ? 327680 : 458752);
2090  m_Flags |= (Flags)num;
2091  return ParsingError.None;
2092  }
2093  ParsingError err = ParsingError.None;
2094  num = CheckAuthorityHelper(ptr, num, num2, ref err, ref m_Flags, m_Syntax, ref newHost);
2095  if (err != 0)
2096  {
2097  return err;
2098  }
2099  if (num < num2 && ptr[(int)num] == '\\' && NotAny(Flags.ImplicitFile) && m_Syntax.NotAny(UriSyntaxFlags.AllowDOSPath))
2100  {
2101  return ParsingError.BadAuthorityTerminator;
2102  }
2103  m_Flags |= (Flags)num;
2104  }
2105  if (s_IdnScope != 0 || m_iriParsing)
2106  {
2107  PrivateParseMinimalIri(newHost, num);
2108  }
2109  return ParsingError.None;
2110  }
2111 
2112  private void PrivateParseMinimalIri(string newHost, ushort idx)
2113  {
2114  if (newHost != null)
2115  {
2116  m_String = newHost;
2117  }
2118  if ((!m_iriParsing && AllowIdn && ((m_Flags & Flags.IdnHost) != Flags.Zero || (m_Flags & Flags.UnicodeHost) != Flags.Zero)) || (m_iriParsing && (m_Flags & Flags.HasUnicode) == Flags.Zero && AllowIdn && (m_Flags & Flags.IdnHost) != Flags.Zero))
2119  {
2120  m_Flags &= ~(Flags.SchemeNotCanonical | Flags.UserNotCanonical | Flags.HostNotCanonical | Flags.PortNotCanonical | Flags.PathNotCanonical | Flags.QueryNotCanonical | Flags.FragmentNotCanonical | Flags.E_UserNotCanonical | Flags.E_HostNotCanonical | Flags.E_PortNotCanonical | Flags.E_PathNotCanonical | Flags.E_QueryNotCanonical | Flags.E_FragmentNotCanonical | Flags.ShouldBeCompressed | Flags.FirstSlashAbsent | Flags.BackslashInPath);
2121  m_Flags |= (Flags)m_String.Length;
2122  m_String += m_originalUnicodeString.Substring(idx, m_originalUnicodeString.Length - idx);
2123  }
2124  if (m_iriParsing && (m_Flags & Flags.HasUnicode) != Flags.Zero)
2125  {
2126  m_Flags |= Flags.UseOrigUncdStrOffset;
2127  }
2128  }
2129 
2130  private unsafe void CreateUriInfo(Flags cF)
2131  {
2132  UriInfo uriInfo = new UriInfo();
2133  uriInfo.Offset.End = (ushort)m_String.Length;
2134  if (!UserDrivenParsing)
2135  {
2136  bool flag = false;
2137  ushort num;
2138  if ((cF & Flags.ImplicitFile) != Flags.Zero)
2139  {
2140  num = 0;
2141  while (IsLWS(m_String[num]))
2142  {
2143  num = (ushort)(num + 1);
2144  uriInfo.Offset.Scheme++;
2145  }
2146  if (StaticInFact(cF, Flags.UncPath))
2147  {
2148  num = (ushort)(num + 2);
2149  while (num < (ushort)(cF & Flags.IndexMask) && (m_String[num] == '/' || m_String[num] == '\\'))
2150  {
2151  num = (ushort)(num + 1);
2152  }
2153  }
2154  }
2155  else
2156  {
2157  num = (ushort)m_Syntax.SchemeName.Length;
2158  while (true)
2159  {
2160  string @string = m_String;
2161  ushort num2 = num;
2162  num = (ushort)(num2 + 1);
2163  if (@string[num2] == ':')
2164  {
2165  break;
2166  }
2167  uriInfo.Offset.Scheme++;
2168  }
2169  if ((cF & Flags.AuthorityFound) != Flags.Zero)
2170  {
2171  if (m_String[num] == '\\' || m_String[num + 1] == '\\')
2172  {
2173  flag = true;
2174  }
2175  num = (ushort)(num + 2);
2176  if ((cF & (Flags.DosPath | Flags.UncPath)) != Flags.Zero)
2177  {
2178  while (num < (ushort)(cF & Flags.IndexMask) && (m_String[num] == '/' || m_String[num] == '\\'))
2179  {
2180  flag = true;
2181  num = (ushort)(num + 1);
2182  }
2183  }
2184  }
2185  }
2186  if (m_Syntax.DefaultPort != -1)
2187  {
2188  uriInfo.Offset.PortValue = (ushort)m_Syntax.DefaultPort;
2189  }
2190  if ((cF & Flags.HostTypeMask) == Flags.HostTypeMask || StaticInFact(cF, Flags.DosPath))
2191  {
2192  uriInfo.Offset.User = (ushort)(cF & Flags.IndexMask);
2193  uriInfo.Offset.Host = uriInfo.Offset.User;
2194  uriInfo.Offset.Path = uriInfo.Offset.User;
2195  cF = (Flags)((long)cF & -65536L);
2196  if (flag)
2197  {
2198  cF |= Flags.SchemeNotCanonical;
2199  }
2200  }
2201  else
2202  {
2203  uriInfo.Offset.User = num;
2204  if (HostType == Flags.BasicHostType)
2205  {
2206  uriInfo.Offset.Host = num;
2207  uriInfo.Offset.Path = (ushort)(cF & Flags.IndexMask);
2208  cF = (Flags)((long)cF & -65536L);
2209  }
2210  else
2211  {
2212  if ((cF & Flags.HasUserInfo) != Flags.Zero)
2213  {
2214  while (m_String[num] != '@')
2215  {
2216  num = (ushort)(num + 1);
2217  }
2218  num = (ushort)(num + 1);
2219  uriInfo.Offset.Host = num;
2220  }
2221  else
2222  {
2223  uriInfo.Offset.Host = num;
2224  }
2225  num = (ushort)(cF & Flags.IndexMask);
2226  cF = (Flags)((long)cF & -65536L);
2227  if (flag)
2228  {
2229  cF |= Flags.SchemeNotCanonical;
2230  }
2231  uriInfo.Offset.Path = num;
2232  bool flag2 = false;
2233  bool flag3 = (cF & Flags.UseOrigUncdStrOffset) != Flags.Zero;
2234  cF = (Flags)((long)cF & -274877906945L);
2235  if (flag3)
2236  {
2237  uriInfo.Offset.End = (ushort)m_originalUnicodeString.Length;
2238  }
2239  if (num < uriInfo.Offset.End)
2240  {
2241  fixed (char* ptr = flag3 ? m_originalUnicodeString : m_String)
2242  {
2243  if (ptr[(int)num] == ':')
2244  {
2245  int num3 = 0;
2246  if ((num = (ushort)(num + 1)) < uriInfo.Offset.End)
2247  {
2248  num3 = (ushort)(ptr[(int)num] - 48);
2249  if (num3 != 65535 && num3 != 15 && num3 != 65523)
2250  {
2251  flag2 = true;
2252  if (num3 == 0)
2253  {
2254  cF |= (Flags.PortNotCanonical | Flags.E_PortNotCanonical);
2255  }
2256  for (num = (ushort)(num + 1); num < uriInfo.Offset.End; num = (ushort)(num + 1))
2257  {
2258  ushort num4 = (ushort)(ptr[(int)num] - 48);
2259  if (num4 == ushort.MaxValue || num4 == 15 || num4 == 65523)
2260  {
2261  break;
2262  }
2263  num3 = num3 * 10 + num4;
2264  }
2265  }
2266  }
2267  if (flag2 && uriInfo.Offset.PortValue != (ushort)num3)
2268  {
2269  uriInfo.Offset.PortValue = (ushort)num3;
2270  cF |= Flags.NotDefaultPort;
2271  }
2272  else
2273  {
2274  cF |= (Flags.PortNotCanonical | Flags.E_PortNotCanonical);
2275  }
2276  uriInfo.Offset.Path = num;
2277  }
2278  }
2279  }
2280  }
2281  }
2282  }
2283  cF |= Flags.MinimalUriInfoSet;
2284  uriInfo.DnsSafeHost = m_DnsSafeHost;
2285  lock (m_String)
2286  {
2287  if ((m_Flags & Flags.MinimalUriInfoSet) == Flags.Zero)
2288  {
2289  m_Info = uriInfo;
2290  m_Flags = (Flags)(((long)m_Flags & -65536L) | (long)cF);
2291  }
2292  }
2293  }
2294 
2295  private unsafe void CreateHostString()
2296  {
2297  if (!m_Syntax.IsSimple)
2298  {
2299  lock (m_Info)
2300  {
2301  if (NotAny(Flags.ErrorOrParsingRecursion))
2302  {
2303  m_Flags |= Flags.ErrorOrParsingRecursion;
2304  GetHostViaCustomSyntax();
2305  m_Flags &= ~Flags.ErrorOrParsingRecursion;
2306  return;
2307  }
2308  }
2309  }
2310  Flags flags = m_Flags;
2311  string text = CreateHostStringHelper(m_String, m_Info.Offset.Host, m_Info.Offset.Path, ref flags, ref m_Info.ScopeId);
2312  if (text.Length != 0)
2313  {
2314  if (HostType == Flags.BasicHostType)
2315  {
2316  ushort idx = 0;
2317  Check check;
2318  fixed (char* str = text)
2319  {
2320  check = CheckCanonical(str, ref idx, (ushort)text.Length, '\uffff');
2321  }
2322  if ((check & Check.DisplayCanonical) == Check.None && (NotAny(Flags.ImplicitFile) || (check & Check.ReservedFound) != 0))
2323  {
2324  flags |= Flags.HostNotCanonical;
2325  }
2326  if (InFact(Flags.ImplicitFile) && (check & (Check.EscapedCanonical | Check.ReservedFound)) != 0)
2327  {
2328  check &= ~Check.EscapedCanonical;
2329  }
2330  if ((check & (Check.EscapedCanonical | Check.BackslashInPath)) != Check.EscapedCanonical)
2331  {
2332  flags |= Flags.E_HostNotCanonical;
2333  if (NotAny(Flags.UserEscaped))
2334  {
2335  int destPos = 0;
2336  char[] array = UriHelper.EscapeString(text, 0, text.Length, null, ref destPos, isUriString: true, '?', '#', IsImplicitFile ? '\uffff' : '%');
2337  if (array != null)
2338  {
2339  text = new string(array, 0, destPos);
2340  }
2341  }
2342  }
2343  }
2344  else if (NotAny(Flags.CanonicalDnsHost))
2345  {
2346  if (m_Info.ScopeId != null)
2347  {
2348  flags |= (Flags.HostNotCanonical | Flags.E_HostNotCanonical);
2349  }
2350  else
2351  {
2352  for (ushort num = 0; num < text.Length; num = (ushort)(num + 1))
2353  {
2354  if (m_Info.Offset.Host + num >= m_Info.Offset.End || text[num] != m_String[m_Info.Offset.Host + num])
2355  {
2356  flags |= (Flags.HostNotCanonical | Flags.E_HostNotCanonical);
2357  break;
2358  }
2359  }
2360  }
2361  }
2362  }
2363  m_Info.Host = text;
2364  lock (m_Info)
2365  {
2366  m_Flags |= flags;
2367  }
2368  }
2369 
2370  private static string CreateHostStringHelper(string str, ushort idx, ushort end, ref Flags flags, ref string scopeId)
2371  {
2372  bool loopback = false;
2373  string text;
2374  switch (flags & Flags.HostTypeMask)
2375  {
2376  case Flags.DnsHostType:
2377  text = DomainNameHelper.ParseCanonicalName(str, idx, end, ref loopback);
2378  break;
2379  case Flags.IPv6HostType:
2380  text = IPv6AddressHelper.ParseCanonicalName(str, idx, ref loopback, ref scopeId);
2381  break;
2382  case Flags.IPv4HostType:
2383  text = IPv4AddressHelper.ParseCanonicalName(str, idx, end, ref loopback);
2384  break;
2385  case Flags.UncHostType:
2386  text = UncNameHelper.ParseCanonicalName(str, idx, end, ref loopback);
2387  break;
2388  case Flags.BasicHostType:
2389  text = ((!StaticInFact(flags, Flags.DosPath)) ? str.Substring(idx, end - idx) : string.Empty);
2390  if (text.Length == 0)
2391  {
2392  loopback = true;
2393  }
2394  break;
2395  case Flags.HostTypeMask:
2396  text = string.Empty;
2397  break;
2398  default:
2399  throw GetException(ParsingError.BadHostName);
2400  }
2401  if (loopback)
2402  {
2403  flags |= Flags.LoopbackHost;
2404  }
2405  return text;
2406  }
2407 
2408  private unsafe void GetHostViaCustomSyntax()
2409  {
2410  if (m_Info.Host != null)
2411  {
2412  return;
2413  }
2414  string text = m_Syntax.InternalGetComponents(this, UriComponents.Host, UriFormat.UriEscaped);
2415  if (m_Info.Host == null)
2416  {
2417  if (text.Length >= 65520)
2418  {
2419  throw GetException(ParsingError.SizeLimit);
2420  }
2421  ParsingError err = ParsingError.None;
2422  Flags flags = (Flags)((long)m_Flags & -458753L);
2423  fixed (char* pString = text)
2424  {
2425  string newHost = null;
2426  if (CheckAuthorityHelper(pString, 0, (ushort)text.Length, ref err, ref flags, m_Syntax, ref newHost) != (ushort)text.Length)
2427  {
2428  flags = (Flags)((long)flags & -458753L);
2429  flags |= Flags.HostTypeMask;
2430  }
2431  }
2432  if (err != 0 || (flags & Flags.HostTypeMask) == Flags.HostTypeMask)
2433  {
2434  m_Flags = (Flags)(((long)m_Flags & -458753L) | 0x50000);
2435  }
2436  else
2437  {
2438  text = CreateHostStringHelper(text, 0, (ushort)text.Length, ref flags, ref m_Info.ScopeId);
2439  for (ushort num = 0; num < text.Length; num = (ushort)(num + 1))
2440  {
2441  if (m_Info.Offset.Host + num >= m_Info.Offset.End || text[num] != m_String[m_Info.Offset.Host + num])
2442  {
2443  m_Flags |= (Flags.HostNotCanonical | Flags.E_HostNotCanonical);
2444  break;
2445  }
2446  }
2447  m_Flags = (Flags)(((long)m_Flags & -458753L) | (long)(flags & Flags.HostTypeMask));
2448  }
2449  }
2450  string text2 = m_Syntax.InternalGetComponents(this, UriComponents.StrongPort, UriFormat.UriEscaped);
2451  int num2 = 0;
2452  if (text2 == null || text2.Length == 0)
2453  {
2454  m_Flags &= ~Flags.NotDefaultPort;
2455  m_Flags |= (Flags.PortNotCanonical | Flags.E_PortNotCanonical);
2456  m_Info.Offset.PortValue = 0;
2457  }
2458  else
2459  {
2460  for (int i = 0; i < text2.Length; i++)
2461  {
2462  int num3 = text2[i] - 48;
2463  if (num3 < 0 || num3 > 9 || (num2 = num2 * 10 + num3) > 65535)
2464  {
2465  throw new UriFormatException(SR.GetString("net_uri_PortOutOfRange", m_Syntax.GetType().FullName, text2));
2466  }
2467  }
2468  if (num2 != m_Info.Offset.PortValue)
2469  {
2470  if (num2 == m_Syntax.DefaultPort)
2471  {
2472  m_Flags &= ~Flags.NotDefaultPort;
2473  }
2474  else
2475  {
2476  m_Flags |= Flags.NotDefaultPort;
2477  }
2478  m_Flags |= (Flags.PortNotCanonical | Flags.E_PortNotCanonical);
2479  m_Info.Offset.PortValue = (ushort)num2;
2480  }
2481  }
2482  m_Info.Host = text;
2483  }
2484 
2485  internal string GetParts(UriComponents uriParts, UriFormat formatAs)
2486  {
2487  return GetComponents(uriParts, formatAs);
2488  }
2489 
2490  private string GetEscapedParts(UriComponents uriParts)
2491  {
2492  ushort num = (ushort)(((ushort)m_Flags & 0x3F80) >> 6);
2493  if (InFact(Flags.SchemeNotCanonical))
2494  {
2495  num = (ushort)(num | 1);
2496  }
2497  if ((uriParts & UriComponents.Path) != 0)
2498  {
2499  if (InFact(Flags.ShouldBeCompressed | Flags.FirstSlashAbsent | Flags.BackslashInPath))
2500  {
2501  num = (ushort)(num | 0x10);
2502  }
2503  else if (IsDosPath && m_String[m_Info.Offset.Path + SecuredPathIndex - 1] == '|')
2504  {
2505  num = (ushort)(num | 0x10);
2506  }
2507  }
2508  if (((ushort)uriParts & num) == 0)
2509  {
2510  string uriPartsFromUserString = GetUriPartsFromUserString(uriParts);
2511  if (uriPartsFromUserString != null)
2512  {
2513  return uriPartsFromUserString;
2514  }
2515  }
2516  return ReCreateParts(uriParts, num, UriFormat.UriEscaped);
2517  }
2518 
2519  private string GetUnescapedParts(UriComponents uriParts, UriFormat formatAs)
2520  {
2521  ushort num = (ushort)((ushort)m_Flags & 0x7F);
2522  if ((uriParts & UriComponents.Path) != 0)
2523  {
2524  if ((m_Flags & (Flags.ShouldBeCompressed | Flags.FirstSlashAbsent | Flags.BackslashInPath)) != Flags.Zero)
2525  {
2526  num = (ushort)(num | 0x10);
2527  }
2528  else if (IsDosPath && m_String[m_Info.Offset.Path + SecuredPathIndex - 1] == '|')
2529  {
2530  num = (ushort)(num | 0x10);
2531  }
2532  }
2533  if (((ushort)uriParts & num) == 0)
2534  {
2535  string uriPartsFromUserString = GetUriPartsFromUserString(uriParts);
2536  if (uriPartsFromUserString != null)
2537  {
2538  return uriPartsFromUserString;
2539  }
2540  }
2541  return ReCreateParts(uriParts, num, formatAs);
2542  }
2543 
2544  private unsafe string ReCreateParts(UriComponents parts, ushort nonCanonical, UriFormat formatAs)
2545  {
2546  EnsureHostString(allowDnsOptimization: false);
2547  string text = ((parts & UriComponents.Host) == (UriComponents)0) ? string.Empty : m_Info.Host;
2548  int num = (m_Info.Offset.End - m_Info.Offset.User) * ((formatAs != UriFormat.UriEscaped) ? 1 : 12);
2549  char[] array = new char[text.Length + num + m_Syntax.SchemeName.Length + 3 + 1];
2550  num = 0;
2551  if ((parts & UriComponents.Scheme) != 0)
2552  {
2553  m_Syntax.SchemeName.CopyTo(0, array, num, m_Syntax.SchemeName.Length);
2554  num += m_Syntax.SchemeName.Length;
2555  if (parts != UriComponents.Scheme)
2556  {
2557  array[num++] = ':';
2558  if (InFact(Flags.AuthorityFound))
2559  {
2560  array[num++] = '/';
2561  array[num++] = '/';
2562  }
2563  }
2564  }
2565  if ((parts & UriComponents.UserInfo) != 0 && InFact(Flags.HasUserInfo))
2566  {
2567  if ((nonCanonical & 2) != 0)
2568  {
2569  switch (formatAs)
2570  {
2571  case UriFormat.UriEscaped:
2572  if (NotAny(Flags.UserEscaped))
2573  {
2574  array = UriHelper.EscapeString(m_String, m_Info.Offset.User, m_Info.Offset.Host, array, ref num, isUriString: true, '?', '#', '%');
2575  break;
2576  }
2577  InFact(Flags.E_UserNotCanonical);
2578  m_String.CopyTo(m_Info.Offset.User, array, num, m_Info.Offset.Host - m_Info.Offset.User);
2579  num += m_Info.Offset.Host - m_Info.Offset.User;
2580  break;
2581  case UriFormat.SafeUnescaped:
2582  array = UriHelper.UnescapeString(m_String, m_Info.Offset.User, m_Info.Offset.Host - 1, array, ref num, '@', '/', '\\', InFact(Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape, m_Syntax, isQuery: false);
2583  array[num++] = '@';
2584  break;
2585  case UriFormat.Unescaped:
2586  array = UriHelper.UnescapeString(m_String, m_Info.Offset.User, m_Info.Offset.Host, array, ref num, '\uffff', '\uffff', '\uffff', UnescapeMode.Unescape | UnescapeMode.UnescapeAll, m_Syntax, isQuery: false);
2587  break;
2588  default:
2589  array = UriHelper.UnescapeString(m_String, m_Info.Offset.User, m_Info.Offset.Host, array, ref num, '\uffff', '\uffff', '\uffff', UnescapeMode.CopyOnly, m_Syntax, isQuery: false);
2590  break;
2591  }
2592  }
2593  else
2594  {
2595  UriHelper.UnescapeString(m_String, m_Info.Offset.User, m_Info.Offset.Host, array, ref num, '\uffff', '\uffff', '\uffff', UnescapeMode.CopyOnly, m_Syntax, isQuery: false);
2596  }
2597  if (parts == UriComponents.UserInfo)
2598  {
2599  num--;
2600  }
2601  }
2602  if ((parts & UriComponents.Host) != 0 && text.Length != 0)
2603  {
2604  UnescapeMode unescapeMode = (formatAs != UriFormat.UriEscaped && HostType == Flags.BasicHostType && (nonCanonical & 4) != 0) ? ((formatAs == UriFormat.Unescaped) ? (UnescapeMode.Unescape | UnescapeMode.UnescapeAll) : (InFact(Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape)) : UnescapeMode.CopyOnly;
2605  if ((parts & UriComponents.NormalizedHost) != 0)
2606  {
2607  fixed (char* hostname = text)
2608  {
2609  bool allAscii = false;
2610  bool atLeastOneValidIdn = false;
2611  try
2612  {
2613  text = DomainNameHelper.UnicodeEquivalent(hostname, 0, text.Length, ref allAscii, ref atLeastOneValidIdn);
2614  }
2615  catch (UriFormatException)
2616  {
2617  }
2618  }
2619  }
2620  array = UriHelper.UnescapeString(text, 0, text.Length, array, ref num, '/', '?', '#', unescapeMode, m_Syntax, isQuery: false);
2621  if ((parts & UriComponents.SerializationInfoString) != 0 && HostType == Flags.IPv6HostType && m_Info.ScopeId != null)
2622  {
2623  m_Info.ScopeId.CopyTo(0, array, num - 1, m_Info.ScopeId.Length);
2624  num += m_Info.ScopeId.Length;
2625  array[num - 1] = ']';
2626  }
2627  }
2628  if ((parts & UriComponents.Port) != 0)
2629  {
2630  if ((nonCanonical & 8) == 0)
2631  {
2632  if (InFact(Flags.NotDefaultPort))
2633  {
2634  ushort num6 = m_Info.Offset.Path;
2635  while (m_String[num6 = (ushort)(num6 - 1)] != ':')
2636  {
2637  }
2638  m_String.CopyTo(num6, array, num, m_Info.Offset.Path - num6);
2639  num += m_Info.Offset.Path - num6;
2640  }
2641  else if ((parts & UriComponents.StrongPort) != 0 && m_Syntax.DefaultPort != -1)
2642  {
2643  array[num++] = ':';
2644  text = m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture);
2645  text.CopyTo(0, array, num, text.Length);
2646  num += text.Length;
2647  }
2648  }
2649  else if (InFact(Flags.NotDefaultPort) || ((parts & UriComponents.StrongPort) != 0 && m_Syntax.DefaultPort != -1))
2650  {
2651  array[num++] = ':';
2652  text = m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture);
2653  text.CopyTo(0, array, num, text.Length);
2654  num += text.Length;
2655  }
2656  }
2657  if ((parts & UriComponents.Path) != 0)
2658  {
2659  array = GetCanonicalPath(array, ref num, formatAs);
2660  if (parts == UriComponents.Path)
2661  {
2662  ushort startIndex;
2663  if (InFact(Flags.AuthorityFound) && num != 0 && array[0] == '/')
2664  {
2665  startIndex = 1;
2666  num--;
2667  }
2668  else
2669  {
2670  startIndex = 0;
2671  }
2672  if (num != 0)
2673  {
2674  return new string(array, startIndex, num);
2675  }
2676  return string.Empty;
2677  }
2678  }
2679  if ((parts & UriComponents.Query) != 0 && m_Info.Offset.Query < m_Info.Offset.Fragment)
2680  {
2681  ushort startIndex = (ushort)(m_Info.Offset.Query + 1);
2682  if (parts != UriComponents.Query)
2683  {
2684  array[num++] = '?';
2685  }
2686  if ((nonCanonical & 0x20) != 0)
2687  {
2688  switch (formatAs)
2689  {
2690  case UriFormat.UriEscaped:
2691  if (NotAny(Flags.UserEscaped))
2692  {
2693  array = UriHelper.EscapeString(m_String, startIndex, m_Info.Offset.Fragment, array, ref num, isUriString: true, '#', '\uffff', '%');
2694  }
2695  else
2696  {
2697  UriHelper.UnescapeString(m_String, startIndex, m_Info.Offset.Fragment, array, ref num, '\uffff', '\uffff', '\uffff', UnescapeMode.CopyOnly, m_Syntax, isQuery: true);
2698  }
2699  break;
2700  case (UriFormat)32767:
2701  array = UriHelper.UnescapeString(m_String, startIndex, m_Info.Offset.Fragment, array, ref num, '#', '\uffff', '\uffff', (UnescapeMode)((InFact(Flags.UserEscaped) ? 2 : 3) | 4), m_Syntax, isQuery: true);
2702  break;
2703  case UriFormat.Unescaped:
2704  array = UriHelper.UnescapeString(m_String, startIndex, m_Info.Offset.Fragment, array, ref num, '#', '\uffff', '\uffff', UnescapeMode.Unescape | UnescapeMode.UnescapeAll, m_Syntax, isQuery: true);
2705  break;
2706  default:
2707  array = UriHelper.UnescapeString(m_String, startIndex, m_Info.Offset.Fragment, array, ref num, '#', '\uffff', '\uffff', InFact(Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape, m_Syntax, isQuery: true);
2708  break;
2709  }
2710  }
2711  else
2712  {
2713  UriHelper.UnescapeString(m_String, startIndex, m_Info.Offset.Fragment, array, ref num, '\uffff', '\uffff', '\uffff', UnescapeMode.CopyOnly, m_Syntax, isQuery: true);
2714  }
2715  }
2716  if ((parts & UriComponents.Fragment) != 0 && m_Info.Offset.Fragment < m_Info.Offset.End)
2717  {
2718  ushort startIndex = (ushort)(m_Info.Offset.Fragment + 1);
2719  if (parts != UriComponents.Fragment)
2720  {
2721  array[num++] = '#';
2722  }
2723  if ((nonCanonical & 0x40) != 0)
2724  {
2725  switch (formatAs)
2726  {
2727  case UriFormat.UriEscaped:
2728  if (NotAny(Flags.UserEscaped))
2729  {
2730  array = UriHelper.EscapeString(m_String, startIndex, m_Info.Offset.End, array, ref num, isUriString: true, UriParser.ShouldUseLegacyV2Quirks ? '#' : '\uffff', '\uffff', '%');
2731  }
2732  else
2733  {
2734  UriHelper.UnescapeString(m_String, startIndex, m_Info.Offset.End, array, ref num, '\uffff', '\uffff', '\uffff', UnescapeMode.CopyOnly, m_Syntax, isQuery: false);
2735  }
2736  break;
2737  case (UriFormat)32767:
2738  array = UriHelper.UnescapeString(m_String, startIndex, m_Info.Offset.End, array, ref num, '#', '\uffff', '\uffff', (UnescapeMode)((InFact(Flags.UserEscaped) ? 2 : 3) | 4), m_Syntax, isQuery: false);
2739  break;
2740  case UriFormat.Unescaped:
2741  array = UriHelper.UnescapeString(m_String, startIndex, m_Info.Offset.End, array, ref num, '#', '\uffff', '\uffff', UnescapeMode.Unescape | UnescapeMode.UnescapeAll, m_Syntax, isQuery: false);
2742  break;
2743  default:
2744  array = UriHelper.UnescapeString(m_String, startIndex, m_Info.Offset.End, array, ref num, '#', '\uffff', '\uffff', InFact(Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape, m_Syntax, isQuery: false);
2745  break;
2746  }
2747  }
2748  else
2749  {
2750  UriHelper.UnescapeString(m_String, startIndex, m_Info.Offset.End, array, ref num, '\uffff', '\uffff', '\uffff', UnescapeMode.CopyOnly, m_Syntax, isQuery: false);
2751  }
2752  }
2753  return new string(array, 0, num);
2754  }
2755 
2756  private string GetUriPartsFromUserString(UriComponents uriParts)
2757  {
2758  switch (uriParts & ~UriComponents.KeepDelimiter)
2759  {
2760  case UriComponents.SchemeAndServer:
2761  if (!InFact(Flags.HasUserInfo))
2762  {
2763  return m_String.Substring(m_Info.Offset.Scheme, m_Info.Offset.Path - m_Info.Offset.Scheme);
2764  }
2765  return m_String.Substring(m_Info.Offset.Scheme, m_Info.Offset.User - m_Info.Offset.Scheme) + m_String.Substring(m_Info.Offset.Host, m_Info.Offset.Path - m_Info.Offset.Host);
2766  case UriComponents.HostAndPort:
2767  if (InFact(Flags.HasUserInfo))
2768  {
2769  if (InFact(Flags.NotDefaultPort) || m_Syntax.DefaultPort == -1)
2770  {
2771  return m_String.Substring(m_Info.Offset.Host, m_Info.Offset.Path - m_Info.Offset.Host);
2772  }
2773  return m_String.Substring(m_Info.Offset.Host, m_Info.Offset.Path - m_Info.Offset.Host) + ":" + m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture);
2774  }
2775  goto case UriComponents.StrongAuthority;
2776  case UriComponents.AbsoluteUri:
2777  if (m_Info.Offset.Scheme == 0 && m_Info.Offset.End == m_String.Length)
2778  {
2779  return m_String;
2780  }
2781  return m_String.Substring(m_Info.Offset.Scheme, m_Info.Offset.End - m_Info.Offset.Scheme);
2782  case UriComponents.HttpRequestUrl:
2783  if (InFact(Flags.HasUserInfo))
2784  {
2785  return m_String.Substring(m_Info.Offset.Scheme, m_Info.Offset.User - m_Info.Offset.Scheme) + m_String.Substring(m_Info.Offset.Host, m_Info.Offset.Fragment - m_Info.Offset.Host);
2786  }
2787  if (m_Info.Offset.Scheme == 0 && m_Info.Offset.Fragment == m_String.Length)
2788  {
2789  return m_String;
2790  }
2791  return m_String.Substring(m_Info.Offset.Scheme, m_Info.Offset.Fragment - m_Info.Offset.Scheme);
2792  case UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port:
2793  return m_String.Substring(m_Info.Offset.Scheme, m_Info.Offset.Path - m_Info.Offset.Scheme);
2794  case UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port | UriComponents.Path | UriComponents.Query:
2795  if (m_Info.Offset.Scheme == 0 && m_Info.Offset.Fragment == m_String.Length)
2796  {
2797  return m_String;
2798  }
2799  return m_String.Substring(m_Info.Offset.Scheme, m_Info.Offset.Fragment - m_Info.Offset.Scheme);
2800  case UriComponents.Scheme:
2801  if (uriParts != UriComponents.Scheme)
2802  {
2803  return m_String.Substring(m_Info.Offset.Scheme, m_Info.Offset.User - m_Info.Offset.Scheme);
2804  }
2805  return m_Syntax.SchemeName;
2806  case UriComponents.Host:
2807  {
2808  ushort num2 = m_Info.Offset.Path;
2809  if (InFact(Flags.PortNotCanonical | Flags.NotDefaultPort))
2810  {
2811  while (m_String[num2 = (ushort)(num2 - 1)] != ':')
2812  {
2813  }
2814  }
2815  if (num2 - m_Info.Offset.Host != 0)
2816  {
2817  return m_String.Substring(m_Info.Offset.Host, num2 - m_Info.Offset.Host);
2818  }
2819  return string.Empty;
2820  }
2821  case UriComponents.Path:
2822  {
2823  ushort num = (uriParts != UriComponents.Path || !InFact(Flags.AuthorityFound) || m_Info.Offset.End <= m_Info.Offset.Path || m_String[m_Info.Offset.Path] != '/') ? m_Info.Offset.Path : ((ushort)(m_Info.Offset.Path + 1));
2824  if (num >= m_Info.Offset.Query)
2825  {
2826  return string.Empty;
2827  }
2828  return m_String.Substring(num, m_Info.Offset.Query - num);
2829  }
2830  case UriComponents.Query:
2831  {
2832  ushort num = (uriParts != UriComponents.Query) ? m_Info.Offset.Query : ((ushort)(m_Info.Offset.Query + 1));
2833  if (num >= m_Info.Offset.Fragment)
2834  {
2835  return string.Empty;
2836  }
2837  return m_String.Substring(num, m_Info.Offset.Fragment - num);
2838  }
2839  case UriComponents.Fragment:
2840  {
2841  ushort num = (uriParts != UriComponents.Fragment) ? m_Info.Offset.Fragment : ((ushort)(m_Info.Offset.Fragment + 1));
2842  if (num >= m_Info.Offset.End)
2843  {
2844  return string.Empty;
2845  }
2846  return m_String.Substring(num, m_Info.Offset.End - num);
2847  }
2848  case UriComponents.UserInfo | UriComponents.Host | UriComponents.Port:
2849  if (m_Info.Offset.Path - m_Info.Offset.User != 0)
2850  {
2851  return m_String.Substring(m_Info.Offset.User, m_Info.Offset.Path - m_Info.Offset.User);
2852  }
2853  return string.Empty;
2854  case UriComponents.StrongAuthority:
2855  if (!InFact(Flags.NotDefaultPort) && m_Syntax.DefaultPort != -1)
2856  {
2857  return m_String.Substring(m_Info.Offset.User, m_Info.Offset.Path - m_Info.Offset.User) + ":" + m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture);
2858  }
2859  goto case UriComponents.UserInfo | UriComponents.Host | UriComponents.Port;
2860  case UriComponents.PathAndQuery:
2861  return m_String.Substring(m_Info.Offset.Path, m_Info.Offset.Fragment - m_Info.Offset.Path);
2862  case UriComponents.Scheme | UriComponents.Host | UriComponents.Port | UriComponents.Path | UriComponents.Query | UriComponents.Fragment:
2863  if (InFact(Flags.HasUserInfo))
2864  {
2865  return m_String.Substring(m_Info.Offset.Scheme, m_Info.Offset.User - m_Info.Offset.Scheme) + m_String.Substring(m_Info.Offset.Host, m_Info.Offset.End - m_Info.Offset.Host);
2866  }
2867  if (m_Info.Offset.Scheme == 0 && m_Info.Offset.End == m_String.Length)
2868  {
2869  return m_String;
2870  }
2871  return m_String.Substring(m_Info.Offset.Scheme, m_Info.Offset.End - m_Info.Offset.Scheme);
2872  case UriComponents.Path | UriComponents.Query | UriComponents.Fragment:
2873  return m_String.Substring(m_Info.Offset.Path, m_Info.Offset.End - m_Info.Offset.Path);
2874  case UriComponents.UserInfo:
2875  {
2876  if (NotAny(Flags.HasUserInfo))
2877  {
2878  return string.Empty;
2879  }
2880  ushort num = (uriParts != UriComponents.UserInfo) ? m_Info.Offset.Host : ((ushort)(m_Info.Offset.Host - 1));
2881  if (m_Info.Offset.User >= num)
2882  {
2883  return string.Empty;
2884  }
2885  return m_String.Substring(m_Info.Offset.User, num - m_Info.Offset.User);
2886  }
2887  default:
2888  return null;
2889  }
2890  }
2891 
2892  private unsafe void ParseRemaining()
2893  {
2894  EnsureUriInfo();
2895  Flags flags = Flags.Zero;
2896  if (!UserDrivenParsing)
2897  {
2898  bool flag = m_iriParsing && (m_Flags & Flags.HasUnicode) != Flags.Zero && (m_Flags & Flags.RestUnicodeNormalized) == Flags.Zero;
2899  ushort scheme = m_Info.Offset.Scheme;
2900  ushort num = (ushort)m_String.Length;
2901  Check check = Check.None;
2902  UriSyntaxFlags flags2 = m_Syntax.Flags;
2903  fixed (char* ptr = m_String)
2904  {
2905  if (num > scheme && IsLWS(ptr[num - 1]))
2906  {
2907  num = (ushort)(num - 1);
2908  while (num != scheme && IsLWS(ptr[(int)(num = (ushort)(num - 1))]))
2909  {
2910  }
2911  num = (ushort)(num + 1);
2912  }
2913  if (IsImplicitFile)
2914  {
2915  flags |= Flags.SchemeNotCanonical;
2916  }
2917  else
2918  {
2919  ushort num2 = 0;
2920  ushort num3 = (ushort)m_Syntax.SchemeName.Length;
2921  while (num2 < num3)
2922  {
2923  if (m_Syntax.SchemeName[num2] != ptr[scheme + num2])
2924  {
2925  flags |= Flags.SchemeNotCanonical;
2926  }
2927  num2 = (ushort)(num2 + 1);
2928  }
2929  if ((m_Flags & Flags.AuthorityFound) != Flags.Zero && (scheme + num2 + 3 >= num || ptr[scheme + num2 + 1] != '/' || ptr[scheme + num2 + 2] != '/'))
2930  {
2931  flags |= Flags.SchemeNotCanonical;
2932  }
2933  }
2934  if ((m_Flags & Flags.HasUserInfo) != Flags.Zero)
2935  {
2936  scheme = m_Info.Offset.User;
2937  check = CheckCanonical(ptr, ref scheme, m_Info.Offset.Host, '@');
2938  if ((check & Check.DisplayCanonical) == Check.None)
2939  {
2940  flags |= Flags.UserNotCanonical;
2941  }
2942  if ((check & (Check.EscapedCanonical | Check.BackslashInPath)) != Check.EscapedCanonical)
2943  {
2944  flags |= Flags.E_UserNotCanonical;
2945  }
2946  if (m_iriParsing && (check & (Check.EscapedCanonical | Check.DisplayCanonical | Check.BackslashInPath | Check.NotIriCanonical | Check.FoundNonAscii)) == (Check.DisplayCanonical | Check.FoundNonAscii))
2947  {
2948  flags |= Flags.UserIriCanonical;
2949  }
2950  }
2951  }
2952  scheme = m_Info.Offset.Path;
2953  ushort idx = m_Info.Offset.Path;
2954  if (flag)
2955  {
2956  if (IsDosPath)
2957  {
2958  if (IsImplicitFile)
2959  {
2960  m_String = string.Empty;
2961  }
2962  else
2963  {
2964  m_String = m_Syntax.SchemeName + SchemeDelimiter;
2965  }
2966  }
2967  m_Info.Offset.Path = (ushort)m_String.Length;
2968  scheme = m_Info.Offset.Path;
2969  ushort start = idx;
2970  if (IsImplicitFile || (flags2 & (UriSyntaxFlags.MayHaveQuery | UriSyntaxFlags.MayHaveFragment)) == UriSyntaxFlags.None)
2971  {
2972  FindEndOfComponent(m_originalUnicodeString, ref idx, (ushort)m_originalUnicodeString.Length, '\uffff');
2973  }
2974  else
2975  {
2976  FindEndOfComponent(m_originalUnicodeString, ref idx, (ushort)m_originalUnicodeString.Length, m_Syntax.InFact(UriSyntaxFlags.MayHaveQuery) ? '?' : (m_Syntax.InFact(UriSyntaxFlags.MayHaveFragment) ? '#' : '\ufffe'));
2977  }
2978  string text = EscapeUnescapeIri(m_originalUnicodeString, start, idx, UriComponents.Path);
2979  try
2980  {
2981  if (UriParser.ShouldUseLegacyV2Quirks)
2982  {
2983  m_String += text.Normalize(NormalizationForm.FormC);
2984  }
2985  else
2986  {
2987  m_String += text;
2988  }
2989  }
2990  catch (ArgumentException)
2991  {
2992  UriFormatException exception = GetException(ParsingError.BadFormat);
2993  throw exception;
2994  }
2995  num = (ushort)m_String.Length;
2996  }
2997  fixed (char* ptr2 = m_String)
2998  {
2999  check = ((!IsImplicitFile && (flags2 & (UriSyntaxFlags.MayHaveQuery | UriSyntaxFlags.MayHaveFragment)) != 0) ? CheckCanonical(ptr2, ref scheme, num, ((flags2 & UriSyntaxFlags.MayHaveQuery) != 0) ? '?' : (m_Syntax.InFact(UriSyntaxFlags.MayHaveFragment) ? '#' : '\ufffe')) : CheckCanonical(ptr2, ref scheme, num, '\uffff'));
3000  if ((m_Flags & Flags.AuthorityFound) != Flags.Zero && (flags2 & UriSyntaxFlags.PathIsRooted) != 0 && (m_Info.Offset.Path == num || (ptr2[(int)m_Info.Offset.Path] != '/' && ptr2[(int)m_Info.Offset.Path] != '\\')))
3001  {
3002  flags |= Flags.FirstSlashAbsent;
3003  }
3004  }
3005  bool flag2 = false;
3006  if (IsDosPath || ((m_Flags & Flags.AuthorityFound) != Flags.Zero && ((flags2 & (UriSyntaxFlags.ConvertPathSlashes | UriSyntaxFlags.CompressPath)) != 0 || m_Syntax.InFact(UriSyntaxFlags.UnEscapeDotsAndSlashes))))
3007  {
3008  if ((check & Check.DotSlashEscaped) != 0 && m_Syntax.InFact(UriSyntaxFlags.UnEscapeDotsAndSlashes))
3009  {
3010  flags |= (Flags.PathNotCanonical | Flags.E_PathNotCanonical);
3011  flag2 = true;
3012  }
3013  if ((flags2 & UriSyntaxFlags.ConvertPathSlashes) != 0 && (check & Check.BackslashInPath) != 0)
3014  {
3015  flags |= (Flags.PathNotCanonical | Flags.E_PathNotCanonical);
3016  flag2 = true;
3017  }
3018  if ((flags2 & UriSyntaxFlags.CompressPath) != 0 && ((flags & Flags.E_PathNotCanonical) != Flags.Zero || (check & Check.DotSlashAttn) != 0))
3019  {
3020  flags |= Flags.ShouldBeCompressed;
3021  }
3022  if ((check & Check.BackslashInPath) != 0)
3023  {
3024  flags |= Flags.BackslashInPath;
3025  }
3026  }
3027  else if ((check & Check.BackslashInPath) != 0)
3028  {
3029  flags |= Flags.E_PathNotCanonical;
3030  flag2 = true;
3031  }
3032  if ((check & Check.DisplayCanonical) == Check.None && ((m_Flags & Flags.ImplicitFile) == Flags.Zero || (m_Flags & Flags.UserEscaped) != Flags.Zero || (check & Check.ReservedFound) != 0))
3033  {
3034  flags |= Flags.PathNotCanonical;
3035  flag2 = true;
3036  }
3037  if ((m_Flags & Flags.ImplicitFile) != Flags.Zero && (check & (Check.EscapedCanonical | Check.ReservedFound)) != 0)
3038  {
3039  check &= ~Check.EscapedCanonical;
3040  }
3041  if ((check & Check.EscapedCanonical) == Check.None)
3042  {
3043  flags |= Flags.E_PathNotCanonical;
3044  }
3045  if (m_iriParsing && !flag2 && (check & (Check.EscapedCanonical | Check.DisplayCanonical | Check.NotIriCanonical | Check.FoundNonAscii)) == (Check.DisplayCanonical | Check.FoundNonAscii))
3046  {
3047  flags |= Flags.PathIriCanonical;
3048  }
3049  if (flag)
3050  {
3051  ushort start2 = idx;
3052  if (idx < m_originalUnicodeString.Length && m_originalUnicodeString[idx] == '?')
3053  {
3054  idx = (ushort)(idx + 1);
3055  FindEndOfComponent(m_originalUnicodeString, ref idx, (ushort)m_originalUnicodeString.Length, ((flags2 & UriSyntaxFlags.MayHaveFragment) != 0) ? '#' : '\ufffe');
3056  string text2 = EscapeUnescapeIri(m_originalUnicodeString, start2, idx, UriComponents.Query);
3057  try
3058  {
3059  if (UriParser.ShouldUseLegacyV2Quirks)
3060  {
3061  m_String += text2.Normalize(NormalizationForm.FormC);
3062  }
3063  else
3064  {
3065  m_String += text2;
3066  }
3067  }
3068  catch (ArgumentException)
3069  {
3070  UriFormatException exception2 = GetException(ParsingError.BadFormat);
3071  throw exception2;
3072  }
3073  num = (ushort)m_String.Length;
3074  }
3075  }
3076  m_Info.Offset.Query = scheme;
3077  fixed (char* ptr3 = m_String)
3078  {
3079  if (scheme < num && ptr3[(int)scheme] == '?')
3080  {
3081  scheme = (ushort)(scheme + 1);
3082  check = CheckCanonical(ptr3, ref scheme, num, ((flags2 & UriSyntaxFlags.MayHaveFragment) != 0) ? '#' : '\ufffe');
3083  if ((check & Check.DisplayCanonical) == Check.None)
3084  {
3085  flags |= Flags.QueryNotCanonical;
3086  }
3087  if ((check & (Check.EscapedCanonical | Check.BackslashInPath)) != Check.EscapedCanonical)
3088  {
3089  flags |= Flags.E_QueryNotCanonical;
3090  }
3091  if (m_iriParsing && (check & (Check.EscapedCanonical | Check.DisplayCanonical | Check.BackslashInPath | Check.NotIriCanonical | Check.FoundNonAscii)) == (Check.DisplayCanonical | Check.FoundNonAscii))
3092  {
3093  flags |= Flags.QueryIriCanonical;
3094  }
3095  }
3096  }
3097  if (flag)
3098  {
3099  ushort start3 = idx;
3100  if (idx < m_originalUnicodeString.Length && m_originalUnicodeString[idx] == '#')
3101  {
3102  idx = (ushort)(idx + 1);
3103  FindEndOfComponent(m_originalUnicodeString, ref idx, (ushort)m_originalUnicodeString.Length, '\ufffe');
3104  string text3 = EscapeUnescapeIri(m_originalUnicodeString, start3, idx, UriComponents.Fragment);
3105  try
3106  {
3107  if (UriParser.ShouldUseLegacyV2Quirks)
3108  {
3109  m_String += text3.Normalize(NormalizationForm.FormC);
3110  }
3111  else
3112  {
3113  m_String += text3;
3114  }
3115  }
3116  catch (ArgumentException)
3117  {
3118  UriFormatException exception3 = GetException(ParsingError.BadFormat);
3119  throw exception3;
3120  }
3121  num = (ushort)m_String.Length;
3122  }
3123  }
3124  m_Info.Offset.Fragment = scheme;
3125  fixed (char* ptr4 = m_String)
3126  {
3127  if (scheme < num && ptr4[(int)scheme] == '#')
3128  {
3129  scheme = (ushort)(scheme + 1);
3130  check = CheckCanonical(ptr4, ref scheme, num, '\ufffe');
3131  if ((check & Check.DisplayCanonical) == Check.None)
3132  {
3133  flags |= Flags.FragmentNotCanonical;
3134  }
3135  if ((check & (Check.EscapedCanonical | Check.BackslashInPath)) != Check.EscapedCanonical)
3136  {
3137  flags |= Flags.E_FragmentNotCanonical;
3138  }
3139  if (m_iriParsing && (check & (Check.EscapedCanonical | Check.DisplayCanonical | Check.BackslashInPath | Check.NotIriCanonical | Check.FoundNonAscii)) == (Check.DisplayCanonical | Check.FoundNonAscii))
3140  {
3141  flags |= Flags.FragmentIriCanonical;
3142  }
3143  }
3144  }
3145  m_Info.Offset.End = scheme;
3146  }
3147  flags |= Flags.AllUriInfoSet;
3148  lock (m_Info)
3149  {
3150  m_Flags |= flags;
3151  }
3152  m_Flags |= Flags.RestUnicodeNormalized;
3153  }
3154 
3155  private unsafe static ushort ParseSchemeCheckImplicitFile(char* uriString, ushort length, ref ParsingError err, ref Flags flags, ref UriParser syntax)
3156  {
3157  ushort num = 0;
3158  while (num < length && IsLWS(uriString[(int)num]))
3159  {
3160  num = (ushort)(num + 1);
3161  }
3162  ushort num2 = num;
3163  while (num2 < length && uriString[(int)num2] != ':')
3164  {
3165  num2 = (ushort)(num2 + 1);
3166  }
3167  if (IntPtr.Size == 4 && num2 != length && num2 >= num + 2 && CheckKnownSchemes((long*)(uriString + (int)num), (ushort)(num2 - num), ref syntax))
3168  {
3169  return (ushort)(num2 + 1);
3170  }
3171  if (num + 2 >= length || num2 == num)
3172  {
3173  err = ParsingError.BadFormat;
3174  return 0;
3175  }
3176  char c;
3177  if ((c = uriString[num + 1]) == ':' || c == '|')
3178  {
3179  if (IsAsciiLetter(uriString[(int)num]))
3180  {
3181  if ((c = uriString[num + 2]) == '\\' || c == '/')
3182  {
3183  flags |= (Flags.AuthorityFound | Flags.DosPath | Flags.ImplicitFile);
3184  syntax = UriParser.FileUri;
3185  return num;
3186  }
3187  err = ParsingError.MustRootedPath;
3188  return 0;
3189  }
3190  if (c == ':')
3191  {
3192  err = ParsingError.BadScheme;
3193  }
3194  else
3195  {
3196  err = ParsingError.BadFormat;
3197  }
3198  return 0;
3199  }
3200  if ((c = uriString[(int)num]) == '/' || c == '\\')
3201  {
3202  if ((c = uriString[num + 1]) == '\\' || c == '/')
3203  {
3204  flags |= (Flags.AuthorityFound | Flags.UncPath | Flags.ImplicitFile);
3205  syntax = UriParser.FileUri;
3206  num = (ushort)(num + 2);
3207  while (num < length && ((c = uriString[(int)num]) == '/' || c == '\\'))
3208  {
3209  num = (ushort)(num + 1);
3210  }
3211  return num;
3212  }
3213  err = ParsingError.BadFormat;
3214  return 0;
3215  }
3216  if (num2 == length)
3217  {
3218  err = ParsingError.BadFormat;
3219  return 0;
3220  }
3221  if (num2 - num > 1024)
3222  {
3223  err = ParsingError.SchemeLimit;
3224  return 0;
3225  }
3226  char* ptr = stackalloc char[num2 - num];
3227  length = 0;
3228  while (num < num2)
3229  {
3230  char* intPtr = ptr;
3231  ushort num3 = length;
3232  length = (ushort)(num3 + 1);
3233  intPtr[(int)num3] = uriString[(int)num];
3234  num = (ushort)(num + 1);
3235  }
3236  err = CheckSchemeSyntax(ptr, length, ref syntax);
3237  if (err != 0)
3238  {
3239  return 0;
3240  }
3241  return (ushort)(num2 + 1);
3242  }
3243 
3244  private unsafe static bool CheckKnownSchemes(long* lptr, ushort nChars, ref UriParser syntax)
3245  {
3246  if (nChars == 2)
3247  {
3248  if (((int)(*lptr) | 0x200020) == 7536759)
3249  {
3250  syntax = UriParser.WsUri;
3251  return true;
3252  }
3253  return false;
3254  }
3255  switch (*lptr | 0x20002000200020)
3256  {
3257  case 31525695615402088L:
3258  switch (nChars)
3259  {
3260  case 4:
3261  syntax = UriParser.HttpUri;
3262  return true;
3263  case 5:
3264  if ((*(ushort*)(lptr + 1) | 0x20) == 115)
3265  {
3266  syntax = UriParser.HttpsUri;
3267  return true;
3268  }
3269  break;
3270  }
3271  break;
3272  case 16326042577993847L:
3273  if (nChars == 3)
3274  {
3275  syntax = UriParser.WssUri;
3276  return true;
3277  }
3278  break;
3279  case 28429436511125606L:
3280  if (nChars == 4)
3281  {
3282  syntax = UriParser.FileUri;
3283  return true;
3284  }
3285  break;
3286  case 16326029693157478L:
3287  if (nChars == 3)
3288  {
3289  syntax = UriParser.FtpUri;
3290  return true;
3291  }
3292  break;
3293  case 32370133429452910L:
3294  if (nChars == 4)
3295  {
3296  syntax = UriParser.NewsUri;
3297  return true;
3298  }
3299  break;
3300  case 31525695615008878L:
3301  if (nChars == 4)
3302  {
3303  syntax = UriParser.NntpUri;
3304  return true;
3305  }
3306  break;
3307  case 28147948650299509L:
3308  if (nChars == 4)
3309  {
3310  syntax = UriParser.UuidUri;
3311  return true;
3312  }
3313  break;
3314  case 29273878621519975L:
3315  if (nChars == 6 && (*(int*)(lptr + 1) | 0x200020) == 7471205)
3316  {
3317  syntax = UriParser.GopherUri;
3318  return true;
3319  }
3320  break;
3321  case 30399748462674029L:
3322  if (nChars == 6 && (*(int*)(lptr + 1) | 0x200020) == 7274612)
3323  {
3324  syntax = UriParser.MailToUri;
3325  return true;
3326  }
3327  break;
3328  case 30962711301259380L:
3329  if (nChars == 6 && (*(int*)(lptr + 1) | 0x200020) == 7602277)
3330  {
3331  syntax = UriParser.TelnetUri;
3332  return true;
3333  }
3334  break;
3335  case 12948347151515758L:
3336  if (nChars == 8 && (lptr[1] | 0x20002000200020) == 28429453690994800L)
3337  {
3338  syntax = UriParser.NetPipeUri;
3339  return true;
3340  }
3341  if (nChars == 7 && (lptr[1] | 0x20002000200020) == 16326029692043380L)
3342  {
3343  syntax = UriParser.NetTcpUri;
3344  return true;
3345  }
3346  break;
3347  case 31525614009974892L:
3348  if (nChars == 4)
3349  {
3350  syntax = UriParser.LdapUri;
3351  return true;
3352  }
3353  break;
3354  }
3355  return false;
3356  }
3357 
3358  private unsafe static ParsingError CheckSchemeSyntax(char* ptr, ushort length, ref UriParser syntax)
3359  {
3360  char c = *ptr;
3361  if (c < 'a' || c > 'z')
3362  {
3363  if (c < 'A' || c > 'Z')
3364  {
3365  return ParsingError.BadScheme;
3366  }
3367  *ptr = (char)(c | 0x20);
3368  }
3369  for (ushort num = 1; num < length; num = (ushort)(num + 1))
3370  {
3371  char c2 = ptr[(int)num];
3372  if (c2 < 'a' || c2 > 'z')
3373  {
3374  if (c2 >= 'A' && c2 <= 'Z')
3375  {
3376  ptr[(int)num] = (char)(c2 | 0x20);
3377  }
3378  else if ((c2 < '0' || c2 > '9') && c2 != '+' && c2 != '-' && c2 != '.')
3379  {
3380  return ParsingError.BadScheme;
3381  }
3382  }
3383  }
3384  string lwrCaseScheme = new string(ptr, 0, length);
3385  syntax = UriParser.FindOrFetchAsUnknownV1Syntax(lwrCaseScheme);
3386  return ParsingError.None;
3387  }
3388 
3389  private unsafe ushort CheckAuthorityHelper(char* pString, ushort idx, ushort length, ref ParsingError err, ref Flags flags, UriParser syntax, ref string newHost)
3390  {
3391  int i = length;
3392  int num = idx;
3393  ushort num2 = idx;
3394  newHost = null;
3395  bool justNormalized = false;
3396  bool flag = s_IriParsing && IriParsingStatic(syntax);
3397  bool flag2 = (flags & Flags.HasUnicode) != Flags.Zero;
3398  bool flag3 = (flags & Flags.HostUnicodeNormalized) == Flags.Zero;
3399  UriSyntaxFlags flags2 = syntax.Flags;
3400  if ((flag2 && flag) & flag3)
3401  {
3402  newHost = m_originalUnicodeString.Substring(0, num);
3403  }
3404  char c;
3405  if (idx == length || (c = pString[(int)idx]) == '/' || (c == '\\' && StaticIsFile(syntax)) || c == '#' || c == '?')
3406  {
3407  if (syntax.InFact(UriSyntaxFlags.AllowEmptyHost))
3408  {
3409  flags &= ~Flags.UncPath;
3410  if (StaticInFact(flags, Flags.ImplicitFile))
3411  {
3412  err = ParsingError.BadHostName;
3413  }
3414  else
3415  {
3416  flags |= Flags.BasicHostType;
3417  }
3418  }
3419  else
3420  {
3421  err = ParsingError.BadHostName;
3422  }
3423  if ((flag2 && flag) & flag3)
3424  {
3425  flags |= Flags.HostUnicodeNormalized;
3426  }
3427  return idx;
3428  }
3429  string text = null;
3430  if ((flags2 & UriSyntaxFlags.MayHaveUserInfo) != 0)
3431  {
3432  while (num2 < i)
3433  {
3434  if (num2 == i - 1 || pString[(int)num2] == '?' || pString[(int)num2] == '#' || pString[(int)num2] == '\\' || pString[(int)num2] == '/')
3435  {
3436  num2 = idx;
3437  break;
3438  }
3439  if (pString[(int)num2] == '@')
3440  {
3441  flags |= Flags.HasUserInfo;
3442  if (flag || s_IdnScope != 0)
3443  {
3444  if ((flag && flag2) & flag3)
3445  {
3446  text = IriHelper.EscapeUnescapeIri(pString, num, num2 + 1, UriComponents.UserInfo);
3447  try
3448  {
3449  if (UriParser.ShouldUseLegacyV2Quirks)
3450  {
3451  text = text.Normalize(NormalizationForm.FormC);
3452  }
3453  }
3454  catch (ArgumentException)
3455  {
3456  err = ParsingError.BadFormat;
3457  return idx;
3458  }
3459  newHost += text;
3460  }
3461  else
3462  {
3463  text = new string(pString, num, num2 - num + 1);
3464  }
3465  }
3466  num2 = (ushort)(num2 + 1);
3467  c = pString[(int)num2];
3468  break;
3469  }
3470  num2 = (ushort)(num2 + 1);
3471  }
3472  }
3473  bool notCanonical = (flags2 & UriSyntaxFlags.SimpleUserSyntax) == UriSyntaxFlags.None;
3474  if (c == '[' && syntax.InFact(UriSyntaxFlags.AllowIPv6Host) && IPv6AddressHelper.IsValid(pString, num2 + 1, ref i))
3475  {
3476  flags |= Flags.IPv6HostType;
3477  if (!s_ConfigInitialized)
3478  {
3479  InitializeUriConfig();
3480  m_iriParsing = (s_IriParsing && IriParsingStatic(syntax));
3481  }
3482  if ((flag2 && flag) & flag3)
3483  {
3484  newHost += new string(pString, num2, i - num2);
3485  flags |= Flags.HostUnicodeNormalized;
3486  justNormalized = true;
3487  }
3488  }
3489  else if (c <= '9' && c >= '0' && syntax.InFact(UriSyntaxFlags.AllowIPv4Host) && IPv4AddressHelper.IsValid(pString, num2, ref i, allowIPv6: false, StaticNotAny(flags, Flags.ImplicitFile), syntax.InFact(UriSyntaxFlags.V1_UnknownUri)))
3490  {
3491  flags |= Flags.IPv4HostType;
3492  if ((flag2 && flag) & flag3)
3493  {
3494  newHost += new string(pString, num2, i - num2);
3495  flags |= Flags.HostUnicodeNormalized;
3496  justNormalized = true;
3497  }
3498  }
3499  else if ((flags2 & UriSyntaxFlags.AllowDnsHost) != 0 && !flag && DomainNameHelper.IsValid(pString, num2, ref i, ref notCanonical, StaticNotAny(flags, Flags.ImplicitFile)))
3500  {
3501  flags |= Flags.DnsHostType;
3502  if (!notCanonical)
3503  {
3504  flags |= Flags.CanonicalDnsHost;
3505  }
3506  if (s_IdnScope != 0)
3507  {
3508  if (s_IdnScope == UriIdnScope.AllExceptIntranet && IsIntranet(new string(pString, 0, i)))
3509  {
3510  flags |= Flags.IntranetUri;
3511  }
3512  if (AllowIdnStatic(syntax, flags))
3513  {
3514  bool allAscii = true;
3515  bool atLeastOneValidIdn = false;
3516  string str = DomainNameHelper.UnicodeEquivalent(pString, num2, i, ref allAscii, ref atLeastOneValidIdn);
3517  if (atLeastOneValidIdn)
3518  {
3519  if (StaticNotAny(flags, Flags.HasUnicode))
3520  {
3521  m_originalUnicodeString = m_String;
3522  }
3523  flags |= Flags.IdnHost;
3524  newHost = m_originalUnicodeString.Substring(0, num) + text + str;
3525  flags |= Flags.CanonicalDnsHost;
3526  m_DnsSafeHost = new string(pString, num2, i - num2);
3527  justNormalized = true;
3528  }
3529  flags |= Flags.HostUnicodeNormalized;
3530  }
3531  }
3532  }
3533  else if ((flags2 & UriSyntaxFlags.AllowDnsHost) != 0 && ((syntax.InFact(UriSyntaxFlags.AllowIriParsing) && flag3) || syntax.InFact(UriSyntaxFlags.AllowIdn)) && DomainNameHelper.IsValidByIri(pString, num2, ref i, ref notCanonical, StaticNotAny(flags, Flags.ImplicitFile)))
3534  {
3535  CheckAuthorityHelperHandleDnsIri(pString, num2, i, num, flag, flag2, syntax, text, ref flags, ref justNormalized, ref newHost, ref err);
3536  }
3537  else if ((flags2 & UriSyntaxFlags.AllowUncHost) != 0 && UncNameHelper.IsValid(pString, num2, ref i, StaticNotAny(flags, Flags.ImplicitFile)) && i - num2 <= 256)
3538  {
3539  flags |= Flags.UncHostType;
3540  }
3541  if (i < length && pString[i] == '\\' && (flags & Flags.HostTypeMask) != Flags.Zero && !StaticIsFile(syntax))
3542  {
3543  if (syntax.InFact(UriSyntaxFlags.V1_UnknownUri))
3544  {
3545  err = ParsingError.BadHostName;
3546  flags |= Flags.HostTypeMask;
3547  return (ushort)i;
3548  }
3549  flags &= ~Flags.HostTypeMask;
3550  }
3551  else if (i < length && pString[i] == ':')
3552  {
3553  if (syntax.InFact(UriSyntaxFlags.MayHavePort))
3554  {
3555  int num3 = 0;
3556  int num4 = i;
3557  idx = (ushort)(i + 1);
3558  while (idx < length)
3559  {
3560  ushort num5 = (ushort)(pString[(int)idx] - 48);
3561  if (num5 >= 0 && num5 <= 9)
3562  {
3563  if ((num3 = num3 * 10 + num5) > 65535)
3564  {
3565  break;
3566  }
3567  idx = (ushort)(idx + 1);
3568  continue;
3569  }
3570  if (num5 == ushort.MaxValue || num5 == 15 || num5 == 65523)
3571  {
3572  break;
3573  }
3574  if (syntax.InFact(UriSyntaxFlags.AllowAnyOtherHost) && syntax.NotAny(UriSyntaxFlags.V1_UnknownUri))
3575  {
3576  flags &= ~Flags.HostTypeMask;
3577  break;
3578  }
3579  err = ParsingError.BadPort;
3580  return idx;
3581  }
3582  if (num3 > 65535)
3583  {
3584  if (!syntax.InFact(UriSyntaxFlags.AllowAnyOtherHost))
3585  {
3586  err = ParsingError.BadPort;
3587  return idx;
3588  }
3589  flags &= ~Flags.HostTypeMask;
3590  }
3591  if ((flag && flag2) & justNormalized)
3592  {
3593  newHost += new string(pString, num4, idx - num4);
3594  }
3595  }
3596  else
3597  {
3598  flags &= ~Flags.HostTypeMask;
3599  }
3600  }
3601  if ((flags & Flags.HostTypeMask) == Flags.Zero)
3602  {
3603  flags &= ~Flags.HasUserInfo;
3604  if (syntax.InFact(UriSyntaxFlags.AllowAnyOtherHost))
3605  {
3606  flags |= Flags.BasicHostType;
3607  for (i = idx; i < length && pString[i] != '/' && pString[i] != '?' && pString[i] != '#'; i++)
3608  {
3609  }
3610  CheckAuthorityHelperHandleAnyHostIri(pString, num, i, flag, flag2, syntax, ref flags, ref newHost, ref err);
3611  }
3612  else if (syntax.InFact(UriSyntaxFlags.V1_UnknownUri))
3613  {
3614  bool flag4 = false;
3615  int num6 = idx;
3616  for (i = idx; i < length && (!flag4 || (pString[i] != '/' && pString[i] != '?' && pString[i] != '#')); i++)
3617  {
3618  if (i < idx + 2 && pString[i] == '.')
3619  {
3620  flag4 = true;
3621  continue;
3622  }
3623  err = ParsingError.BadHostName;
3624  flags |= Flags.HostTypeMask;
3625  return idx;
3626  }
3627  flags |= Flags.BasicHostType;
3628  if (flag && flag2 && StaticNotAny(flags, Flags.HostUnicodeNormalized))
3629  {
3630  string text2 = new string(pString, num6, i - num6);
3631  try
3632  {
3633  newHost += text2.Normalize(NormalizationForm.FormC);
3634  }
3635  catch (ArgumentException)
3636  {
3637  err = ParsingError.BadFormat;
3638  return idx;
3639  }
3640  flags |= Flags.HostUnicodeNormalized;
3641  }
3642  }
3643  else if (syntax.InFact(UriSyntaxFlags.MustHaveAuthority) || (syntax.InFact(UriSyntaxFlags.MailToLikeUri) && !UriParser.ShouldUseLegacyV2Quirks))
3644  {
3645  err = ParsingError.BadHostName;
3646  flags |= Flags.HostTypeMask;
3647  return idx;
3648  }
3649  }
3650  return (ushort)i;
3651  }
3652 
3653  private unsafe void CheckAuthorityHelperHandleDnsIri(char* pString, ushort start, int end, int startInput, bool iriParsing, bool hasUnicode, UriParser syntax, string userInfoString, ref Flags flags, ref bool justNormalized, ref string newHost, ref ParsingError err)
3654  {
3655  flags |= Flags.DnsHostType;
3656  if (s_IdnScope == UriIdnScope.AllExceptIntranet && IsIntranet(new string(pString, 0, end)))
3657  {
3658  flags |= Flags.IntranetUri;
3659  }
3660  if (AllowIdnStatic(syntax, flags))
3661  {
3662  bool allAscii = true;
3663  bool atLeastOneValidIdn = false;
3664  string text = DomainNameHelper.IdnEquivalent(pString, start, end, ref allAscii, ref atLeastOneValidIdn);
3665  string text2 = DomainNameHelper.UnicodeEquivalent(text, pString, start, end);
3666  if (!allAscii)
3667  {
3668  flags |= Flags.UnicodeHost;
3669  }
3670  if (atLeastOneValidIdn)
3671  {
3672  flags |= Flags.IdnHost;
3673  }
3674  if (allAscii && atLeastOneValidIdn && StaticNotAny(flags, Flags.HasUnicode))
3675  {
3676  m_originalUnicodeString = m_String;
3677  newHost = m_originalUnicodeString.Substring(0, startInput) + (StaticInFact(flags, Flags.HasUserInfo) ? userInfoString : null);
3678  justNormalized = true;
3679  }
3680  else if (!iriParsing && (StaticInFact(flags, Flags.UnicodeHost) || StaticInFact(flags, Flags.IdnHost)))
3681  {
3682  m_originalUnicodeString = m_String;
3683  newHost = m_originalUnicodeString.Substring(0, startInput) + (StaticInFact(flags, Flags.HasUserInfo) ? userInfoString : null);
3684  justNormalized = true;
3685  }
3686  if (!allAscii || atLeastOneValidIdn)
3687  {
3688  m_DnsSafeHost = text;
3689  newHost += text2;
3690  justNormalized = true;
3691  }
3692  else if ((allAscii && !atLeastOneValidIdn) & iriParsing & hasUnicode)
3693  {
3694  newHost += text2;
3695  justNormalized = true;
3696  }
3697  }
3698  else if (hasUnicode)
3699  {
3700  string text3 = StripBidiControlCharacter(pString, start, end - start);
3701  try
3702  {
3703  newHost += text3?.Normalize(NormalizationForm.FormC);
3704  }
3705  catch (ArgumentException)
3706  {
3707  err = ParsingError.BadHostName;
3708  }
3709  justNormalized = true;
3710  }
3711  flags |= Flags.HostUnicodeNormalized;
3712  }
3713 
3714  private unsafe void CheckAuthorityHelperHandleAnyHostIri(char* pString, int startInput, int end, bool iriParsing, bool hasUnicode, UriParser syntax, ref Flags flags, ref string newHost, ref ParsingError err)
3715  {
3716  if (!StaticNotAny(flags, Flags.HostUnicodeNormalized) || (!AllowIdnStatic(syntax, flags) && (!iriParsing || !hasUnicode)))
3717  {
3718  return;
3719  }
3720  string text = new string(pString, startInput, end - startInput);
3721  if (AllowIdnStatic(syntax, flags))
3722  {
3723  bool allAscii = true;
3724  bool atLeastOneValidIdn = false;
3725  string text2 = DomainNameHelper.UnicodeEquivalent(pString, startInput, end, ref allAscii, ref atLeastOneValidIdn);
3726  if (((allAscii && atLeastOneValidIdn) || !allAscii) && (!iriParsing || !hasUnicode))
3727  {
3728  m_originalUnicodeString = m_String;
3729  newHost = m_originalUnicodeString.Substring(0, startInput);
3730  flags |= Flags.HasUnicode;
3731  }
3732  if (atLeastOneValidIdn || !allAscii)
3733  {
3734  newHost += text2;
3735  string bidiStrippedHost = null;
3736  m_DnsSafeHost = DomainNameHelper.IdnEquivalent(pString, startInput, end, ref allAscii, ref bidiStrippedHost);
3737  if (atLeastOneValidIdn)
3738  {
3739  flags |= Flags.IdnHost;
3740  }
3741  if (!allAscii)
3742  {
3743  flags |= Flags.UnicodeHost;
3744  }
3745  }
3746  else if (iriParsing && hasUnicode)
3747  {
3748  newHost += text;
3749  }
3750  }
3751  else
3752  {
3753  try
3754  {
3755  newHost += text.Normalize(NormalizationForm.FormC);
3756  }
3757  catch (ArgumentException)
3758  {
3759  err = ParsingError.BadHostName;
3760  }
3761  }
3762  flags |= Flags.HostUnicodeNormalized;
3763  }
3764 
3765  private unsafe void FindEndOfComponent(string input, ref ushort idx, ushort end, char delim)
3766  {
3767  fixed (char* str = input)
3768  {
3769  FindEndOfComponent(str, ref idx, end, delim);
3770  }
3771  }
3772 
3773  private unsafe void FindEndOfComponent(char* str, ref ushort idx, ushort end, char delim)
3774  {
3775  char c = '\uffff';
3776  ushort num;
3777  for (num = idx; num < end; num = (ushort)(num + 1))
3778  {
3779  c = str[(int)num];
3780  if (c == delim || (delim == '?' && c == '#' && m_Syntax != null && m_Syntax.InFact(UriSyntaxFlags.MayHaveFragment)))
3781  {
3782  break;
3783  }
3784  }
3785  idx = num;
3786  }
3787 
3788  private unsafe Check CheckCanonical(char* str, ref ushort idx, ushort end, char delim)
3789  {
3790  Check check = Check.None;
3791  bool flag = false;
3792  bool flag2 = false;
3793  char c = '\uffff';
3794  ushort num;
3795  for (num = idx; num < end; num = (ushort)(num + 1))
3796  {
3797  c = str[(int)num];
3798  if (c <= '\u001f' || (c >= '\u007f' && c <= '\u009f'))
3799  {
3800  flag = true;
3801  flag2 = true;
3802  check |= Check.ReservedFound;
3803  }
3804  else if (c > 'z' && c != '~')
3805  {
3806  if (m_iriParsing)
3807  {
3808  bool flag3 = false;
3809  check |= Check.FoundNonAscii;
3810  if (char.IsHighSurrogate(c))
3811  {
3812  if (num + 1 < end)
3813  {
3814  bool surrogatePair = false;
3815  flag3 = IriHelper.CheckIriUnicodeRange(c, str[num + 1], ref surrogatePair, isQuery: true);
3816  }
3817  }
3818  else
3819  {
3820  flag3 = IriHelper.CheckIriUnicodeRange(c, isQuery: true);
3821  }
3822  if (!flag3)
3823  {
3824  check |= Check.NotIriCanonical;
3825  }
3826  }
3827  if (!flag)
3828  {
3829  flag = true;
3830  }
3831  }
3832  else
3833  {
3834  if (c == delim || (delim == '?' && c == '#' && m_Syntax != null && m_Syntax.InFact(UriSyntaxFlags.MayHaveFragment)))
3835  {
3836  break;
3837  }
3838  switch (c)
3839  {
3840  case '?':
3841  if (IsImplicitFile || (m_Syntax != null && !m_Syntax.InFact(UriSyntaxFlags.MayHaveQuery) && delim != '\ufffe'))
3842  {
3843  check |= Check.ReservedFound;
3844  flag2 = true;
3845  flag = true;
3846  }
3847  break;
3848  case '#':
3849  flag = true;
3850  if (IsImplicitFile || (m_Syntax != null && !m_Syntax.InFact(UriSyntaxFlags.MayHaveFragment)))
3851  {
3852  check |= Check.ReservedFound;
3853  flag2 = true;
3854  }
3855  break;
3856  case '/':
3857  case '\\':
3858  if ((check & Check.BackslashInPath) == Check.None && c == '\\')
3859  {
3860  check |= Check.BackslashInPath;
3861  }
3862  if ((check & Check.DotSlashAttn) == Check.None && num + 1 != end && (str[num + 1] == '/' || str[num + 1] == '\\'))
3863  {
3864  check |= Check.DotSlashAttn;
3865  }
3866  break;
3867  case '.':
3868  if (((check & Check.DotSlashAttn) == Check.None && num + 1 == end) || str[num + 1] == '.' || str[num + 1] == '/' || str[num + 1] == '\\' || str[num + 1] == '?' || str[num + 1] == '#')
3869  {
3870  check |= Check.DotSlashAttn;
3871  }
3872  break;
3873  default:
3874  if (!flag && ((c <= '"' && c != '!') || (c >= '[' && c <= '^') || c == '>' || c == '<' || c == '`'))
3875  {
3876  flag = true;
3877  }
3878  else
3879  {
3880  if (c != '%')
3881  {
3882  break;
3883  }
3884  if (!flag2)
3885  {
3886  flag2 = true;
3887  }
3888  if (num + 2 < end && (c = UriHelper.EscapedAscii(str[num + 1], str[num + 2])) != '\uffff')
3889  {
3890  if (c == '.' || c == '/' || c == '\\')
3891  {
3892  check |= Check.DotSlashEscaped;
3893  }
3894  num = (ushort)(num + 2);
3895  }
3896  else if (!flag)
3897  {
3898  flag = true;
3899  }
3900  }
3901  break;
3902  }
3903  }
3904  }
3905  if (flag2)
3906  {
3907  if (!flag)
3908  {
3909  check |= Check.EscapedCanonical;
3910  }
3911  }
3912  else
3913  {
3914  check |= Check.DisplayCanonical;
3915  if (!flag)
3916  {
3917  check |= Check.EscapedCanonical;
3918  }
3919  }
3920  idx = num;
3921  return check;
3922  }
3923 
3924  private unsafe char[] GetCanonicalPath(char[] dest, ref int pos, UriFormat formatAs)
3925  {
3926  if (InFact(Flags.FirstSlashAbsent))
3927  {
3928  dest[pos++] = '/';
3929  }
3930  if (m_Info.Offset.Path == m_Info.Offset.Query)
3931  {
3932  return dest;
3933  }
3934  int end = pos;
3935  int securedPathIndex = SecuredPathIndex;
3936  if (formatAs == UriFormat.UriEscaped)
3937  {
3938  if (InFact(Flags.ShouldBeCompressed))
3939  {
3940  m_String.CopyTo(m_Info.Offset.Path, dest, end, m_Info.Offset.Query - m_Info.Offset.Path);
3941  end += m_Info.Offset.Query - m_Info.Offset.Path;
3942  if (m_Syntax.InFact(UriSyntaxFlags.UnEscapeDotsAndSlashes) && InFact(Flags.PathNotCanonical) && !IsImplicitFile)
3943  {
3944  char[] array = dest;
3945  fixed (char* pch = array)
3946  {
3947  UnescapeOnly(pch, pos, ref end, '.', '/', m_Syntax.InFact(UriSyntaxFlags.ConvertPathSlashes) ? '\\' : '\uffff');
3948  }
3949  }
3950  }
3951  else if (InFact(Flags.E_PathNotCanonical) && NotAny(Flags.UserEscaped))
3952  {
3953  string text = m_String;
3954  if (securedPathIndex != 0 && text[securedPathIndex + m_Info.Offset.Path - 1] == '|')
3955  {
3956  text = text.Remove(securedPathIndex + m_Info.Offset.Path - 1, 1);
3957  text = text.Insert(securedPathIndex + m_Info.Offset.Path - 1, ":");
3958  }
3959  dest = UriHelper.EscapeString(text, m_Info.Offset.Path, m_Info.Offset.Query, dest, ref end, isUriString: true, '?', '#', IsImplicitFile ? '\uffff' : '%');
3960  }
3961  else
3962  {
3963  m_String.CopyTo(m_Info.Offset.Path, dest, end, m_Info.Offset.Query - m_Info.Offset.Path);
3964  end += m_Info.Offset.Query - m_Info.Offset.Path;
3965  }
3966  }
3967  else
3968  {
3969  m_String.CopyTo(m_Info.Offset.Path, dest, end, m_Info.Offset.Query - m_Info.Offset.Path);
3970  end += m_Info.Offset.Query - m_Info.Offset.Path;
3971  if (InFact(Flags.ShouldBeCompressed) && m_Syntax.InFact(UriSyntaxFlags.UnEscapeDotsAndSlashes) && InFact(Flags.PathNotCanonical) && !IsImplicitFile)
3972  {
3973  char[] array = dest;
3974  fixed (char* pch2 = array)
3975  {
3976  UnescapeOnly(pch2, pos, ref end, '.', '/', m_Syntax.InFact(UriSyntaxFlags.ConvertPathSlashes) ? '\\' : '\uffff');
3977  }
3978  }
3979  }
3980  if (securedPathIndex != 0 && dest[securedPathIndex + pos - 1] == '|')
3981  {
3982  dest[securedPathIndex + pos - 1] = ':';
3983  }
3984  if (InFact(Flags.ShouldBeCompressed))
3985  {
3986  dest = Compress(dest, (ushort)(pos + securedPathIndex), ref end, m_Syntax);
3987  if (dest[pos] == '\\')
3988  {
3989  dest[pos] = '/';
3990  }
3991  if (formatAs == UriFormat.UriEscaped && NotAny(Flags.UserEscaped) && InFact(Flags.E_PathNotCanonical))
3992  {
3993  string input = new string(dest, pos, end - pos);
3994  dest = UriHelper.EscapeString(input, 0, end - pos, dest, ref pos, isUriString: true, '?', '#', IsImplicitFile ? '\uffff' : '%');
3995  end = pos;
3996  }
3997  }
3998  else if (m_Syntax.InFact(UriSyntaxFlags.ConvertPathSlashes) && InFact(Flags.BackslashInPath))
3999  {
4000  for (int i = pos; i < end; i++)
4001  {
4002  if (dest[i] == '\\')
4003  {
4004  dest[i] = '/';
4005  }
4006  }
4007  }
4008  if (formatAs != UriFormat.UriEscaped && InFact(Flags.PathNotCanonical))
4009  {
4010  UnescapeMode unescapeMode;
4011  if (InFact(Flags.PathNotCanonical))
4012  {
4013  switch (formatAs)
4014  {
4015  case (UriFormat)32767:
4016  unescapeMode = (UnescapeMode)((InFact(Flags.UserEscaped) ? 2 : 3) | 4);
4017  if (IsImplicitFile)
4018  {
4019  unescapeMode &= ~UnescapeMode.Unescape;
4020  }
4021  break;
4022  case UriFormat.Unescaped:
4023  unescapeMode = ((!IsImplicitFile) ? (UnescapeMode.Unescape | UnescapeMode.UnescapeAll) : UnescapeMode.CopyOnly);
4024  break;
4025  default:
4026  unescapeMode = (InFact(Flags.UserEscaped) ? UnescapeMode.Unescape : UnescapeMode.EscapeUnescape);
4027  if (IsImplicitFile)
4028  {
4029  unescapeMode &= ~UnescapeMode.Unescape;
4030  }
4031  break;
4032  }
4033  }
4034  else
4035  {
4036  unescapeMode = UnescapeMode.CopyOnly;
4037  }
4038  char[] array2 = new char[dest.Length];
4039  Buffer.BlockCopy(dest, 0, array2, 0, end << 1);
4040  char[] array = array2;
4041  fixed (char* pStr = array)
4042  {
4043  dest = UriHelper.UnescapeString(pStr, pos, end, dest, ref pos, '?', '#', '\uffff', unescapeMode, m_Syntax, isQuery: false);
4044  }
4045  }
4046  else
4047  {
4048  pos = end;
4049  }
4050  return dest;
4051  }
4052 
4053  private unsafe static void UnescapeOnly(char* pch, int start, ref int end, char ch1, char ch2, char ch3)
4054  {
4055  if (end - start < 3)
4056  {
4057  return;
4058  }
4059  char* ptr = pch + end - 2;
4060  pch += start;
4061  char* ptr2 = null;
4062  while (pch < ptr)
4063  {
4064  char* intPtr = pch;
4065  pch = intPtr + 1;
4066  if (*intPtr != '%')
4067  {
4068  continue;
4069  }
4070  char* intPtr2 = pch;
4071  pch = intPtr2 + 1;
4072  char digit = *intPtr2;
4073  char* intPtr3 = pch;
4074  pch = intPtr3 + 1;
4075  char c = UriHelper.EscapedAscii(digit, *intPtr3);
4076  if (c != ch1 && c != ch2 && c != ch3)
4077  {
4078  continue;
4079  }
4080  ptr2 = pch - 2;
4081  *(ptr2 - 1) = c;
4082  while (pch < ptr)
4083  {
4084  char* intPtr4 = ptr2;
4085  ptr2 = intPtr4 + 1;
4086  char* intPtr5 = pch;
4087  pch = intPtr5 + 1;
4088  char c2;
4089  *intPtr4 = (c2 = *intPtr5);
4090  if (c2 == '%')
4091  {
4092  char* intPtr6 = ptr2;
4093  ptr2 = intPtr6 + 1;
4094  char* intPtr7 = pch;
4095  pch = intPtr7 + 1;
4096  *intPtr6 = (c2 = *intPtr7);
4097  char digit2 = c2;
4098  char* intPtr8 = ptr2;
4099  ptr2 = intPtr8 + 1;
4100  char* intPtr9 = pch;
4101  pch = intPtr9 + 1;
4102  *intPtr8 = (c2 = *intPtr9);
4103  c = UriHelper.EscapedAscii(digit2, c2);
4104  if (c == ch1 || c == ch2 || c == ch3)
4105  {
4106  ptr2 -= 2;
4107  *(ptr2 - 1) = c;
4108  }
4109  }
4110  }
4111  break;
4112  }
4113  ptr += 2;
4114  if (ptr2 == null)
4115  {
4116  return;
4117  }
4118  if (pch == ptr)
4119  {
4120  end -= (int)(pch - ptr2);
4121  return;
4122  }
4123  char* intPtr10 = ptr2;
4124  ptr2 = intPtr10 + 1;
4125  char* intPtr11 = pch;
4126  pch = intPtr11 + 1;
4127  *intPtr10 = *intPtr11;
4128  if (pch == ptr)
4129  {
4130  end -= (int)(pch - ptr2);
4131  return;
4132  }
4133  char* intPtr12 = ptr2;
4134  ptr2 = intPtr12 + 1;
4135  char* intPtr13 = pch;
4136  pch = intPtr13 + 1;
4137  *intPtr12 = *intPtr13;
4138  end -= (int)(pch - ptr2);
4139  }
4140 
4141  private static char[] Compress(char[] dest, ushort start, ref int destLength, UriParser syntax)
4142  {
4143  ushort num = 0;
4144  ushort num2 = 0;
4145  ushort num3 = 0;
4146  ushort num4 = 0;
4147  ushort num5 = (ushort)((ushort)destLength - 1);
4148  for (start = (ushort)(start - 1); num5 != start; num5 = (ushort)(num5 - 1))
4149  {
4150  char c = dest[num5];
4151  if (c == '\\' && syntax.InFact(UriSyntaxFlags.ConvertPathSlashes))
4152  {
4153  c = (dest[num5] = '/');
4154  }
4155  if (c == '/')
4156  {
4157  num = (ushort)(num + 1);
4158  }
4159  else
4160  {
4161  if (num > 1)
4162  {
4163  num2 = (ushort)(num5 + 1);
4164  }
4165  num = 0;
4166  }
4167  if (c == '.')
4168  {
4169  num3 = (ushort)(num3 + 1);
4170  continue;
4171  }
4172  if (num3 != 0)
4173  {
4174  bool flag = syntax.NotAny(UriSyntaxFlags.CanonicalizeAsFilePath) && (num3 > 2 || c != '/' || num5 == start);
4175  if (!flag && c == '/')
4176  {
4177  if ((num2 == num5 + num3 + 1 || (num2 == 0 && num5 + num3 + 1 == destLength)) && (UriParser.ShouldUseLegacyV2Quirks || num3 <= 2))
4178  {
4179  num2 = (ushort)(num5 + 1 + num3 + ((num2 != 0) ? 1 : 0));
4180  Buffer.BlockCopy(dest, num2 << 1, dest, num5 + 1 << 1, destLength - num2 << 1);
4181  destLength -= num2 - num5 - 1;
4182  num2 = num5;
4183  if (num3 == 2)
4184  {
4185  num4 = (ushort)(num4 + 1);
4186  }
4187  num3 = 0;
4188  continue;
4189  }
4190  }
4191  else if (UriParser.ShouldUseLegacyV2Quirks && !flag && num4 == 0 && (num2 == num5 + num3 + 1 || (num2 == 0 && num5 + num3 + 1 == destLength)))
4192  {
4193  num3 = (ushort)(num5 + 1 + num3);
4194  Buffer.BlockCopy(dest, num3 << 1, dest, num5 + 1 << 1, destLength - num3 << 1);
4195  destLength -= num3 - num5 - 1;
4196  num2 = 0;
4197  num3 = 0;
4198  continue;
4199  }
4200  num3 = 0;
4201  }
4202  if (c == '/')
4203  {
4204  if (num4 != 0)
4205  {
4206  num4 = (ushort)(num4 - 1);
4207  num2 = (ushort)(num2 + 1);
4208  Buffer.BlockCopy(dest, num2 << 1, dest, num5 + 1 << 1, destLength - num2 << 1);
4209  destLength -= num2 - num5 - 1;
4210  }
4211  num2 = num5;
4212  }
4213  }
4214  start = (ushort)(start + 1);
4215  if ((ushort)destLength > start && syntax.InFact(UriSyntaxFlags.CanonicalizeAsFilePath) && num <= 1)
4216  {
4217  if (num4 != 0 && dest[start] != '/')
4218  {
4219  num2 = (ushort)(num2 + 1);
4220  Buffer.BlockCopy(dest, num2 << 1, dest, start << 1, destLength - num2 << 1);
4221  destLength -= num2;
4222  }
4223  else if (num3 != 0 && (num2 == num3 + 1 || (num2 == 0 && num3 + 1 == destLength)))
4224  {
4225  num3 = (ushort)(num3 + ((num2 != 0) ? 1 : 0));
4226  Buffer.BlockCopy(dest, num3 << 1, dest, start << 1, destLength - num3 << 1);
4227  destLength -= num3;
4228  }
4229  }
4230  return dest;
4231  }
4232 
4233  internal static int CalculateCaseInsensitiveHashCode(string text)
4234  {
4235  return StringComparer.InvariantCultureIgnoreCase.GetHashCode(text);
4236  }
4237 
4238  private static string CombineUri(Uri basePart, string relativePart, UriFormat uriFormat)
4239  {
4240  char c = relativePart[0];
4241  if (basePart.IsDosPath && (c == '/' || c == '\\') && (relativePart.Length == 1 || (relativePart[1] != '/' && relativePart[1] != '\\')))
4242  {
4243  int num = basePart.OriginalString.IndexOf(':');
4244  if (basePart.IsImplicitFile)
4245  {
4246  return basePart.OriginalString.Substring(0, num + 1) + relativePart;
4247  }
4248  num = basePart.OriginalString.IndexOf(':', num + 1);
4249  return basePart.OriginalString.Substring(0, num + 1) + relativePart;
4250  }
4251  if (StaticIsFile(basePart.Syntax) && (c == '\\' || c == '/'))
4252  {
4253  if (relativePart.Length >= 2 && (relativePart[1] == '\\' || relativePart[1] == '/'))
4254  {
4255  if (!basePart.IsImplicitFile)
4256  {
4257  return "file:" + relativePart;
4258  }
4259  return relativePart;
4260  }
4261  if (basePart.IsUnc)
4262  {
4263  string text = basePart.GetParts(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.Unescaped);
4264  for (int i = 1; i < text.Length; i++)
4265  {
4266  if (text[i] == '/')
4267  {
4268  text = text.Substring(0, i);
4269  break;
4270  }
4271  }
4272  if (basePart.IsImplicitFile)
4273  {
4274  return "\\\\" + basePart.GetParts(UriComponents.Host, UriFormat.Unescaped) + text + relativePart;
4275  }
4276  return "file://" + basePart.GetParts(UriComponents.Host, uriFormat) + text + relativePart;
4277  }
4278  return "file://" + relativePart;
4279  }
4280  bool flag = basePart.Syntax.InFact(UriSyntaxFlags.ConvertPathSlashes);
4281  string text2 = null;
4282  if (c == '/' || (c == '\\' && flag))
4283  {
4284  if (relativePart.Length >= 2 && relativePart[1] == '/')
4285  {
4286  return basePart.Scheme + ":" + relativePart;
4287  }
4288  text2 = ((basePart.HostType != Flags.IPv6HostType) ? basePart.GetParts(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port, uriFormat) : (basePart.GetParts(UriComponents.Scheme | UriComponents.UserInfo, uriFormat) + "[" + basePart.DnsSafeHost + "]" + basePart.GetParts(UriComponents.Port | UriComponents.KeepDelimiter, uriFormat)));
4289  if (flag && c == '\\')
4290  {
4291  relativePart = "/" + relativePart.Substring(1);
4292  }
4293  return text2 + relativePart;
4294  }
4295  text2 = basePart.GetParts(UriComponents.Path | UriComponents.KeepDelimiter, basePart.IsImplicitFile ? UriFormat.Unescaped : uriFormat);
4296  int num2 = text2.Length;
4297  char[] array = new char[num2 + relativePart.Length];
4298  if (num2 > 0)
4299  {
4300  text2.CopyTo(0, array, 0, num2);
4301  while (num2 > 0)
4302  {
4303  if (array[--num2] == '/')
4304  {
4305  num2++;
4306  break;
4307  }
4308  }
4309  }
4310  relativePart.CopyTo(0, array, num2, relativePart.Length);
4311  c = (basePart.Syntax.InFact(UriSyntaxFlags.MayHaveQuery) ? '?' : '\uffff');
4312  char c2 = (!basePart.IsImplicitFile && basePart.Syntax.InFact(UriSyntaxFlags.MayHaveFragment)) ? '#' : '\uffff';
4313  string text3 = string.Empty;
4314  if (c != '\uffff' || c2 != '\uffff')
4315  {
4316  int j;
4317  for (j = 0; j < relativePart.Length && array[num2 + j] != c && array[num2 + j] != c2; j++)
4318  {
4319  }
4320  if (j == 0)
4321  {
4322  text3 = relativePart;
4323  }
4324  else if (j < relativePart.Length)
4325  {
4326  text3 = relativePart.Substring(j);
4327  }
4328  num2 += j;
4329  }
4330  else
4331  {
4332  num2 += relativePart.Length;
4333  }
4334  if (basePart.HostType == Flags.IPv6HostType)
4335  {
4336  text2 = ((!basePart.IsImplicitFile) ? (basePart.GetParts(UriComponents.Scheme | UriComponents.UserInfo, uriFormat) + "[" + basePart.DnsSafeHost + "]" + basePart.GetParts(UriComponents.Port | UriComponents.KeepDelimiter, uriFormat)) : ("\\\\[" + basePart.DnsSafeHost + "]"));
4337  }
4338  else if (basePart.IsImplicitFile)
4339  {
4340  if (basePart.IsDosPath)
4341  {
4342  array = Compress(array, 3, ref num2, basePart.Syntax);
4343  return new string(array, 1, num2 - 1) + text3;
4344  }
4345  text2 = "\\\\" + basePart.GetParts(UriComponents.Host, UriFormat.Unescaped);
4346  }
4347  else
4348  {
4349  text2 = basePart.GetParts(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port, uriFormat);
4350  }
4351  array = Compress(array, basePart.SecuredPathIndex, ref num2, basePart.Syntax);
4352  return text2 + new string(array, 0, num2) + text3;
4353  }
4354 
4355  private static string PathDifference(string path1, string path2, bool compareCase)
4356  {
4357  int num = -1;
4358  int i;
4359  for (i = 0; i < path1.Length && i < path2.Length && (path1[i] == path2[i] || (!compareCase && char.ToLower(path1[i], CultureInfo.InvariantCulture) == char.ToLower(path2[i], CultureInfo.InvariantCulture))); i++)
4360  {
4361  if (path1[i] == '/')
4362  {
4363  num = i;
4364  }
4365  }
4366  if (i == 0)
4367  {
4368  return path2;
4369  }
4370  if (i == path1.Length && i == path2.Length)
4371  {
4372  return string.Empty;
4373  }
4374  StringBuilder stringBuilder = new StringBuilder();
4375  for (; i < path1.Length; i++)
4376  {
4377  if (path1[i] == '/')
4378  {
4379  stringBuilder.Append("../");
4380  }
4381  }
4382  if (stringBuilder.Length == 0 && path2.Length - 1 == num)
4383  {
4384  return "./";
4385  }
4386  return stringBuilder.ToString() + path2.Substring(num + 1);
4387  }
4388 
4389  private static bool IsLWS(char ch)
4390  {
4391  if (ch <= ' ')
4392  {
4393  if (ch != ' ' && ch != '\n' && ch != '\r')
4394  {
4395  return ch == '\t';
4396  }
4397  return true;
4398  }
4399  return false;
4400  }
4401 
4402  private static bool IsAsciiLetter(char character)
4403  {
4404  if (character < 'a' || character > 'z')
4405  {
4406  if (character >= 'A')
4407  {
4408  return character <= 'Z';
4409  }
4410  return false;
4411  }
4412  return true;
4413  }
4414 
4415  internal static bool IsAsciiLetterOrDigit(char character)
4416  {
4417  if (!IsAsciiLetter(character))
4418  {
4419  if (character >= '0')
4420  {
4421  return character <= '9';
4422  }
4423  return false;
4424  }
4425  return true;
4426  }
4427 
4428  internal static bool IsBidiControlCharacter(char ch)
4429  {
4430  if (ch != '\u200e' && ch != '\u200f' && ch != '\u202a' && ch != '\u202b' && ch != '\u202c' && ch != '\u202d')
4431  {
4432  return ch == '\u202e';
4433  }
4434  return true;
4435  }
4436 
4437  internal unsafe static string StripBidiControlCharacter(char* strToClean, int start, int length)
4438  {
4439  if (length <= 0)
4440  {
4441  return "";
4442  }
4443  char[] array = new char[length];
4444  int num = 0;
4445  for (int i = 0; i < length; i++)
4446  {
4447  char c = strToClean[start + i];
4448  if (c < '\u200e' || c > '\u202e' || !IsBidiControlCharacter(c))
4449  {
4450  array[num++] = c;
4451  }
4452  }
4453  return new string(array, 0, num);
4454  }
4455 
4462  [Obsolete("The method has been deprecated. Please use MakeRelativeUri(Uri uri). http://go.microsoft.com/fwlink/?linkid=14202")]
4463  public string MakeRelative(Uri toUri)
4464  {
4465  if ((object)toUri == null)
4466  {
4467  throw new ArgumentNullException("toUri");
4468  }
4469  if (IsNotAbsoluteUri || toUri.IsNotAbsoluteUri)
4470  {
4471  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
4472  }
4473  if (Scheme == toUri.Scheme && Host == toUri.Host && Port == toUri.Port)
4474  {
4475  return PathDifference(AbsolutePath, toUri.AbsolutePath, !IsUncOrDosPath);
4476  }
4477  return toUri.ToString();
4478  }
4479 
4482  [Obsolete("The method has been deprecated. It is not used by the system. http://go.microsoft.com/fwlink/?linkid=14202")]
4483  protected virtual void Parse()
4484  {
4485  }
4486 
4490  [Obsolete("The method has been deprecated. It is not used by the system. http://go.microsoft.com/fwlink/?linkid=14202")]
4491  protected virtual void Canonicalize()
4492  {
4493  }
4494 
4497  [Obsolete("The method has been deprecated. It is not used by the system. http://go.microsoft.com/fwlink/?linkid=14202")]
4498  protected virtual void Escape()
4499  {
4500  }
4501 
4505  [Obsolete("The method has been deprecated. Please use GetComponents() or static UnescapeDataString() to unescape a Uri component or a string. http://go.microsoft.com/fwlink/?linkid=14202")]
4506  protected virtual string Unescape(string path)
4507  {
4508  char[] dest = new char[path.Length];
4509  int destPosition = 0;
4510  dest = UriHelper.UnescapeString(path, 0, path.Length, dest, ref destPosition, '\uffff', '\uffff', '\uffff', UnescapeMode.Unescape | UnescapeMode.UnescapeAll, null, isQuery: false);
4511  return new string(dest, 0, destPosition);
4512  }
4513 
4517  [Obsolete("The method has been deprecated. Please use GetComponents() or static EscapeUriString() to escape a Uri component or a string. http://go.microsoft.com/fwlink/?linkid=14202")]
4518  protected static string EscapeString(string str)
4519  {
4520  if (str == null)
4521  {
4522  return string.Empty;
4523  }
4524  int destPos = 0;
4525  char[] array = UriHelper.EscapeString(str, 0, str.Length, null, ref destPos, isUriString: true, '?', '#', '%');
4526  if (array == null)
4527  {
4528  return str;
4529  }
4530  return new string(array, 0, destPos);
4531  }
4532 
4534  [Obsolete("The method has been deprecated. It is not used by the system. http://go.microsoft.com/fwlink/?linkid=14202")]
4535  protected virtual void CheckSecurity()
4536  {
4537  bool flag = Scheme == "telnet";
4538  }
4539 
4543  [Obsolete("The method has been deprecated. It is not used by the system. http://go.microsoft.com/fwlink/?linkid=14202")]
4544  protected virtual bool IsReservedCharacter(char character)
4545  {
4546  if (character != ';' && character != '/' && character != ':' && character != '@' && character != '&' && character != '=' && character != '+' && character != '$')
4547  {
4548  return character == ',';
4549  }
4550  return true;
4551  }
4552 
4556  [Obsolete("The method has been deprecated. It is not used by the system. http://go.microsoft.com/fwlink/?linkid=14202")]
4557  protected static bool IsExcludedCharacter(char character)
4558  {
4559  if (character > ' ' && character < '\u007f' && character != '<' && character != '>' && character != '#' && character != '%' && character != '"' && character != '{' && character != '}' && character != '|' && character != '\\' && character != '^' && character != '[' && character != ']')
4560  {
4561  return character == '`';
4562  }
4563  return true;
4564  }
4565 
4569  [Obsolete("The method has been deprecated. It is not used by the system. http://go.microsoft.com/fwlink/?linkid=14202")]
4570  protected virtual bool IsBadFileSystemCharacter(char character)
4571  {
4572  if (character >= ' ' && character != ';' && character != '/' && character != '?' && character != ':' && character != '&' && character != '=' && character != ',' && character != '*' && character != '<' && character != '>' && character != '"' && character != '|' && character != '\\')
4573  {
4574  return character == '^';
4575  }
4576  return true;
4577  }
4578 
4579  private void CreateThis(string uri, bool dontEscape, UriKind uriKind)
4580  {
4581  if (uriKind < UriKind.RelativeOrAbsolute || uriKind > UriKind.Relative)
4582  {
4583  throw new ArgumentException(SR.GetString("net_uri_InvalidUriKind", uriKind));
4584  }
4585  m_String = ((uri == null) ? string.Empty : uri);
4586  if (dontEscape)
4587  {
4588  m_Flags |= Flags.UserEscaped;
4589  }
4590  ParsingError err = ParseScheme(m_String, ref m_Flags, ref m_Syntax);
4591  InitializeUri(err, uriKind, out UriFormatException e);
4592  if (e != null)
4593  {
4594  throw e;
4595  }
4596  }
4597 
4598  private void InitializeUri(ParsingError err, UriKind uriKind, out UriFormatException e)
4599  {
4600  if (err == ParsingError.None)
4601  {
4602  if (IsImplicitFile)
4603  {
4604  if (NotAny(Flags.DosPath) && uriKind != UriKind.Absolute && (uriKind == UriKind.Relative || (m_String.Length >= 2 && (m_String[0] != '\\' || m_String[1] != '\\'))))
4605  {
4606  m_Syntax = null;
4607  m_Flags &= Flags.UserEscaped;
4608  e = null;
4609  return;
4610  }
4611  if (uriKind == UriKind.Relative && InFact(Flags.DosPath))
4612  {
4613  m_Syntax = null;
4614  m_Flags &= Flags.UserEscaped;
4615  e = null;
4616  return;
4617  }
4618  }
4619  }
4620  else if (err > ParsingError.EmptyUriString)
4621  {
4622  m_String = null;
4623  e = GetException(err);
4624  return;
4625  }
4626  bool flag = false;
4627  if (!s_ConfigInitialized && CheckForConfigLoad(m_String))
4628  {
4629  InitializeUriConfig();
4630  }
4631  m_iriParsing = (s_IriParsing && (m_Syntax == null || m_Syntax.InFact(UriSyntaxFlags.AllowIriParsing)));
4632  if (m_iriParsing && (CheckForUnicode(m_String) || CheckForEscapedUnreserved(m_String)))
4633  {
4634  m_Flags |= Flags.HasUnicode;
4635  flag = true;
4636  m_originalUnicodeString = m_String;
4637  }
4638  if (m_Syntax != null)
4639  {
4640  if (m_Syntax.IsSimple)
4641  {
4642  if ((err = PrivateParseMinimal()) != 0)
4643  {
4644  if (uriKind != UriKind.Absolute && err <= ParsingError.EmptyUriString)
4645  {
4646  m_Syntax = null;
4647  e = null;
4648  m_Flags &= Flags.UserEscaped;
4649  }
4650  else
4651  {
4652  e = GetException(err);
4653  }
4654  }
4655  else if (uriKind == UriKind.Relative)
4656  {
4657  e = GetException(ParsingError.CannotCreateRelative);
4658  }
4659  else
4660  {
4661  e = null;
4662  }
4663  if (m_iriParsing && flag)
4664  {
4665  EnsureParseRemaining();
4666  }
4667  return;
4668  }
4669  m_Syntax = m_Syntax.InternalOnNewUri();
4670  m_Flags |= Flags.UserDrivenParsing;
4671  m_Syntax.InternalValidate(this, out e);
4672  if (e != null)
4673  {
4674  if (uriKind != UriKind.Absolute && err != 0 && err <= ParsingError.EmptyUriString)
4675  {
4676  m_Syntax = null;
4677  e = null;
4678  m_Flags &= Flags.UserEscaped;
4679  }
4680  return;
4681  }
4682  if (err != 0 || InFact(Flags.ErrorOrParsingRecursion))
4683  {
4684  SetUserDrivenParsing();
4685  }
4686  else if (uriKind == UriKind.Relative)
4687  {
4688  e = GetException(ParsingError.CannotCreateRelative);
4689  }
4690  if (m_iriParsing && flag)
4691  {
4692  EnsureParseRemaining();
4693  }
4694  }
4695  else if (err != 0 && uriKind != UriKind.Absolute && err <= ParsingError.EmptyUriString)
4696  {
4697  e = null;
4698  m_Flags &= (Flags.UserEscaped | Flags.HasUnicode);
4699  if (m_iriParsing && flag)
4700  {
4701  m_String = EscapeUnescapeIri(m_originalUnicodeString, 0, m_originalUnicodeString.Length, (UriComponents)0);
4702  try
4703  {
4704  if (UriParser.ShouldUseLegacyV2Quirks)
4705  {
4706  m_String = m_String.Normalize(NormalizationForm.FormC);
4707  }
4708  }
4709  catch (ArgumentException)
4710  {
4711  e = GetException(ParsingError.BadFormat);
4712  }
4713  }
4714  }
4715  else
4716  {
4717  m_String = null;
4718  e = GetException(err);
4719  }
4720  }
4721 
4722  private unsafe bool CheckForConfigLoad(string data)
4723  {
4724  bool result = false;
4725  int length = data.Length;
4726  fixed (char* ptr = data)
4727  {
4728  for (int i = 0; i < length; i++)
4729  {
4730  if (ptr[i] > '\u007f' || ptr[i] == '%' || (ptr[i] == 'x' && i + 3 < length && ptr[i + 1] == 'n' && ptr[i + 2] == '-' && ptr[i + 3] == '-'))
4731  {
4732  result = true;
4733  break;
4734  }
4735  }
4736  }
4737  return result;
4738  }
4739 
4740  private bool CheckForUnicode(string data)
4741  {
4742  bool result = false;
4743  char[] dest = new char[data.Length];
4744  int destPosition = 0;
4745  dest = UriHelper.UnescapeString(data, 0, data.Length, dest, ref destPosition, '\uffff', '\uffff', '\uffff', UnescapeMode.Unescape | UnescapeMode.UnescapeAll, null, isQuery: false);
4746  for (int i = 0; i < destPosition; i++)
4747  {
4748  if (dest[i] > '\u007f')
4749  {
4750  result = true;
4751  break;
4752  }
4753  }
4754  return result;
4755  }
4756 
4757  private unsafe bool CheckForEscapedUnreserved(string data)
4758  {
4759  fixed (char* ptr = data)
4760  {
4761  for (int i = 0; i < data.Length - 2; i++)
4762  {
4763  if (ptr[i] == '%' && IsHexDigit(ptr[i + 1]) && IsHexDigit(ptr[i + 2]) && ptr[i + 1] >= '0' && ptr[i + 1] <= '7')
4764  {
4765  char c = UriHelper.EscapedAscii(ptr[i + 1], ptr[i + 2]);
4766  if (c != '\uffff' && UriHelper.Is3986Unreserved(c))
4767  {
4768  return true;
4769  }
4770  }
4771  }
4772  }
4773  return false;
4774  }
4775 
4781  [global::__DynamicallyInvokable]
4782  public static bool TryCreate(string uriString, UriKind uriKind, out Uri result)
4783  {
4784  if (uriString == null)
4785  {
4786  result = null;
4787  return false;
4788  }
4789  UriFormatException e = null;
4790  result = CreateHelper(uriString, dontEscape: false, uriKind, ref e);
4791  if (e == null)
4792  {
4793  return result != null;
4794  }
4795  return false;
4796  }
4797 
4803  [global::__DynamicallyInvokable]
4804  public static bool TryCreate(Uri baseUri, string relativeUri, out Uri result)
4805  {
4806  if (TryCreate(relativeUri, UriKind.RelativeOrAbsolute, out Uri result2))
4807  {
4808  if (!result2.IsAbsoluteUri)
4809  {
4810  return TryCreate(baseUri, result2, out result);
4811  }
4812  result = result2;
4813  return true;
4814  }
4815  result = null;
4816  return false;
4817  }
4818 
4826  [global::__DynamicallyInvokable]
4827  public static bool TryCreate(Uri baseUri, Uri relativeUri, out Uri result)
4828  {
4829  result = null;
4830  if ((object)baseUri == null || (object)relativeUri == null)
4831  {
4832  return false;
4833  }
4834  if (baseUri.IsNotAbsoluteUri)
4835  {
4836  return false;
4837  }
4838  string newUriString = null;
4839  bool userEscaped;
4841  if (baseUri.Syntax.IsSimple)
4842  {
4843  userEscaped = relativeUri.UserEscaped;
4844  result = ResolveHelper(baseUri, relativeUri, ref newUriString, ref userEscaped, out e);
4845  }
4846  else
4847  {
4848  userEscaped = false;
4849  newUriString = baseUri.Syntax.InternalResolve(baseUri, relativeUri, out e);
4850  }
4851  if (e != null)
4852  {
4853  return false;
4854  }
4855  if ((object)result == null)
4856  {
4857  result = CreateHelper(newUriString, userEscaped, UriKind.Absolute, ref e);
4858  }
4859  if (e == null && result != null)
4860  {
4861  return result.IsAbsoluteUri;
4862  }
4863  return false;
4864  }
4865 
4873  [global::__DynamicallyInvokable]
4874  public string GetComponents(UriComponents components, UriFormat format)
4875  {
4876  if ((components & UriComponents.SerializationInfoString) != 0 && components != UriComponents.SerializationInfoString)
4877  {
4878  throw new ArgumentOutOfRangeException("components", components, SR.GetString("net_uri_NotJustSerialization"));
4879  }
4880  if ((format & (UriFormat)(-4)) != 0)
4881  {
4882  throw new ArgumentOutOfRangeException("format");
4883  }
4884  if (IsNotAbsoluteUri)
4885  {
4886  if (components == UriComponents.SerializationInfoString)
4887  {
4888  return GetRelativeSerializationString(format);
4889  }
4890  throw new InvalidOperationException(SR.GetString("net_uri_NotAbsolute"));
4891  }
4892  if (Syntax.IsSimple)
4893  {
4894  return GetComponentsHelper(components, format);
4895  }
4896  return Syntax.InternalGetComponents(this, components, format);
4897  }
4898 
4911  [global::__DynamicallyInvokable]
4912  public static int Compare(Uri uri1, Uri uri2, UriComponents partsToCompare, UriFormat compareFormat, StringComparison comparisonType)
4913  {
4914  if ((object)uri1 == null)
4915  {
4916  if (uri2 == null)
4917  {
4918  return 0;
4919  }
4920  return -1;
4921  }
4922  if ((object)uri2 == null)
4923  {
4924  return 1;
4925  }
4926  if (!uri1.IsAbsoluteUri || !uri2.IsAbsoluteUri)
4927  {
4928  if (!uri1.IsAbsoluteUri)
4929  {
4930  if (!uri2.IsAbsoluteUri)
4931  {
4932  return string.Compare(uri1.OriginalString, uri2.OriginalString, comparisonType);
4933  }
4934  return -1;
4935  }
4936  return 1;
4937  }
4938  return string.Compare(uri1.GetParts(partsToCompare, compareFormat), uri2.GetParts(partsToCompare, compareFormat), comparisonType);
4939  }
4940 
4943  [global::__DynamicallyInvokable]
4945  {
4946  if (IsNotAbsoluteUri || Syntax.IsSimple)
4947  {
4948  return InternalIsWellFormedOriginalString();
4949  }
4950  return Syntax.InternalIsWellFormedOriginalString(this);
4951  }
4952 
4957  [global::__DynamicallyInvokable]
4958  public static bool IsWellFormedUriString(string uriString, UriKind uriKind)
4959  {
4960  if (!TryCreate(uriString, uriKind, out Uri result))
4961  {
4962  return false;
4963  }
4964  return result.IsWellFormedOriginalString();
4965  }
4966 
4967  internal unsafe bool InternalIsWellFormedOriginalString()
4968  {
4969  if (UserDrivenParsing)
4970  {
4971  throw new InvalidOperationException(SR.GetString("net_uri_UserDrivenParsing", GetType().FullName));
4972  }
4973  fixed (char* ptr = m_String)
4974  {
4975  ushort idx = 0;
4976  if (!IsAbsoluteUri)
4977  {
4978  if (!UriParser.ShouldUseLegacyV2Quirks && CheckForColonInFirstPathSegment(m_String))
4979  {
4980  return false;
4981  }
4982  return (CheckCanonical(ptr, ref idx, (ushort)m_String.Length, '\ufffe') & (Check.EscapedCanonical | Check.BackslashInPath)) == Check.EscapedCanonical;
4983  }
4984  if (IsImplicitFile)
4985  {
4986  return false;
4987  }
4988  EnsureParseRemaining();
4989  Flags flags = m_Flags & (Flags.E_UserNotCanonical | Flags.E_HostNotCanonical | Flags.E_PortNotCanonical | Flags.E_PathNotCanonical | Flags.E_QueryNotCanonical | Flags.E_FragmentNotCanonical | Flags.UserIriCanonical | Flags.PathIriCanonical | Flags.QueryIriCanonical | Flags.FragmentIriCanonical);
4990  if ((flags & Flags.E_CannotDisplayCanonical & (Flags.E_UserNotCanonical | Flags.E_PathNotCanonical | Flags.E_QueryNotCanonical | Flags.E_FragmentNotCanonical)) != Flags.Zero && (!m_iriParsing || (m_iriParsing && ((flags & Flags.E_UserNotCanonical) == Flags.Zero || (flags & Flags.UserIriCanonical) == Flags.Zero) && ((flags & Flags.E_PathNotCanonical) == Flags.Zero || (flags & Flags.PathIriCanonical) == Flags.Zero) && ((flags & Flags.E_QueryNotCanonical) == Flags.Zero || (flags & Flags.QueryIriCanonical) == Flags.Zero) && ((flags & Flags.E_FragmentNotCanonical) == Flags.Zero || (flags & Flags.FragmentIriCanonical) == Flags.Zero))))
4991  {
4992  return false;
4993  }
4994  if (InFact(Flags.AuthorityFound))
4995  {
4996  idx = (ushort)(m_Info.Offset.Scheme + m_Syntax.SchemeName.Length + 2);
4997  if (idx >= m_Info.Offset.User || m_String[idx - 1] == '\\' || m_String[idx] == '\\')
4998  {
4999  return false;
5000  }
5001  if (InFact(Flags.DosPath | Flags.UncPath) && (idx = (ushort)(idx + 1)) < m_Info.Offset.User && (m_String[idx] == '/' || m_String[idx] == '\\'))
5002  {
5003  return false;
5004  }
5005  }
5006  if (InFact(Flags.FirstSlashAbsent) && m_Info.Offset.Query > m_Info.Offset.Path)
5007  {
5008  return false;
5009  }
5010  if (InFact(Flags.BackslashInPath))
5011  {
5012  return false;
5013  }
5014  if (IsDosPath && m_String[m_Info.Offset.Path + SecuredPathIndex - 1] == '|')
5015  {
5016  return false;
5017  }
5018  if ((m_Flags & Flags.CanonicalDnsHost) == Flags.Zero && HostType != Flags.IPv6HostType)
5019  {
5020  idx = m_Info.Offset.User;
5021  Check check = CheckCanonical(ptr, ref idx, m_Info.Offset.Path, '/');
5022  if ((check & (Check.EscapedCanonical | Check.BackslashInPath | Check.ReservedFound)) != Check.EscapedCanonical && (!m_iriParsing || (m_iriParsing && (check & (Check.DisplayCanonical | Check.NotIriCanonical | Check.FoundNonAscii)) != (Check.DisplayCanonical | Check.FoundNonAscii))))
5023  {
5024  return false;
5025  }
5026  }
5027  if ((m_Flags & (Flags.SchemeNotCanonical | Flags.AuthorityFound)) == (Flags.SchemeNotCanonical | Flags.AuthorityFound))
5028  {
5029  idx = (ushort)m_Syntax.SchemeName.Length;
5030  char* intPtr;
5031  ushort num;
5032  do
5033  {
5034  intPtr = ptr;
5035  num = idx;
5036  idx = (ushort)(num + 1);
5037  }
5038  while (intPtr[(int)num] != ':');
5039  if (idx + 1 >= m_String.Length || ptr[(int)idx] != '/' || ptr[idx + 1] != '/')
5040  {
5041  return false;
5042  }
5043  }
5044  }
5045  return true;
5046  }
5047 
5053  [global::__DynamicallyInvokable]
5054  public unsafe static string UnescapeDataString(string stringToUnescape)
5055  {
5056  if (stringToUnescape == null)
5057  {
5058  throw new ArgumentNullException("stringToUnescape");
5059  }
5060  if (stringToUnescape.Length == 0)
5061  {
5062  return string.Empty;
5063  }
5064  fixed (char* ptr = stringToUnescape)
5065  {
5066  int i;
5067  for (i = 0; i < stringToUnescape.Length && ptr[i] != '%'; i++)
5068  {
5069  }
5070  if (i == stringToUnescape.Length)
5071  {
5072  return stringToUnescape;
5073  }
5074  UnescapeMode unescapeMode = UnescapeMode.Unescape | UnescapeMode.UnescapeAll;
5075  i = 0;
5076  char[] dest = new char[stringToUnescape.Length];
5077  dest = UriHelper.UnescapeString(stringToUnescape, 0, stringToUnescape.Length, dest, ref i, '\uffff', '\uffff', '\uffff', unescapeMode, null, isQuery: false);
5078  return new string(dest, 0, i);
5079  }
5080  }
5081 
5089  [global::__DynamicallyInvokable]
5090  public static string EscapeUriString(string stringToEscape)
5091  {
5092  if (stringToEscape == null)
5093  {
5094  throw new ArgumentNullException("stringToEscape");
5095  }
5096  if (stringToEscape.Length == 0)
5097  {
5098  return string.Empty;
5099  }
5100  int destPos = 0;
5101  char[] array = UriHelper.EscapeString(stringToEscape, 0, stringToEscape.Length, null, ref destPos, isUriString: true, '\uffff', '\uffff', '\uffff');
5102  if (array == null)
5103  {
5104  return stringToEscape;
5105  }
5106  return new string(array, 0, destPos);
5107  }
5108 
5116  [global::__DynamicallyInvokable]
5117  public static string EscapeDataString(string stringToEscape)
5118  {
5119  if (stringToEscape == null)
5120  {
5121  throw new ArgumentNullException("stringToEscape");
5122  }
5123  if (stringToEscape.Length == 0)
5124  {
5125  return string.Empty;
5126  }
5127  int destPos = 0;
5128  char[] array = UriHelper.EscapeString(stringToEscape, 0, stringToEscape.Length, null, ref destPos, isUriString: false, '\uffff', '\uffff', '\uffff');
5129  if (array == null)
5130  {
5131  return stringToEscape;
5132  }
5133  return new string(array, 0, destPos);
5134  }
5135 
5136  internal unsafe string EscapeUnescapeIri(string input, int start, int end, UriComponents component)
5137  {
5138  fixed (char* pInput = input)
5139  {
5140  return IriHelper.EscapeUnescapeIri(pInput, start, end, component);
5141  }
5142  }
5143 
5144  private Uri(Flags flags, UriParser uriParser, string uri)
5145  {
5146  m_Flags = flags;
5147  m_Syntax = uriParser;
5148  m_String = uri;
5149  }
5150 
5151  internal static Uri CreateHelper(string uriString, bool dontEscape, UriKind uriKind, ref UriFormatException e)
5152  {
5153  if (uriKind < UriKind.RelativeOrAbsolute || uriKind > UriKind.Relative)
5154  {
5155  throw new ArgumentException(SR.GetString("net_uri_InvalidUriKind", uriKind));
5156  }
5157  UriParser syntax = null;
5158  Flags flags = Flags.Zero;
5159  ParsingError parsingError = ParseScheme(uriString, ref flags, ref syntax);
5160  if (dontEscape)
5161  {
5162  flags |= Flags.UserEscaped;
5163  }
5164  if (parsingError != 0)
5165  {
5166  if (uriKind != UriKind.Absolute && parsingError <= ParsingError.EmptyUriString)
5167  {
5168  return new Uri(flags & Flags.UserEscaped, null, uriString);
5169  }
5170  return null;
5171  }
5172  Uri uri = new Uri(flags, syntax, uriString);
5173  try
5174  {
5175  uri.InitializeUri(parsingError, uriKind, out e);
5176  if (e == null)
5177  {
5178  return uri;
5179  }
5180  return null;
5181  }
5182  catch (UriFormatException ex)
5183  {
5184  UriFormatException ex2 = e = ex;
5185  return null;
5186  }
5187  }
5188 
5189  internal static Uri ResolveHelper(Uri baseUri, Uri relativeUri, ref string newUriString, ref bool userEscaped, out UriFormatException e)
5190  {
5191  e = null;
5192  string empty = string.Empty;
5193  if ((object)relativeUri != null)
5194  {
5195  if (relativeUri.IsAbsoluteUri)
5196  {
5197  return relativeUri;
5198  }
5199  empty = relativeUri.OriginalString;
5200  userEscaped = relativeUri.UserEscaped;
5201  }
5202  else
5203  {
5204  empty = string.Empty;
5205  }
5206  if (empty.Length > 0 && (IsLWS(empty[0]) || IsLWS(empty[empty.Length - 1])))
5207  {
5208  empty = empty.Trim(_WSchars);
5209  }
5210  if (empty.Length == 0)
5211  {
5212  newUriString = baseUri.GetParts(UriComponents.AbsoluteUri, baseUri.UserEscaped ? UriFormat.UriEscaped : UriFormat.SafeUnescaped);
5213  return null;
5214  }
5215  if (empty[0] == '#' && !baseUri.IsImplicitFile && baseUri.Syntax.InFact(UriSyntaxFlags.MayHaveFragment))
5216  {
5217  newUriString = baseUri.GetParts(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port | UriComponents.Path | UriComponents.Query, UriFormat.UriEscaped) + empty;
5218  return null;
5219  }
5220  if (empty[0] == '?' && !baseUri.IsImplicitFile && baseUri.Syntax.InFact(UriSyntaxFlags.MayHaveQuery))
5221  {
5222  newUriString = baseUri.GetParts(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port | UriComponents.Path, UriFormat.UriEscaped) + empty;
5223  return null;
5224  }
5225  if (empty.Length >= 3 && (empty[1] == ':' || empty[1] == '|') && IsAsciiLetter(empty[0]) && (empty[2] == '\\' || empty[2] == '/'))
5226  {
5227  if (baseUri.IsImplicitFile)
5228  {
5229  newUriString = empty;
5230  return null;
5231  }
5232  if (baseUri.Syntax.InFact(UriSyntaxFlags.AllowDOSPath))
5233  {
5234  newUriString = string.Concat(str1: (!baseUri.InFact(Flags.AuthorityFound)) ? (baseUri.Syntax.InFact(UriSyntaxFlags.PathIsRooted) ? ":/" : ":") : (baseUri.Syntax.InFact(UriSyntaxFlags.PathIsRooted) ? ":///" : "://"), str0: baseUri.Scheme, str2: empty);
5235  return null;
5236  }
5237  }
5238  ParsingError combinedString = GetCombinedString(baseUri, empty, userEscaped, ref newUriString);
5239  if (combinedString != 0)
5240  {
5241  e = GetException(combinedString);
5242  return null;
5243  }
5244  if ((object)newUriString == baseUri.m_String)
5245  {
5246  return baseUri;
5247  }
5248  return null;
5249  }
5250 
5251  private string GetRelativeSerializationString(UriFormat format)
5252  {
5253  switch (format)
5254  {
5255  case UriFormat.UriEscaped:
5256  {
5257  if (m_String.Length == 0)
5258  {
5259  return string.Empty;
5260  }
5261  int destPos = 0;
5262  char[] array = UriHelper.EscapeString(m_String, 0, m_String.Length, null, ref destPos, isUriString: true, '\uffff', '\uffff', '%');
5263  if (array == null)
5264  {
5265  return m_String;
5266  }
5267  return new string(array, 0, destPos);
5268  }
5269  case UriFormat.Unescaped:
5270  return UnescapeDataString(m_String);
5271  case UriFormat.SafeUnescaped:
5272  {
5273  if (m_String.Length == 0)
5274  {
5275  return string.Empty;
5276  }
5277  char[] dest = new char[m_String.Length];
5278  int destPosition = 0;
5279  dest = UriHelper.UnescapeString(m_String, 0, m_String.Length, dest, ref destPosition, '\uffff', '\uffff', '\uffff', UnescapeMode.EscapeUnescape, null, isQuery: false);
5280  return new string(dest, 0, destPosition);
5281  }
5282  default:
5283  throw new ArgumentOutOfRangeException("format");
5284  }
5285  }
5286 
5287  internal string GetComponentsHelper(UriComponents uriComponents, UriFormat uriFormat)
5288  {
5289  if (uriComponents == UriComponents.Scheme)
5290  {
5291  return m_Syntax.SchemeName;
5292  }
5293  if ((uriComponents & UriComponents.SerializationInfoString) != 0)
5294  {
5295  uriComponents |= UriComponents.AbsoluteUri;
5296  }
5297  EnsureParseRemaining();
5298  if ((uriComponents & UriComponents.NormalizedHost) != 0)
5299  {
5300  uriComponents |= UriComponents.Host;
5301  }
5302  if ((uriComponents & UriComponents.Host) != 0)
5303  {
5304  EnsureHostString(allowDnsOptimization: true);
5305  }
5306  if (uriComponents == UriComponents.Port || uriComponents == UriComponents.StrongPort)
5307  {
5308  if ((m_Flags & Flags.NotDefaultPort) != Flags.Zero || (uriComponents == UriComponents.StrongPort && m_Syntax.DefaultPort != -1))
5309  {
5310  return m_Info.Offset.PortValue.ToString(CultureInfo.InvariantCulture);
5311  }
5312  return string.Empty;
5313  }
5314  if ((uriComponents & UriComponents.StrongPort) != 0)
5315  {
5316  uriComponents |= UriComponents.Port;
5317  }
5318  if (uriComponents == UriComponents.Host && (uriFormat == UriFormat.UriEscaped || (m_Flags & (Flags.HostNotCanonical | Flags.E_HostNotCanonical)) == Flags.Zero))
5319  {
5320  EnsureHostString(allowDnsOptimization: false);
5321  return m_Info.Host;
5322  }
5323  switch (uriFormat)
5324  {
5325  case UriFormat.UriEscaped:
5326  return GetEscapedParts(uriComponents);
5327  case UriFormat.Unescaped:
5328  case UriFormat.SafeUnescaped:
5329  case (UriFormat)32767:
5330  return GetUnescapedParts(uriComponents, uriFormat);
5331  default:
5332  throw new ArgumentOutOfRangeException("uriFormat");
5333  }
5334  }
5335 
5342  [global::__DynamicallyInvokable]
5343  public bool IsBaseOf(Uri uri)
5344  {
5345  if ((object)uri == null)
5346  {
5347  throw new ArgumentNullException("uri");
5348  }
5349  if (!IsAbsoluteUri)
5350  {
5351  return false;
5352  }
5353  if (Syntax.IsSimple)
5354  {
5355  return IsBaseOfHelper(uri);
5356  }
5357  return Syntax.InternalIsBaseOf(this, uri);
5358  }
5359 
5360  internal unsafe bool IsBaseOfHelper(Uri uriLink)
5361  {
5362  if (!IsAbsoluteUri || UserDrivenParsing)
5363  {
5364  return false;
5365  }
5366  if (!uriLink.IsAbsoluteUri)
5367  {
5368  string newUriString = null;
5369  bool userEscaped = false;
5370  uriLink = ResolveHelper(this, uriLink, ref newUriString, ref userEscaped, out UriFormatException e);
5371  if (e != null)
5372  {
5373  return false;
5374  }
5375  if ((object)uriLink == null)
5376  {
5377  uriLink = CreateHelper(newUriString, userEscaped, UriKind.Absolute, ref e);
5378  }
5379  if (e != null)
5380  {
5381  return false;
5382  }
5383  }
5384  if (Syntax.SchemeName != uriLink.Syntax.SchemeName)
5385  {
5386  return false;
5387  }
5388  string parts = GetParts(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port | UriComponents.Path | UriComponents.Query, UriFormat.SafeUnescaped);
5389  string parts2 = uriLink.GetParts(UriComponents.Scheme | UriComponents.UserInfo | UriComponents.Host | UriComponents.Port | UriComponents.Path | UriComponents.Query, UriFormat.SafeUnescaped);
5390  fixed (char* pMe = parts)
5391  {
5392  fixed (char* pShe = parts2)
5393  {
5394  return UriHelper.TestForSubPath(pMe, (ushort)parts.Length, pShe, (ushort)parts2.Length, IsUncOrDosPath || uriLink.IsUncOrDosPath);
5395  }
5396  }
5397  }
5398 
5399  private void CreateThisFromUri(Uri otherUri)
5400  {
5401  m_Info = null;
5402  m_Flags = otherUri.m_Flags;
5403  if (InFact(Flags.MinimalUriInfoSet))
5404  {
5405  m_Flags &= ~(Flags.SchemeNotCanonical | Flags.UserNotCanonical | Flags.HostNotCanonical | Flags.PortNotCanonical | Flags.PathNotCanonical | Flags.QueryNotCanonical | Flags.FragmentNotCanonical | Flags.E_UserNotCanonical | Flags.E_HostNotCanonical | Flags.E_PortNotCanonical | Flags.E_PathNotCanonical | Flags.E_QueryNotCanonical | Flags.E_FragmentNotCanonical | Flags.ShouldBeCompressed | Flags.FirstSlashAbsent | Flags.BackslashInPath | Flags.MinimalUriInfoSet | Flags.AllUriInfoSet);
5406  int num = otherUri.m_Info.Offset.Path;
5407  if (InFact(Flags.NotDefaultPort))
5408  {
5409  while (otherUri.m_String[num] != ':' && num > otherUri.m_Info.Offset.Host)
5410  {
5411  num--;
5412  }
5413  if (otherUri.m_String[num] != ':')
5414  {
5415  num = otherUri.m_Info.Offset.Path;
5416  }
5417  }
5418  m_Flags |= (Flags)num;
5419  }
5420  m_Syntax = otherUri.m_Syntax;
5421  m_String = otherUri.m_String;
5422  m_iriParsing = otherUri.m_iriParsing;
5423  if (otherUri.OriginalStringSwitched)
5424  {
5425  m_originalUnicodeString = otherUri.m_originalUnicodeString;
5426  }
5427  if (otherUri.AllowIdn && (otherUri.InFact(Flags.IdnHost) || otherUri.InFact(Flags.UnicodeHost)))
5428  {
5429  m_DnsSafeHost = otherUri.m_DnsSafeHost;
5430  }
5431  }
5432  }
5433 }
UriKind
Defines the kinds of T:System.Uris for the M:System.Uri.IsWellFormedUriString(System....
Definition: UriKind.cs:5
static CultureInfo InvariantCulture
Gets the T:System.Globalization.CultureInfo object that is culture-independent (invariant).
Definition: CultureInfo.cs:263
static unsafe string UnescapeDataString(string stringToUnescape)
Converts a string to its unescaped representation.
Definition: Uri.cs:5054
static readonly string UriSchemeGopher
Specifies that the URI is accessed through the Gopher protocol. This field is read-only.
Definition: Uri.cs:151
int Port
Gets the port number of this URI.
Definition: Uri.cs:617
The P:System.Uri.LocalPath and P:System.Uri.Query data. Also see P:System.Uri.PathAndQuery.
bool UserEscaped
Indicates that the URI string was completely escaped before the T:System.Uri instance was created.
Definition: Uri.cs:832
The exception that is thrown when a null reference (Nothing in Visual Basic) is passed to a method th...
static bool IsHexEncoding(string pattern, int index)
Determines whether a character in a string is hexadecimal encoded.
Definition: Uri.cs:1550
Describes a set of security permissions applied to code. This class cannot be inherited.
static bool operator !=(Uri uri1, Uri uri2)
Determines whether two T:System.Uri instances do not have the same value.
Definition: Uri.cs:1713
UriHostNameType
Defines host name types for the M:System.Uri.CheckHostName(System.String) method.
Represents text as a sequence of UTF-16 code units.To browse the .NET Framework source code for this ...
Definition: String.cs:18
static readonly string UriSchemeHttp
Specifies that the URI is accessed through the Hypertext Transfer Protocol (HTTP)....
Definition: Uri.cs:154
Uri MakeRelativeUri(Uri uri)
Determines the difference between two T:System.Uri instances.
Definition: Uri.cs:1900
Uri(string uriString)
Initializes a new instance of the T:System.Uri class with the specified URI.
Definition: Uri.cs:1013
StringComparison
Specifies the culture, case, and sort rules to be used by certain overloads of the M:System....
static readonly string UriSchemeNetTcp
Specifies that the URI is accessed through the NetTcp scheme used by Windows Communication Foundation...
Definition: Uri.cs:173
The P:System.Uri.Fragment data.
static string EscapeUriString(string stringToEscape)
Converts a URI string to its escaped representation.
Definition: Uri.cs:5090
static char HexUnescape(string pattern, ref int index)
Converts a specified hexadecimal representation of a character to the character.
Definition: Uri.cs:1528
void GetObjectData(SerializationInfo serializationInfo, StreamingContext streamingContext)
Returns the data needed to serialize the current instance.
Definition: Uri.cs:1308
string AbsoluteUri
Gets the absolute URI.
Definition: Uri.cs:344
LayoutKind
Controls the layout of an object when exported to unmanaged code.
Definition: LayoutKind.cs:7
The scheme and authority segments of the URI.
bool IsWellFormedOriginalString()
Indicates whether the string used to construct this T:System.Uri was well-formed and is not required ...
Definition: Uri.cs:4944
Definition: __Canon.cs:3
string Scheme
Gets the scheme name for this URI.
Definition: Uri.cs:702
The exception that is thrown when the value of an argument is outside the allowable range of values a...
static readonly string UriSchemeFtp
Specifies that the URI is accessed through the File Transfer Protocol (FTP). This field is read-only.
Definition: Uri.cs:148
static bool IsWellFormedUriString(string uriString, UriKind uriKind)
Indicates whether the string is well-formed by attempting to construct a URI with the string and ensu...
Definition: Uri.cs:4958
static readonly string UriSchemeNews
Specifies that the URI is an Internet news group and is accessed through the Network News Transport P...
Definition: Uri.cs:167
The exception that is thrown when an unrecognized HRESULT is returned from a COM method call.
Definition: COMException.cs:12
Uri(string uriString, UriKind uriKind)
Initializes a new instance of the T:System.Uri class with the specified URI. This constructor allows ...
Definition: Uri.cs:1079
Describes the source and destination of a given serialized stream, and provides an additional caller-...
override int GetHashCode()
Gets the hash code for the URI.
Definition: Uri.cs:1630
static readonly string UriSchemeMailto
Specifies that the URI is an e-mail address and is accessed through the Simple Mail Transport Protoco...
Definition: Uri.cs:164
static bool TryCreate(string uriString, UriKind uriKind, out Uri result)
Creates a new T:System.Uri using the specified T:System.String instance and a T:System....
Definition: Uri.cs:4782
string DnsSafeHost
Gets an unescaped host name that is safe to use for DNS resolution.
Definition: Uri.cs:756
UriComponents
Specifies the parts of a T:System.Uri.
Definition: UriComponents.cs:6
The P:System.Uri.UserInfo data.
The environment variable is stored or retrieved from the HKEY_CURRENT_USER\Environment key in the Win...
The P:System.Uri.Host data.
The exception thrown when an invalid COM object is used.
Uri(Uri baseUri, Uri relativeUri)
Initializes a new instance of the T:System.Uri class based on the combination of a specified base T:S...
Definition: Uri.cs:1158
Uri(Uri baseUri, string relativeUri, bool dontEscape)
Initializes a new instance of the T:System.Uri class based on the specified base and relative URIs,...
Definition: Uri.cs:1052
bool IsAbsoluteUri
Gets whether the T:System.Uri instance is absolute.
Definition: Uri.cs:820
SecurityAction
Specifies the security actions that can be performed using declarative security.
string AbsolutePath
Gets the absolute path of the URI.
Definition: Uri.cs:303
void AddValue(string name, object value, Type type)
Adds a value into the T:System.Runtime.Serialization.SerializationInfo store, where value is associa...
bool IsBaseOf(Uri uri)
Determines whether the current T:System.Uri instance is a base of the specified T:System....
Definition: Uri.cs:5343
Uri(SerializationInfo serializationInfo, StreamingContext streamingContext)
Initializes a new instance of the T:System.Uri class from the specified instances of the T:System....
Definition: Uri.cs:1279
virtual bool IsBadFileSystemCharacter(char character)
Gets whether a character is invalid in a file system name.
Definition: Uri.cs:4570
static unsafe UriHostNameType CheckHostName(string name)
Determines whether the specified host name is a valid DNS name.
Definition: Uri.cs:1431
NormalizationForm
Defines the type of normalization to perform.
static readonly string UriSchemeNntp
Specifies that the URI is an Internet news group and is accessed through the Network News Transport P...
Definition: Uri.cs:170
UriPartial
Defines the parts of a URI for the M:System.Uri.GetLeftPart(System.UriPartial) method.
Definition: UriPartial.cs:4
static int CompareExchange(ref int location1, int value, int comparand)
Compares two 32-bit signed integers for equality and, if they are equal, replaces the first value.
static bool TryCreate(Uri baseUri, Uri relativeUri, out Uri result)
Creates a new T:System.Uri using the specified base and relative T:System.Uri instances.
Definition: Uri.cs:4827
string Query
Gets any query information included in the specified URI.
Definition: Uri.cs:646
unsafe override bool Equals(object comparand)
Compares two T:System.Uri instances for equality.
Definition: Uri.cs:1731
static string EscapeDataString(string stringToEscape)
Converts a string to its escaped representation.
Definition: Uri.cs:5117
string GetLeftPart(UriPartial part)
Gets the specified portion of a T:System.Uri instance.
Definition: Uri.cs:1479
The P:System.Uri.Scheme data.
string OriginalString
Gets the original URI string that was passed to the T:System.Uri constructor.
Definition: Uri.cs:739
GenericUriParserOptions
Specifies options for a T:System.UriParser.
string GetComponents(UriComponents components, UriFormat format)
Gets the specified components of the current instance using the specified escaping for special charac...
Definition: Uri.cs:4874
Stores all the data needed to serialize or deserialize an object. This class cannot be inherited.
static readonly string UriSchemeFile
Specifies that the URI is a pointer to a file. This field is read-only.
Definition: Uri.cs:145
virtual int Add(object value)
Adds an object to the end of the T:System.Collections.ArrayList.
Definition: ArrayList.cs:2381
static int Compare(Uri uri1, Uri uri2, UriComponents partsToCompare, UriFormat compareFormat, StringComparison comparisonType)
Compares the specified parts of two URIs using the specified comparison rules.
Definition: Uri.cs:4912
The exception that is thrown when one of the arguments provided to a method is not valid.
UriFormat
Controls how URI information is escaped.
Definition: UriFormat.cs:5
Allows an object to control its own serialization and deserialization.
Definition: ISerializable.cs:8
static readonly string UriSchemeNetPipe
Specifies that the URI is accessed through the NetPipe scheme used by Windows Communication Foundatio...
Definition: Uri.cs:176
static string HexEscape(char character)
Converts a specified character into its hexadecimal equivalent.
Definition: Uri.cs:1510
The P:System.Uri.Port data.
string GetString(string name)
Retrieves a T:System.String value from the T:System.Runtime.Serialization.SerializationInfo store.
string Fragment
Gets the escaped URI fragment.
Definition: Uri.cs:674
Uri(Uri baseUri, string relativeUri)
Initializes a new instance of the T:System.Uri class based on the specified base URI and relative URI...
Definition: Uri.cs:1098
Specifies that the class can be serialized.
static bool IsHexDigit(char character)
Determines whether a specified character is a valid hexadecimal digit.
Definition: Uri.cs:1595
virtual int ErrorCode
Gets the HRESULT of the error.
The exception that is thrown when a method call is invalid for the object's current state.
static readonly string SchemeDelimiter
Specifies the characters that separate the communication protocol scheme from the address portion of ...
Definition: Uri.cs:179
string IdnHost
The RFC 3490 compliant International Domain Name of the host, using Punycode as appropriate.
Definition: Uri.cs:803
static bool CheckSchemeName(string schemeName)
Determines whether the specified scheme name is valid.
Definition: Uri.cs:1576
Uri(string uriString, bool dontEscape)
Initializes a new instance of the T:System.Uri class with the specified URI, with explicit control of...
Definition: Uri.cs:1032
Provides information about a specific culture (called a locale for unmanaged code development)....
Definition: CultureInfo.cs:16
static bool TryCreate(Uri baseUri, string relativeUri, out Uri result)
Creates a new T:System.Uri using the specified base and relative T:System.String instances.
Definition: Uri.cs:4804
SecurityPermissionFlag
Specifies access flags for the security permission object.
Provides an object representation of a uniform resource identifier (URI) and easy access to the parts...
Definition: Uri.cs:19
The P:System.Uri.Query data.
static readonly string UriSchemeHttps
Specifies that the URI is accessed through the Secure Hypertext Transfer Protocol (HTTPS)....
Definition: Uri.cs:157
Compresses the underlying stream.
static int FromHex(char digit)
Gets the decimal value of a hexadecimal digit.
Definition: Uri.cs:1613
UriIdnScope
Provides the possible values for the configuration setting of the T:System.Configuration....
Definition: UriIdnScope.cs:4
Parses a new URI scheme. This is an abstract class.
Definition: UriParser.cs:9
void GetObjectData(SerializationInfo info, StreamingContext context)
Populates a T:System.Runtime.Serialization.SerializationInfo with the data needed to serialize the ta...
string Host
Gets the host component of this instance.
Definition: Uri.cs:587
Provides atomic operations for variables that are shared by multiple threads.
Definition: Interlocked.cs:10
The P:System.Uri.LocalPath data.
override string ToString()
Gets a canonical string representation for the specified T:System.Uri instance.
Definition: Uri.cs:1663
Provides a unified way of converting types of values to other types, as well as for accessing standar...
The P:System.Uri.Scheme, P:System.Uri.UserInfo, P:System.Uri.Host, P:System.Uri.Port,...
virtual object [] ToArray()
Copies the elements of the T:System.Collections.ArrayList to a new T:System.Object array.
Definition: ArrayList.cs:3083
The exception that is thrown when an invalid Uniform Resource Identifier (URI) is detected.
Implements the T:System.Collections.IList interface using an array whose size is dynamically increase...
Definition: ArrayList.cs:14