Code:
/ WCF / WCF / 3.5.30729.1 / untmp / Orcas / SP / ndp / cdf / src / NetFx35 / System.ServiceModel.Web / System / UriTemplateLiteralPathSegment.cs / 2 / UriTemplateLiteralPathSegment.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System { using System.Collections.Specialized; using System.ServiceModel; using System.ServiceModel.Web; using System.Text; // thin wrapper around string; use type system to help ensure we // are doing canonicalization right/consistently class UriTemplateLiteralPathSegment : UriTemplatePathSegment, IComparable{ // segment doesn't store trailing slash readonly string segment; static Uri dummyUri = new Uri("http://localhost"); UriTemplateLiteralPathSegment(string segment) : base(segment, UriTemplatePartType.Literal, segment.EndsWith("/", StringComparison.Ordinal)) { Fx.Assert(segment != null, "bad literal segment"); if (this.EndsWithSlash) { this.segment = segment.Remove(segment.Length - 1); } else { this.segment = segment; } } public static new UriTemplateLiteralPathSegment CreateFromUriTemplate(string segment, UriTemplate template) { // run it through UriBuilder to escape-if-necessary it if (string.Compare(segment, "/", StringComparison.Ordinal) == 0) { // running an empty segment through UriBuilder has unexpected/wrong results return new UriTemplateLiteralPathSegment("/"); } if (segment.IndexOf(UriTemplate.WildcardPath, StringComparison.Ordinal) != -1) { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new FormatException( SR2.GetString(SR2.UTInvalidWildcardInVariableOrLiteral, template.originalTemplate, UriTemplate.WildcardPath))); } // '*' is not usually escaped by the Uri\UriBuilder to %2a, since we forbid passing a // clear character and the workaroud is to pass the escaped form, we should replace the // escaped form with the regular one. segment = segment.Replace("%2a", "*").Replace("%2A", "*"); UriBuilder ub = new UriBuilder(dummyUri); ub.Path = segment; string escapedIfNecessarySegment = ub.Uri.AbsolutePath.Substring(1); if (escapedIfNecessarySegment == string.Empty) { // This path through UriBuilder will sometimes consume various segments // such as '../' and './'. When this happens and the result is an empty // string, we should just throw and tell the user we don't handle that. throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgument("segment", SR2.GetString(SR2.UTInvalidFormatSegmentOrQueryPart, segment)); } return new UriTemplateLiteralPathSegment(escapedIfNecessarySegment); } public static UriTemplateLiteralPathSegment CreateFromWireData(string segment) { return new UriTemplateLiteralPathSegment(segment); } public string AsUnescapedString() { Fx.Assert(this.segment != null, "this should only be called by Bind\\Lookup"); return Uri.UnescapeDataString(this.segment); } public override void Bind(string[] values, ref int valueIndex, StringBuilder path) { if (this.EndsWithSlash) { path.AppendFormat("{0}/", AsUnescapedString()); } else { path.Append(AsUnescapedString()); } } public int CompareTo(UriTemplateLiteralPathSegment other) { return StringComparer.OrdinalIgnoreCase.Compare(this.segment, other.segment); } public override bool Equals(object obj) { UriTemplateLiteralPathSegment lps = obj as UriTemplateLiteralPathSegment; if (lps == null) { Fx.Assert("why would we ever call this?"); return false; } else { return ((this.EndsWithSlash == lps.EndsWithSlash) && StringComparer.OrdinalIgnoreCase.Equals(this.segment, lps.segment)); } } public override int GetHashCode() { return StringComparer.OrdinalIgnoreCase.GetHashCode(this.segment); } public override bool IsEquivalentTo(UriTemplatePathSegment other, bool ignoreTrailingSlash) { if (other == null) { Fx.Assert("why would we ever call this?"); return false; } if (other.Nature != UriTemplatePartType.Literal) { return false; } UriTemplateLiteralPathSegment otherAsLiteral = other as UriTemplateLiteralPathSegment; Fx.Assert(otherAsLiteral != null, "The nature requires that this will be OK"); return IsMatch(otherAsLiteral, ignoreTrailingSlash); } public override bool IsMatch(UriTemplateLiteralPathSegment segment, bool ignoreTrailingSlash) { if (!ignoreTrailingSlash && (segment.EndsWithSlash != this.EndsWithSlash)) { return false; } return (CompareTo(segment) == 0); } public bool IsNullOrEmpty() { return string.IsNullOrEmpty(this.segment); } public override void Lookup(string segment, NameValueCollection boundParameters) { Fx.Assert(StringComparer.OrdinalIgnoreCase.Compare(AsUnescapedString(), segment) == 0, "How can that be? Lookup is expected to be called after IsMatch"); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PointAnimationBase.cs
- ConfigurationStrings.cs
- InkCanvasSelectionAdorner.cs
- BufferModesCollection.cs
- WebPartRestoreVerb.cs
- CheckStoreFileValidityRequest.cs
- AutomationProperties.cs
- DataColumnPropertyDescriptor.cs
- CodeGenerator.cs
- WsatServiceAddress.cs
- AddingNewEventArgs.cs
- WebPartCatalogCloseVerb.cs
- XmlMapping.cs
- SortQueryOperator.cs
- PermissionSetTriple.cs
- WeakEventTable.cs
- TypeConverterValueSerializer.cs
- TypeBuilder.cs
- InvokeProviderWrapper.cs
- BitmapFrameEncode.cs
- XamlToRtfParser.cs
- ProtectedConfigurationSection.cs
- Pen.cs
- TagNameToTypeMapper.cs
- RangeBaseAutomationPeer.cs
- VersionedStreamOwner.cs
- Encoding.cs
- ExpressionBinding.cs
- ConnectivityStatus.cs
- PtsHelper.cs
- ChannelCacheDefaults.cs
- UrlAuthorizationModule.cs
- CompModSwitches.cs
- MessageQuerySet.cs
- SoundPlayerAction.cs
- ValidationSummary.cs
- ServiceOperationListItem.cs
- relpropertyhelper.cs
- sqlnorm.cs
- BindingCompleteEventArgs.cs
- Directory.cs
- XmlImplementation.cs
- SwitchExpression.cs
- DatasetMethodGenerator.cs
- ImageDrawing.cs
- NamespaceInfo.cs
- UIElement3DAutomationPeer.cs
- TransformationRules.cs
- PropertyDescriptorGridEntry.cs
- ScriptDescriptor.cs
- WindowProviderWrapper.cs
- ADMembershipProvider.cs
- LockCookie.cs
- UnmanagedHandle.cs
- KeyConverter.cs
- SchemaLookupTable.cs
- DataRelationPropertyDescriptor.cs
- BindingGroup.cs
- unsafenativemethodstextservices.cs
- ThicknessKeyFrameCollection.cs
- SHA1Managed.cs
- PixelFormat.cs
- Type.cs
- HtmlPanelAdapter.cs
- AutoGeneratedField.cs
- CustomValidator.cs
- CodeGenerator.cs
- LinqDataSourceSelectEventArgs.cs
- DrawingCollection.cs
- FixedDocument.cs
- XPathDescendantIterator.cs
- ErrorInfoXmlDocument.cs
- SoapSchemaMember.cs
- UnitySerializationHolder.cs
- ISAPIRuntime.cs
- WebPartConnectionsConfigureVerb.cs
- ProjectionCamera.cs
- UnsafeNativeMethods.cs
- PnrpPermission.cs
- SqlPersonalizationProvider.cs
- HandlerBase.cs
- UnsafeNativeMethodsMilCoreApi.cs
- StaticFileHandler.cs
- BuilderElements.cs
- ServiceModelEnumValidator.cs
- SecurityTokenAuthenticator.cs
- OdbcDataReader.cs
- ExpanderAutomationPeer.cs
- RepeaterItemCollection.cs
- MemberProjectionIndex.cs
- _ListenerResponseStream.cs
- DataServicePagingProviderWrapper.cs
- DecimalFormatter.cs
- RelationshipEntry.cs
- XmlIterators.cs
- DynamicDocumentPaginator.cs
- SplitContainerDesigner.cs
- ListControl.cs
- RefreshEventArgs.cs
- PrimitiveXmlSerializers.cs