Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Framework / System / Windows / Markup / TypeExtension.cs / 1 / TypeExtension.cs
/****************************************************************************\ * * File: TypeExtension.cs * * Class for Xaml markup extension for a Type reference * * Copyright (C) 2004 by Microsoft Corporation. All rights reserved. * \***************************************************************************/ using System; using System.Windows; using System.ComponentModel; namespace System.Windows.Markup { ////// Class for Xaml markup extension for a Type reference. /// [TypeConverter(typeof(TypeExtensionConverter))] [MarkupExtensionReturnType(typeof(Type))] public class TypeExtension : MarkupExtension { ////// Default Constructor /// public TypeExtension() { } ////// Constructor that takes a type name /// public TypeExtension(string typeName) { if (typeName == null) { throw new ArgumentNullException("typeName"); } _typeName = typeName; } ////// Constructor that takes a type /// public TypeExtension(Type type) { if (type == null) { throw new ArgumentNullException("type"); } _type = type; // we would like to set TypeName here, but we can't because we can't resolve its namespace } ////// Return an object that should be set on the targetObject's targetProperty /// for this markup extension. TypeExtension resolves a string into a Type /// and returns it. /// /// Object that can provide services for the markup extension. ////// The object to set on this property. /// public override object ProvideValue(IServiceProvider serviceProvider) { // If a type was supplied, no context nor type name are needed if (_type != null) { return _type; } // Validate the initialization if (_typeName == null) { throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionTypeName)); } // Get the IXamlTypeResolver from the service provider IXamlTypeResolver xamlTypeResolver = serviceProvider.GetService(typeof(IXamlTypeResolver)) as IXamlTypeResolver; if( xamlTypeResolver == null ) { throw new InvalidOperationException( SR.Get(SRID.MarkupExtensionNoContext, GetType().Name, "IXamlTypeResolver" )); } // Get the type _type = xamlTypeResolver.Resolve(_typeName); if (_type == null) { throw new InvalidOperationException(SR.Get(SRID.MarkupExtensionTypeNameBad, _typeName)); } return _type; // we could cash the result of type as _type, but it might cause some problems, and in theory we shouldn't need to } ////// The typename represented by this markup extension. The name has the format /// Prefix:Typename, where Prefix is the xml namespace prefix for this type. /// [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)] public string TypeName { get { return _typeName; } set { if (value == null) { throw new ArgumentNullException("value"); } _typeName = value; _type = null; // so that ProvideValue does not use the existing type } } ////// The type represented by this markup extension. /// [DefaultValue(null)] [ConstructorArgument("type")] public Type Type { get { return _type; } set { if (value == null) { throw new ArgumentNullException("value"); } _type = value; _typeName = null; // so that ProvideValue does not use the existing typeName } } private string _typeName; private Type _type; } } // 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
- CommandField.cs
- AnimationClock.cs
- DynamicHyperLink.cs
- DisposableCollectionWrapper.cs
- ContractUtils.cs
- WindowAutomationPeer.cs
- BoundPropertyEntry.cs
- X509PeerCertificateAuthentication.cs
- ServiceObjectContainer.cs
- AssemblyAssociatedContentFileAttribute.cs
- LocalizableResourceBuilder.cs
- EntitySqlException.cs
- nulltextnavigator.cs
- EntityDataSourceDesignerHelper.cs
- ColumnTypeConverter.cs
- AutoResetEvent.cs
- WorkflowMarkupSerializer.cs
- QuestionEventArgs.cs
- DrawingGroup.cs
- MessageEncodingBindingElement.cs
- CheckoutException.cs
- AutomationPattern.cs
- InertiaRotationBehavior.cs
- DbFunctionCommandTree.cs
- StringExpressionSet.cs
- WithParamAction.cs
- BitmapEffectDrawing.cs
- DateTimeOffsetStorage.cs
- DataMemberAttribute.cs
- Main.cs
- BitmapEffectDrawingContextWalker.cs
- DescendantQuery.cs
- RecordConverter.cs
- DataPagerField.cs
- ButtonChrome.cs
- PageTheme.cs
- Ref.cs
- OdbcConnectionFactory.cs
- TemplateBamlTreeBuilder.cs
- DoubleAnimation.cs
- DbProviderConfigurationHandler.cs
- ThicknessAnimation.cs
- ListBox.cs
- HWStack.cs
- OdbcParameter.cs
- UntypedNullExpression.cs
- SR.cs
- ReflectionPermission.cs
- SrgsRule.cs
- WebRequest.cs
- TransactedBatchingElement.cs
- FormatSettings.cs
- LineServices.cs
- EncryptedXml.cs
- InvalidPropValue.cs
- ToolStripItemRenderEventArgs.cs
- UriTemplatePathPartiallyEquivalentSet.cs
- WindowManager.cs
- ObjectListGeneralPage.cs
- FacetValueContainer.cs
- MouseGestureValueSerializer.cs
- WebPartDescriptionCollection.cs
- MachineKeyConverter.cs
- ErrorWebPart.cs
- datacache.cs
- PrivilegedConfigurationManager.cs
- Transactions.cs
- WorkingDirectoryEditor.cs
- BitmapEffectState.cs
- ElementNotAvailableException.cs
- EditorServiceContext.cs
- CounterSampleCalculator.cs
- Rfc2898DeriveBytes.cs
- OletxResourceManager.cs
- ParameterToken.cs
- KeyToListMap.cs
- DbDataRecord.cs
- WorkflowDesignerColors.cs
- DBNull.cs
- FormClosingEvent.cs
- WithParamAction.cs
- uribuilder.cs
- StringAttributeCollection.cs
- IImplicitResourceProvider.cs
- PathNode.cs
- CodeMemberField.cs
- ContainerUIElement3D.cs
- EastAsianLunisolarCalendar.cs
- _LocalDataStoreMgr.cs
- CompositeControl.cs
- WindowsTokenRoleProvider.cs
- Shape.cs
- WebPartActionVerb.cs
- Margins.cs
- DynamicValidatorEventArgs.cs
- MatchAllMessageFilter.cs
- XXXInfos.cs
- Splitter.cs
- XmlUrlResolver.cs
- TextCollapsingProperties.cs