Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / Xaml / AttributeConverter.cs / 1305376 / AttributeConverter.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.Xaml { using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Globalization; using System.Reflection; using System.Collections; using System.Runtime; //AttributeConverter is to convert some XAML-unfriendly attributes (without default ctor) to InstanceDescriptor for XAML serialization //AttributeInfo is a helper class to provide type specfic info for each Attribute class abstract class AttributeInfowhere TAttribute : Attribute { public abstract ConstructorInfo GetConstructor(); public abstract ICollection GetConstructorArguments(TAttribute attribute); //whether to use argumented-ctor for serialization even when there's default ctor public abstract bool LookupConstructionRequiresArguments { get; } } class AttributeConverter : TypeConverter where TAttribute:Attribute where TAttributeInfo:AttributeInfo , new() { TAttributeInfo attributeInfo = new TAttributeInfo(); static ConstructorInfo attributeConstructor = null; ConstructorInfo Constructor { get { //no need to lock here because every thread will generate the same constructor info even in race condition //and cost to get the constructor is relative small if (AttributeConverter .attributeConstructor == null) { AttributeConverter .attributeConstructor = this.attributeInfo.GetConstructor(); } return AttributeConverter .attributeConstructor; } } public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { return true; } return base.CanConvertTo(context, destinationType); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return false; } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType != typeof(InstanceDescriptor)) { return base.ConvertTo(context, culture, value, destinationType); } TAttribute attribute = value as TAttribute; if (attribute == null) { throw FxTrace.Exception.AsError(new ArgumentException( string.Format(CultureInfo.CurrentCulture, SR.AttributeConverter_ValueMustBeAttribute, typeof(TAttribute)), "value")); } return new InstanceDescriptor(this.Constructor, this.attributeInfo.GetConstructorArguments(attribute), true); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.Xaml { using System.Collections.Generic; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Globalization; using System.Reflection; using System.Collections; using System.Runtime; //AttributeConverter is to convert some XAML-unfriendly attributes (without default ctor) to InstanceDescriptor for XAML serialization //AttributeInfo is a helper class to provide type specfic info for each Attribute class abstract class AttributeInfo where TAttribute : Attribute { public abstract ConstructorInfo GetConstructor(); public abstract ICollection GetConstructorArguments(TAttribute attribute); //whether to use argumented-ctor for serialization even when there's default ctor public abstract bool LookupConstructionRequiresArguments { get; } } class AttributeConverter : TypeConverter where TAttribute:Attribute where TAttributeInfo:AttributeInfo , new() { TAttributeInfo attributeInfo = new TAttributeInfo(); static ConstructorInfo attributeConstructor = null; ConstructorInfo Constructor { get { //no need to lock here because every thread will generate the same constructor info even in race condition //and cost to get the constructor is relative small if (AttributeConverter .attributeConstructor == null) { AttributeConverter .attributeConstructor = this.attributeInfo.GetConstructor(); } return AttributeConverter .attributeConstructor; } } public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { return true; } return base.CanConvertTo(context, destinationType); } public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return false; } public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType != typeof(InstanceDescriptor)) { return base.ConvertTo(context, culture, value, destinationType); } TAttribute attribute = value as TAttribute; if (attribute == null) { throw FxTrace.Exception.AsError(new ArgumentException( string.Format(CultureInfo.CurrentCulture, SR.AttributeConverter_ValueMustBeAttribute, typeof(TAttribute)), "value")); } return new InstanceDescriptor(this.Constructor, this.attributeInfo.GetConstructorArguments(attribute), true); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- SmtpCommands.cs
- ActivityCollectionMarkupSerializer.cs
- RegularExpressionValidator.cs
- ReadOnlyActivityGlyph.cs
- MustUnderstandBehavior.cs
- HwndStylusInputProvider.cs
- PreProcessInputEventArgs.cs
- ApplicationInfo.cs
- CommonGetThemePartSize.cs
- ViewCellSlot.cs
- Point3DValueSerializer.cs
- TraceXPathNavigator.cs
- AppSettingsSection.cs
- ExtensionWindowResizeGrip.cs
- FunctionImportMapping.cs
- NativeMethods.cs
- TextRunCacheImp.cs
- ArglessEventHandlerProxy.cs
- DashStyles.cs
- StringCollectionEditor.cs
- Margins.cs
- Menu.cs
- DesignBinding.cs
- _NegoStream.cs
- JsonWriterDelegator.cs
- ValueQuery.cs
- MenuRendererClassic.cs
- GetLastErrorDetailsRequest.cs
- FontWeightConverter.cs
- ElementAction.cs
- WorkItem.cs
- XmlSchemaParticle.cs
- AppSettingsExpressionBuilder.cs
- FileNotFoundException.cs
- BasicBrowserDialog.designer.cs
- WebBrowserBase.cs
- SelectionUIHandler.cs
- UrlMappingsSection.cs
- PinProtectionHelper.cs
- SmtpLoginAuthenticationModule.cs
- MenuEventArgs.cs
- ReflectionTypeLoadException.cs
- SynthesizerStateChangedEventArgs.cs
- PageRequestManager.cs
- TransactionFlowProperty.cs
- GenericAuthenticationEventArgs.cs
- DocumentSchemaValidator.cs
- TableLayoutPanelDesigner.cs
- IntMinMaxAggregationOperator.cs
- StreamWithDictionary.cs
- VirtualizingPanel.cs
- InProcStateClientManager.cs
- ThrowOnMultipleAssignment.cs
- CanonicalFontFamilyReference.cs
- NativeMethodsOther.cs
- DataMember.cs
- SpoolingTaskBase.cs
- XPathAncestorQuery.cs
- altserialization.cs
- ConfigurationElementProperty.cs
- ReadOnlyDictionary.cs
- Matrix.cs
- CookieHandler.cs
- FileDialogCustomPlace.cs
- Nodes.cs
- MetadataUtilsSmi.cs
- Menu.cs
- FormViewPageEventArgs.cs
- SqlServices.cs
- HttpGetServerProtocol.cs
- XmlDataDocument.cs
- MarkedHighlightComponent.cs
- TemplateControlParser.cs
- ObfuscationAttribute.cs
- OdbcConnectionPoolProviderInfo.cs
- ServiceEndpointAssociationProvider.cs
- AdornedElementPlaceholder.cs
- VersionedStream.cs
- DbConnectionHelper.cs
- PropertyCollection.cs
- _CacheStreams.cs
- MonitorWrapper.cs
- GridLength.cs
- ListViewGroup.cs
- ItemsControlAutomationPeer.cs
- SingleObjectCollection.cs
- TextTrailingCharacterEllipsis.cs
- ProxyWebPartConnectionCollection.cs
- HttpModuleActionCollection.cs
- InfoCardTraceRecord.cs
- DBSqlParserColumnCollection.cs
- WizardPanel.cs
- listviewsubitemcollectioneditor.cs
- CommittableTransaction.cs
- _BasicClient.cs
- PermissionRequestEvidence.cs
- ClientSession.cs
- WeakRefEnumerator.cs
- Propagator.Evaluator.cs
- PageBuildProvider.cs