Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / 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
- FileStream.cs
- EditorPartDesigner.cs
- counter.cs
- HTMLTagNameToTypeMapper.cs
- ConnectionPoint.cs
- Win32SafeHandles.cs
- CallbackException.cs
- NumberAction.cs
- ToolBarOverflowPanel.cs
- ReaderWriterLock.cs
- TreeNodeStyleCollection.cs
- DbProviderFactory.cs
- ThreadStaticAttribute.cs
- LoginDesignerUtil.cs
- UInt16.cs
- ContextQuery.cs
- OutputCacheProfileCollection.cs
- DataGridViewCellPaintingEventArgs.cs
- CodeDomConfigurationHandler.cs
- OracleParameter.cs
- ApplicationException.cs
- WebServiceTypeData.cs
- EnumType.cs
- ScriptResourceAttribute.cs
- AsyncPostBackTrigger.cs
- ChannelServices.cs
- TrustManager.cs
- DataKeyCollection.cs
- ValidationHelper.cs
- XmlEntityReference.cs
- MailBnfHelper.cs
- UniqueCodeIdentifierScope.cs
- EnumConverter.cs
- PreProcessInputEventArgs.cs
- Pair.cs
- Journaling.cs
- PriorityChain.cs
- SecurityResources.cs
- Evidence.cs
- UrlMappingsModule.cs
- ClientData.cs
- SqlNodeAnnotations.cs
- DataGridViewHeaderCell.cs
- SetterBase.cs
- HttpStreamXmlDictionaryReader.cs
- NetworkInformationPermission.cs
- TextRangeEditTables.cs
- GradientStopCollection.cs
- SQLInt32Storage.cs
- Translator.cs
- TemplateBindingExtensionConverter.cs
- Serializer.cs
- ComponentEditorForm.cs
- XPathParser.cs
- RijndaelManagedTransform.cs
- ConfigurationManagerHelper.cs
- DataGridAutoFormat.cs
- ColorTransformHelper.cs
- DocComment.cs
- SymDocumentType.cs
- AssemblyResolver.cs
- XmlDocumentSerializer.cs
- ServiceDescriptions.cs
- XmlILModule.cs
- Membership.cs
- ToolStripScrollButton.cs
- TextBoxView.cs
- DataGridTableCollection.cs
- CorrelationManager.cs
- MetadataException.cs
- DataControlImageButton.cs
- HyperLinkColumn.cs
- NumericUpDownAccelerationCollection.cs
- ComplexBindingPropertiesAttribute.cs
- WebHttpBinding.cs
- MSAAEventDispatcher.cs
- PerformanceCounterPermission.cs
- StateMachine.cs
- CustomErrorsSectionWrapper.cs
- _SafeNetHandles.cs
- TargetInvocationException.cs
- QualificationDataAttribute.cs
- Parsers.cs
- XmlComplianceUtil.cs
- DataSourceControl.cs
- RequiredFieldValidator.cs
- SystemMulticastIPAddressInformation.cs
- FormViewInsertEventArgs.cs
- HwndAppCommandInputProvider.cs
- VideoDrawing.cs
- CTreeGenerator.cs
- XmlSchemaAny.cs
- Int16.cs
- DocumentViewerBase.cs
- ToolTipService.cs
- SortExpressionBuilder.cs
- DispatcherHooks.cs
- typedescriptorpermissionattribute.cs
- VisualBrush.cs
- RowTypeElement.cs