Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / System / Windows / Markup / ProvideValueServiceProvider.cs / 1 / 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, IBamlReader, 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); } // IBamlReader implementation BamlRecordReader IBamlReader.GetBamlReader() { return _context.BamlReader; } // 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(IBamlReader)) { return this as IBamlReader; } 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, IBamlReader, 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); } // IBamlReader implementation BamlRecordReader IBamlReader.GetBamlReader() { return _context.BamlReader; } // 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(IBamlReader)) { return this as IBamlReader; } 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
- ViewGenResults.cs
- RegexMatch.cs
- Light.cs
- FormsAuthenticationModule.cs
- WebPartEditorApplyVerb.cs
- HotCommands.cs
- EmissiveMaterial.cs
- UrlMappingsSection.cs
- ByteAnimationUsingKeyFrames.cs
- MemberRelationshipService.cs
- X509ChainElement.cs
- versioninfo.cs
- UserControlDesigner.cs
- NameValueConfigurationCollection.cs
- NegotiationTokenAuthenticatorStateCache.cs
- ForeignKeyConstraint.cs
- AuthStoreRoleProvider.cs
- PermissionListSet.cs
- DataGridDesigner.cs
- ResourceAttributes.cs
- PathFigureCollectionValueSerializer.cs
- documentation.cs
- DataGridViewRowCollection.cs
- HandoffBehavior.cs
- PostBackOptions.cs
- ImageClickEventArgs.cs
- CompareValidator.cs
- NonSerializedAttribute.cs
- SubstitutionResponseElement.cs
- DataSourceHelper.cs
- BehaviorEditorPart.cs
- OdbcPermission.cs
- PrintingPermission.cs
- _PooledStream.cs
- DesignBinding.cs
- WebPartDesigner.cs
- ObjectContext.cs
- SchemaLookupTable.cs
- ListControlConvertEventArgs.cs
- SQLDecimal.cs
- SoapExtensionReflector.cs
- TextBoxBase.cs
- ObjectHandle.cs
- BitmapEffectGroup.cs
- MetadataItemSerializer.cs
- TimeoutHelper.cs
- Suspend.cs
- OleStrCAMarshaler.cs
- BinaryCommonClasses.cs
- RequestNavigateEventArgs.cs
- HttpDictionary.cs
- UIElement3D.cs
- MsmqActivation.cs
- HttpRequest.cs
- DrawingGroup.cs
- LoadGrammarCompletedEventArgs.cs
- XmlEnumAttribute.cs
- SecondaryIndex.cs
- EventListener.cs
- GridItemProviderWrapper.cs
- XmlSerializerFactory.cs
- RSAPKCS1SignatureFormatter.cs
- StreamAsIStream.cs
- IndependentAnimationStorage.cs
- ClientBuildManagerCallback.cs
- System.Data.OracleClient_BID.cs
- ServiceHostFactory.cs
- HitTestWithPointDrawingContextWalker.cs
- SelectorItemAutomationPeer.cs
- Avt.cs
- WorkflowRuntimeElement.cs
- Wildcard.cs
- KnownAssemblyEntry.cs
- WebPartEditorApplyVerb.cs
- HtmlControlPersistable.cs
- AudioBase.cs
- ArgumentsParser.cs
- BaseTemplateBuildProvider.cs
- WindowsStartMenu.cs
- PanelDesigner.cs
- ToolStripRenderer.cs
- DependencyPropertyConverter.cs
- ImplicitInputBrush.cs
- TextBoxRenderer.cs
- DockPanel.cs
- OperatingSystemVersionCheck.cs
- BamlLocalizabilityResolver.cs
- WmpBitmapEncoder.cs
- UInt64.cs
- SystemInfo.cs
- ResourceType.cs
- Aggregates.cs
- DataGridViewImageColumn.cs
- MonthCalendar.cs
- PointAnimationClockResource.cs
- Permission.cs
- QilLiteral.cs
- TreeBuilderXamlTranslator.cs
- HttpModuleCollection.cs
- DataTableExtensions.cs