Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / Markup / ProvideValueServiceProvider.cs / 1305600 / ProvideValueServiceProvider.cs
/****************************************************************************\ * * File: ProvideValueServiceProvider.cs * * ServiceProvider class that is passed into MarkupExtensions.ProvideValue method * that understands the ParserContext. * * Copyright (C) 2006 by Microsoft Corporation. All rights reserved. * \***************************************************************************/ using System; using System.Windows; using System.Windows.Media; using System.Diagnostics; namespace System.Windows.Markup { ////// Base class for all Xaml markup extensions. /// internal class ProvideValueServiceProvider : IServiceProvider, IProvideValueTarget, IXamlTypeResolver, IUriContext, IFreezeFreezables { // Construction internal ProvideValueServiceProvider(ParserContext context) { _context = context; } internal ProvideValueServiceProvider() { } // Set the TargetObject/Property (for use by IProvideValueTarget). internal void SetData(object targetObject, object targetProperty) { _targetObject = targetObject; _targetProperty = targetProperty; } // Clear the TargetObject/Property (after a call to ProvideValue) internal void ClearData() { _targetObject = _targetProperty = null; } // IXamlTypeResolver implementation Type IXamlTypeResolver.Resolve(string qualifiedTypeName) // E.g. foo:Class { return _context.XamlTypeMapper.GetTypeFromBaseString(qualifiedTypeName, _context, true); } // IProvideValueTarget implementation object IProvideValueTarget.TargetObject { get { return _targetObject; } } object IProvideValueTarget.TargetProperty { get { return _targetProperty; } } // IUriContext implementation Uri IUriContext.BaseUri { get { return _context.BaseUri; } set { throw new NotSupportedException(SR.Get(SRID.ParserProvideValueCantSetUri)); } } bool IFreezeFreezables.FreezeFreezables { get { return _context.FreezeFreezables; } } bool IFreezeFreezables.TryFreeze(string value, Freezable freezable) { return _context.TryCacheFreezable(value, freezable); } Freezable IFreezeFreezables.TryGetFreezable(string value) { return _context.TryGetFreezable(value); } // IServiceProvider implementation (this is the way to get to the // above interface implementations). public object GetService(Type service) { // IProvideValueTarget is the only implementation that // doesn't need the ParserContext if( service == typeof(IProvideValueTarget)) { return this as IProvideValueTarget; } if( _context != null ) { if( service == typeof(IXamlTypeResolver)) { return this as IXamlTypeResolver; } else if( service == typeof(IUriContext)) { return this as IUriContext; } else if (service == typeof(IFreezeFreezables)) { return this as IFreezeFreezables; } } return null; } // Data private ParserContext _context = null; private object _targetObject = null; private object _targetProperty = null; } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /****************************************************************************\ * * File: ProvideValueServiceProvider.cs * * ServiceProvider class that is passed into MarkupExtensions.ProvideValue method * that understands the ParserContext. * * Copyright (C) 2006 by Microsoft Corporation. All rights reserved. * \***************************************************************************/ using System; using System.Windows; using System.Windows.Media; using System.Diagnostics; namespace System.Windows.Markup { ////// Base class for all Xaml markup extensions. /// internal class ProvideValueServiceProvider : IServiceProvider, IProvideValueTarget, IXamlTypeResolver, IUriContext, IFreezeFreezables { // Construction internal ProvideValueServiceProvider(ParserContext context) { _context = context; } internal ProvideValueServiceProvider() { } // Set the TargetObject/Property (for use by IProvideValueTarget). internal void SetData(object targetObject, object targetProperty) { _targetObject = targetObject; _targetProperty = targetProperty; } // Clear the TargetObject/Property (after a call to ProvideValue) internal void ClearData() { _targetObject = _targetProperty = null; } // IXamlTypeResolver implementation Type IXamlTypeResolver.Resolve(string qualifiedTypeName) // E.g. foo:Class { return _context.XamlTypeMapper.GetTypeFromBaseString(qualifiedTypeName, _context, true); } // IProvideValueTarget implementation object IProvideValueTarget.TargetObject { get { return _targetObject; } } object IProvideValueTarget.TargetProperty { get { return _targetProperty; } } // IUriContext implementation Uri IUriContext.BaseUri { get { return _context.BaseUri; } set { throw new NotSupportedException(SR.Get(SRID.ParserProvideValueCantSetUri)); } } bool IFreezeFreezables.FreezeFreezables { get { return _context.FreezeFreezables; } } bool IFreezeFreezables.TryFreeze(string value, Freezable freezable) { return _context.TryCacheFreezable(value, freezable); } Freezable IFreezeFreezables.TryGetFreezable(string value) { return _context.TryGetFreezable(value); } // IServiceProvider implementation (this is the way to get to the // above interface implementations). public object GetService(Type service) { // IProvideValueTarget is the only implementation that // doesn't need the ParserContext if( service == typeof(IProvideValueTarget)) { return this as IProvideValueTarget; } if( _context != null ) { if( service == typeof(IXamlTypeResolver)) { return this as IXamlTypeResolver; } else if( service == typeof(IUriContext)) { return this as IUriContext; } else if (service == typeof(IFreezeFreezables)) { return this as IFreezeFreezables; } } return null; } // Data private ParserContext _context = null; private object _targetObject = null; private object _targetProperty = null; } } // 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
- XmlMembersMapping.cs
- SoundPlayer.cs
- XamlFigureLengthSerializer.cs
- Drawing.cs
- ListSortDescription.cs
- DesignBindingPicker.cs
- ListViewGroup.cs
- GridItemPattern.cs
- MultiTrigger.cs
- ArrangedElementCollection.cs
- DependencyObjectType.cs
- AnnotationHelper.cs
- IApplicationTrustManager.cs
- TypeHelpers.cs
- DecoderReplacementFallback.cs
- WebPageTraceListener.cs
- DependencyObjectProvider.cs
- xml.cs
- BindingContext.cs
- SurrogateDataContract.cs
- Line.cs
- RegexReplacement.cs
- DbConnectionInternal.cs
- StringReader.cs
- SchemaCollectionCompiler.cs
- ChannelSinkStacks.cs
- SelfIssuedAuthAsymmetricKey.cs
- TypedTableBase.cs
- ObjectDataSourceMethodEditor.cs
- TextTreePropertyUndoUnit.cs
- MissingFieldException.cs
- PixelFormats.cs
- GlyphRunDrawing.cs
- DetailsViewPageEventArgs.cs
- TrackingRecord.cs
- FrameworkTemplate.cs
- NamespaceInfo.cs
- DefaultClaimSet.cs
- PageCatalogPart.cs
- SqlErrorCollection.cs
- PathGeometry.cs
- ObjectAssociationEndMapping.cs
- DataGridState.cs
- XmlEncApr2001.cs
- StorageScalarPropertyMapping.cs
- NextPreviousPagerField.cs
- Timeline.cs
- BitmapVisualManager.cs
- XmlTypeAttribute.cs
- RotationValidation.cs
- AppSettingsSection.cs
- TogglePatternIdentifiers.cs
- XPathNodeInfoAtom.cs
- ListViewPagedDataSource.cs
- BitmapPalette.cs
- ToolStripContentPanelRenderEventArgs.cs
- XmlHierarchicalEnumerable.cs
- DirectoryInfo.cs
- XamlBrushSerializer.cs
- OverlappedContext.cs
- SelectionService.cs
- SecurityHelper.cs
- Context.cs
- LocalFileSettingsProvider.cs
- TabPanel.cs
- Storyboard.cs
- WindowsScrollBar.cs
- Trace.cs
- HandlerFactoryCache.cs
- Interlocked.cs
- PopupRootAutomationPeer.cs
- TextDecorationCollection.cs
- HttpEncoderUtility.cs
- FlowchartDesigner.Helpers.cs
- CatalogZone.cs
- LayoutSettings.cs
- HtmlInputHidden.cs
- BrushMappingModeValidation.cs
- ApplicationContext.cs
- DataBindingHandlerAttribute.cs
- listitem.cs
- DispatcherHooks.cs
- MobileUserControl.cs
- EntityDataSourceDataSelectionPanel.designer.cs
- Binding.cs
- FormatConvertedBitmap.cs
- CompareInfo.cs
- WorkflowApplicationAbortedEventArgs.cs
- WebPartTransformerAttribute.cs
- ComplexPropertyEntry.cs
- ImplicitInputBrush.cs
- ArrayConverter.cs
- ContextMarshalException.cs
- EndEvent.cs
- FixedSOMTextRun.cs
- ReadContentAsBinaryHelper.cs
- precedingquery.cs
- VisualStyleRenderer.cs
- PersonalizablePropertyEntry.cs
- DataObjectPastingEventArgs.cs