Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / MS / Internal / Markup / StaticExtension.cs / 1305600 / StaticExtension.cs
/****************************************************************************\ * * File: StaticExtension.cs * * Class for Xaml markup extension for static field and property references. * * Copyright (C) 2004 by Microsoft Corporation. All rights reserved. * \***************************************************************************/ using System; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Windows.Input; using System.Reflection; using MS.Internal.WindowsBase; using MS.Utility; using System.Runtime.CompilerServices; using System.Windows.Markup; using System.Windows; namespace MS.Internal.Markup { ////// WPF wrapper for StaticExtension. Optimizes some common SystemResourceKeys & Commands /// internal class StaticExtension : System.Windows.Markup.StaticExtension { public StaticExtension() : base() { } public StaticExtension(String member) : base(member) { } ////// Return an object that should be set on the targetObject's targetProperty /// for this markup extension. For a StaticExtension this is a static field /// or property value. /// /// Object that can provide services for the markup extension. ////// The object to set on this property. /// public override object ProvideValue(IServiceProvider serviceProvider) { if (Member == null) { throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionStaticMember)); } object value; if (MemberType != null) { value = SystemResourceKey.GetSystemResourceKey(MemberType.Name + "." + Member); if (value != null) { return value; } } else { value = SystemResourceKey.GetSystemResourceKey(Member); if (value != null) { return value; } // Validate the _member int dotIndex = Member.IndexOf('.'); if (dotIndex < 0) { throw new ArgumentException(SR.Get(SRID.MarkupExtensionBadStatic, Member)); } // Pull out the type substring (this will include any XML prefix, e.g. "av:Button") string typeString = Member.Substring(0, dotIndex); if (typeString == string.Empty) { throw new ArgumentException(SR.Get(SRID.MarkupExtensionBadStatic, Member)); } // Get the IXamlTypeResolver from the service provider if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; if (xamlTypeResolver == null) { throw new ArgumentException(SR.Get(SRID.MarkupExtensionNoContext, GetType().Name, "IXamlTypeResolver")); } // Use the type resolver to get a Type instance MemberType = xamlTypeResolver.Resolve(typeString); // Get the member name substring Member = Member.Substring(dotIndex + 1, Member.Length - dotIndex - 1); } value = CommandConverter.GetKnownControlCommand(MemberType, Member); if (value != null) { return value; } return base.ProvideValue(serviceProvider); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. /****************************************************************************\ * * File: StaticExtension.cs * * Class for Xaml markup extension for static field and property references. * * Copyright (C) 2004 by Microsoft Corporation. All rights reserved. * \***************************************************************************/ using System; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Windows.Input; using System.Reflection; using MS.Internal.WindowsBase; using MS.Utility; using System.Runtime.CompilerServices; using System.Windows.Markup; using System.Windows; namespace MS.Internal.Markup { ////// WPF wrapper for StaticExtension. Optimizes some common SystemResourceKeys & Commands /// internal class StaticExtension : System.Windows.Markup.StaticExtension { public StaticExtension() : base() { } public StaticExtension(String member) : base(member) { } ////// Return an object that should be set on the targetObject's targetProperty /// for this markup extension. For a StaticExtension this is a static field /// or property value. /// /// Object that can provide services for the markup extension. ////// The object to set on this property. /// public override object ProvideValue(IServiceProvider serviceProvider) { if (Member == null) { throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionStaticMember)); } object value; if (MemberType != null) { value = SystemResourceKey.GetSystemResourceKey(MemberType.Name + "." + Member); if (value != null) { return value; } } else { value = SystemResourceKey.GetSystemResourceKey(Member); if (value != null) { return value; } // Validate the _member int dotIndex = Member.IndexOf('.'); if (dotIndex < 0) { throw new ArgumentException(SR.Get(SRID.MarkupExtensionBadStatic, Member)); } // Pull out the type substring (this will include any XML prefix, e.g. "av:Button") string typeString = Member.Substring(0, dotIndex); if (typeString == string.Empty) { throw new ArgumentException(SR.Get(SRID.MarkupExtensionBadStatic, Member)); } // Get the IXamlTypeResolver from the service provider if (serviceProvider == null) { throw new ArgumentNullException("serviceProvider"); } IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; if (xamlTypeResolver == null) { throw new ArgumentException(SR.Get(SRID.MarkupExtensionNoContext, GetType().Name, "IXamlTypeResolver")); } // Use the type resolver to get a Type instance MemberType = xamlTypeResolver.Resolve(typeString); // Get the member name substring Member = Member.Substring(dotIndex + 1, Member.Length - dotIndex - 1); } value = CommandConverter.GetKnownControlCommand(MemberType, Member); if (value != null) { return value; } return base.ProvideValue(serviceProvider); } } } // 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
- BaseTemplateParser.cs
- StateWorkerRequest.cs
- SecurityDocument.cs
- CheckoutException.cs
- CustomUserNameSecurityTokenAuthenticator.cs
- ProxyFragment.cs
- TheQuery.cs
- Double.cs
- ApplicationFileParser.cs
- SynchronizedDispatch.cs
- ReadWriteObjectLock.cs
- XsltLibrary.cs
- LoginViewDesigner.cs
- ColumnResizeUndoUnit.cs
- AlternateView.cs
- RuleInfoComparer.cs
- Endpoint.cs
- OracleCommandBuilder.cs
- SymbolType.cs
- WinEventWrap.cs
- ComUdtElement.cs
- OutgoingWebRequestContext.cs
- MessageQueueException.cs
- HGlobalSafeHandle.cs
- BaseTemplateParser.cs
- TreeNodeStyle.cs
- DataGridViewRowDividerDoubleClickEventArgs.cs
- UserControlDocumentDesigner.cs
- SizeValueSerializer.cs
- TdsParserSessionPool.cs
- IOException.cs
- TagNameToTypeMapper.cs
- SqlBulkCopyColumnMappingCollection.cs
- TripleDESCryptoServiceProvider.cs
- EntityParameter.cs
- ValueUtilsSmi.cs
- FloaterParagraph.cs
- DynamicContractTypeBuilder.cs
- MenuItemStyleCollection.cs
- SimpleTypeResolver.cs
- XmlObjectSerializerReadContextComplex.cs
- BufferedGraphicsManager.cs
- XsltCompileContext.cs
- WindowsClaimSet.cs
- FollowerQueueCreator.cs
- EncodingDataItem.cs
- AttributeCollection.cs
- Utilities.cs
- NamedPermissionSet.cs
- _NestedSingleAsyncResult.cs
- webeventbuffer.cs
- CollectionViewGroup.cs
- FileDetails.cs
- StylusDevice.cs
- QueueTransferProtocol.cs
- sitestring.cs
- BitmapEncoder.cs
- ProcessModuleCollection.cs
- WebPartConnectionsCancelVerb.cs
- MobileControlsSection.cs
- RelatedCurrencyManager.cs
- XmlAttributeAttribute.cs
- StructuredTypeInfo.cs
- ErrorFormatter.cs
- ObjectFullSpanRewriter.cs
- WebColorConverter.cs
- SafeRightsManagementPubHandle.cs
- CharUnicodeInfo.cs
- ProxyElement.cs
- PropertyInformation.cs
- ToolStripSettings.cs
- SelfIssuedAuthRSAPKCS1SignatureFormatter.cs
- TreeNodeStyleCollection.cs
- TTSEvent.cs
- DelegateBodyWriter.cs
- PrinterSettings.cs
- OneToOneMappingSerializer.cs
- _AuthenticationState.cs
- FontNamesConverter.cs
- CommandLibraryHelper.cs
- TextTreeDeleteContentUndoUnit.cs
- ChangeNode.cs
- PixelFormatConverter.cs
- WrappingXamlSchemaContext.cs
- ContainerFilterService.cs
- RoleServiceManager.cs
- HttpRequestTraceRecord.cs
- DocumentScope.cs
- MultiPageTextView.cs
- ProfileServiceManager.cs
- loginstatus.cs
- ISO2022Encoding.cs
- RegularExpressionValidator.cs
- WorkflowWebService.cs
- PersonalizationStateQuery.cs
- XPathDocumentNavigator.cs
- BackgroundFormatInfo.cs
- SingleObjectCollection.cs
- AnnotationComponentChooser.cs
- XmlAttributes.cs