internal void InternalValidate(Uri thisUri, out UriFormatException?parsingError) { thisUri.DebugAssertInCtor(); InitializeAndValidate(thisUri, out parsingError); // InitializeAndValidate should not be called outside of the constructor Debug.Assert(sizeof(Uri.Flags) == sizeof(ulong)); Interlocked.Or(ref Unsafe.As <Uri.Flags, ulong>(ref thisUri._flags), (ulong)Uri.Flags.CustomParser_ParseMinimalAlreadyCalled); }
// // Parses and validates a Uri object, is called at the Uri ctor time. // // This method returns a non null parsingError if Uri being created is invalid: // protected virtual void InitializeAndValidate(Uri uri, out UriFormatException?parsingError) { if (uri._syntax is null) { throw new InvalidOperationException(SR.net_uri_NotAbsolute); } if (!ReferenceEquals(uri._syntax, this)) { throw new InvalidOperationException(SR.Format(SR.net_uri_UserDrivenParsing, uri._syntax.GetType())); } Debug.Assert(sizeof(Uri.Flags) == sizeof(ulong)); // If ParseMinimal is called multiple times this Uri instance may be corrupted, throw an exception instead ulong previous = Interlocked.Or(ref Unsafe.As <Uri.Flags, ulong>(ref uri._flags), (ulong)Uri.Flags.CustomParser_ParseMinimalAlreadyCalled); if (((Uri.Flags)previous & Uri.Flags.CustomParser_ParseMinimalAlreadyCalled) != 0) { throw new InvalidOperationException(SR.net_uri_InitializeCalledAlreadyOrTooLate); } parsingError = uri.ParseMinimal(); }