Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / 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
- XmlObjectSerializerContext.cs
- SBCSCodePageEncoding.cs
- SqlException.cs
- BinaryCommonClasses.cs
- ResourceReferenceKeyNotFoundException.cs
- AstTree.cs
- WebEventCodes.cs
- DataSourceProvider.cs
- ConfigurationHandlersInstallComponent.cs
- TraceSection.cs
- SpeechEvent.cs
- OpenTypeLayout.cs
- AttachedPropertyBrowsableForTypeAttribute.cs
- XmlAttributes.cs
- TreeNode.cs
- SpeechRecognizer.cs
- AttributeProviderAttribute.cs
- SiteMapDataSource.cs
- AsmxEndpointPickerExtension.cs
- ButtonPopupAdapter.cs
- HighlightVisual.cs
- MD5CryptoServiceProvider.cs
- Normalization.cs
- BufferedStream.cs
- SecurityTokenValidationException.cs
- SetState.cs
- RelOps.cs
- HtmlImageAdapter.cs
- MemoryRecordBuffer.cs
- XmlILTrace.cs
- ItemsPresenter.cs
- EventMetadata.cs
- QueryModel.cs
- SocketElement.cs
- ArithmeticException.cs
- GraphicsContext.cs
- TextRange.cs
- NativeRightsManagementAPIsStructures.cs
- ErrorReporting.cs
- FieldDescriptor.cs
- DataGridViewIntLinkedList.cs
- XmlCollation.cs
- HealthMonitoringSectionHelper.cs
- SQLSingleStorage.cs
- MetadataFile.cs
- ServiceObjectContainer.cs
- UriExt.cs
- SignedXmlDebugLog.cs
- SortDescription.cs
- FieldReference.cs
- DataGridViewCellFormattingEventArgs.cs
- DataGridPageChangedEventArgs.cs
- Int64Storage.cs
- Library.cs
- OdbcConnectionString.cs
- ModuleConfigurationInfo.cs
- SByte.cs
- PageThemeParser.cs
- EndOfStreamException.cs
- Util.cs
- BigInt.cs
- SiteMapPath.cs
- HashMembershipCondition.cs
- HttpProtocolImporter.cs
- _NegoStream.cs
- StaticExtension.cs
- AuthenticationConfig.cs
- BooleanKeyFrameCollection.cs
- recordstatefactory.cs
- MappingSource.cs
- Single.cs
- TypedDataSourceCodeGenerator.cs
- RequestCache.cs
- HtmlImageAdapter.cs
- SolidColorBrush.cs
- RowBinding.cs
- URLAttribute.cs
- MulticastDelegate.cs
- TextServicesDisplayAttribute.cs
- AutomationIdentifier.cs
- ToolStripArrowRenderEventArgs.cs
- DecimalAverageAggregationOperator.cs
- TypedReference.cs
- LineBreak.cs
- DriveNotFoundException.cs
- Baml2006KeyRecord.cs
- DropSource.cs
- SessionStateItemCollection.cs
- OrderByQueryOptionExpression.cs
- CodeDelegateInvokeExpression.cs
- SelectorAutomationPeer.cs
- ActivityInterfaces.cs
- SwitchLevelAttribute.cs
- DbMetaDataColumnNames.cs
- GroupBox.cs
- Evidence.cs
- InvalidOperationException.cs
- HwndStylusInputProvider.cs
- ResourceContainer.cs
- MexBindingBindingCollectionElement.cs