Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Shared / System / Windows / Media / TypeConverterHelper.cs / 1 / TypeConverterHelper.cs
//------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, All rights reserved. // // File: TypeConverterHelper.cs // //----------------------------------------------------------------------------- using System; using System.Diagnostics; using System.ComponentModel; using System.Windows.Markup; using System.Runtime.InteropServices; using System.Windows.Navigation; namespace System.Windows.Media { #region UriHolder ////// UriHolder /// Holds Original and Base Uris /// [StructLayout(LayoutKind.Sequential, Pack=1)] internal struct UriHolder { ////// BaseUri /// internal Uri BaseUri; ///Can be null ////// OriginalUri /// internal Uri OriginalUri; }; #endregion #region TypeConverterHelper ////// This helper method is used primarily by type converters to resolve their uri /// ////// There are three scenarios that can happen: /// /// 1) inputString is an absolute uri -- we return it as the resolvedUri /// 2) inputString is not absolute: /// i) the relativeBaseUri (obtained from IUriContext) has the following values: /// a) is an absolute uri, we use relativeBaseUri as base uri and resolve /// the inputString against it /// /// b) is a relative uri, we use Application's base uri (obtained from /// BindUriHelperCore.BaseUri) as the base and resolve the relativeBaseUri /// against it; furthermore, we resolve the inputString against with uri /// obtained from the application base resolution. /// /// c) is "", we resolve inputString against the Application's base uri /// internal static class TypeConverterHelper { internal static UriHolder GetUriFromUriContext(ITypeDescriptorContext context, object inputString) { UriHolder uriHolder = new UriHolder(); if (inputString is string) { uriHolder.OriginalUri = new Uri((string)inputString, UriKind.RelativeOrAbsolute); } else { Debug.Assert(inputString is Uri); uriHolder.OriginalUri = (Uri)inputString; } if (uriHolder.OriginalUri.IsAbsoluteUri == false) { //Debug.Assert (context != null, "Context should not be null"); if (context != null) { IUriContext iuc = (IUriContext)context.GetService(typeof(IUriContext)); //Debug.Assert (iuc != null, "IUriContext should not be null here"); if (iuc != null) { // the base uri is NOT "" if (iuc.BaseUri != null) { uriHolder.BaseUri = iuc.BaseUri; if (!uriHolder.BaseUri.IsAbsoluteUri) { uriHolder.BaseUri = new Uri(BaseUriHelper.BaseUri, uriHolder.BaseUri); } } // uriHolder.BaseUriString != "" else { // if we reach here, the base uri we got from IUriContext is "" // and the inputString is a relative uri. Here we resolve it to // application's base uriHolder.BaseUri = BaseUriHelper.BaseUri; } } // iuc != null } // context!= null } // uriHolder.OriginalUri.IsAbsoluteUri == false return uriHolder; } } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, All rights reserved. // // File: TypeConverterHelper.cs // //----------------------------------------------------------------------------- using System; using System.Diagnostics; using System.ComponentModel; using System.Windows.Markup; using System.Runtime.InteropServices; using System.Windows.Navigation; namespace System.Windows.Media { #region UriHolder ////// UriHolder /// Holds Original and Base Uris /// [StructLayout(LayoutKind.Sequential, Pack=1)] internal struct UriHolder { ////// BaseUri /// internal Uri BaseUri; ///Can be null ////// OriginalUri /// internal Uri OriginalUri; }; #endregion #region TypeConverterHelper ////// This helper method is used primarily by type converters to resolve their uri /// ////// There are three scenarios that can happen: /// /// 1) inputString is an absolute uri -- we return it as the resolvedUri /// 2) inputString is not absolute: /// i) the relativeBaseUri (obtained from IUriContext) has the following values: /// a) is an absolute uri, we use relativeBaseUri as base uri and resolve /// the inputString against it /// /// b) is a relative uri, we use Application's base uri (obtained from /// BindUriHelperCore.BaseUri) as the base and resolve the relativeBaseUri /// against it; furthermore, we resolve the inputString against with uri /// obtained from the application base resolution. /// /// c) is "", we resolve inputString against the Application's base uri /// internal static class TypeConverterHelper { internal static UriHolder GetUriFromUriContext(ITypeDescriptorContext context, object inputString) { UriHolder uriHolder = new UriHolder(); if (inputString is string) { uriHolder.OriginalUri = new Uri((string)inputString, UriKind.RelativeOrAbsolute); } else { Debug.Assert(inputString is Uri); uriHolder.OriginalUri = (Uri)inputString; } if (uriHolder.OriginalUri.IsAbsoluteUri == false) { //Debug.Assert (context != null, "Context should not be null"); if (context != null) { IUriContext iuc = (IUriContext)context.GetService(typeof(IUriContext)); //Debug.Assert (iuc != null, "IUriContext should not be null here"); if (iuc != null) { // the base uri is NOT "" if (iuc.BaseUri != null) { uriHolder.BaseUri = iuc.BaseUri; if (!uriHolder.BaseUri.IsAbsoluteUri) { uriHolder.BaseUri = new Uri(BaseUriHelper.BaseUri, uriHolder.BaseUri); } } // uriHolder.BaseUriString != "" else { // if we reach here, the base uri we got from IUriContext is "" // and the inputString is a relative uri. Here we resolve it to // application's base uriHolder.BaseUri = BaseUriHelper.BaseUri; } } // iuc != null } // context!= null } // uriHolder.OriginalUri.IsAbsoluteUri == false return uriHolder; } } #endregion } // 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
- DataGridViewIntLinkedList.cs
- PingReply.cs
- TemplatePropertyEntry.cs
- BamlLocalizableResource.cs
- PointIndependentAnimationStorage.cs
- RealProxy.cs
- ApplicationBuildProvider.cs
- DataGridViewAccessibleObject.cs
- TranslateTransform3D.cs
- Config.cs
- BindingSource.cs
- InheritedPropertyDescriptor.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- XslAst.cs
- basecomparevalidator.cs
- HtmlMeta.cs
- OleCmdHelper.cs
- MouseGesture.cs
- SqlCaseSimplifier.cs
- SafeProcessHandle.cs
- Item.cs
- ToolStrip.cs
- VectorCollectionConverter.cs
- AnnotationDocumentPaginator.cs
- WebConfigurationHost.cs
- BaseProcessor.cs
- StylusPointDescription.cs
- InternalConfigRoot.cs
- Point4DValueSerializer.cs
- Sequence.cs
- CacheOutputQuery.cs
- TableNameAttribute.cs
- TableCellAutomationPeer.cs
- MatrixConverter.cs
- ToolboxCategory.cs
- NumberSubstitution.cs
- ExpressionConverter.cs
- ExtenderProvidedPropertyAttribute.cs
- DoubleLinkList.cs
- HtmlMobileTextWriter.cs
- AssemblyBuilder.cs
- DbConnectionOptions.cs
- InputProcessorProfiles.cs
- ParagraphVisual.cs
- SoapRpcMethodAttribute.cs
- ImageCodecInfoPrivate.cs
- IItemProperties.cs
- LinqDataSourceValidationException.cs
- Double.cs
- XmlDictionaryString.cs
- RuleSettings.cs
- FlagsAttribute.cs
- EntityDataSourceStatementEditor.cs
- GridViewColumnHeader.cs
- SqlLiftWhereClauses.cs
- DataGridItemAttachedStorage.cs
- DataFieldConverter.cs
- ImplicitInputBrush.cs
- CompositeKey.cs
- XamlTemplateSerializer.cs
- XmlQueryType.cs
- AddIn.cs
- ImageAttributes.cs
- ItemCheckEvent.cs
- WebService.cs
- Propagator.Evaluator.cs
- ExtensionDataObject.cs
- UInt16Converter.cs
- WebServiceParameterData.cs
- ErrorLog.cs
- XmlUtil.cs
- OciEnlistContext.cs
- SqlDataSourceRefreshSchemaForm.cs
- SqlConnection.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- DependentTransaction.cs
- WmfPlaceableFileHeader.cs
- JoinTreeSlot.cs
- DataGridViewCell.cs
- ItemContainerGenerator.cs
- DBCommandBuilder.cs
- SecurityIdentifierElementCollection.cs
- DesignerRegionMouseEventArgs.cs
- XmlWellformedWriterHelpers.cs
- NoResizeHandleGlyph.cs
- ByteKeyFrameCollection.cs
- ToolboxCategoryItems.cs
- WebPartCloseVerb.cs
- UIAgentRequest.cs
- CrossAppDomainChannel.cs
- OleAutBinder.cs
- KeyToListMap.cs
- InkSerializer.cs
- Debug.cs
- DataSourceListEditor.cs
- EasingQuaternionKeyFrame.cs
- DelegateBodyWriter.cs
- SurrogateDataContract.cs
- _DisconnectOverlappedAsyncResult.cs
- mda.cs