Code:
/ 4.0 / 4.0 / untmp / 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.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- ClientTargetCollection.cs
- XhtmlTextWriter.cs
- HtmlInputControl.cs
- WinEventTracker.cs
- InvalidPropValue.cs
- ProfileSettings.cs
- GridLength.cs
- PngBitmapEncoder.cs
- PackUriHelper.cs
- dataSvcMapFileLoader.cs
- DeflateInput.cs
- DataGridViewCellToolTipTextNeededEventArgs.cs
- FontFamilyConverter.cs
- PhysicalAddress.cs
- FilteredXmlReader.cs
- TagPrefixAttribute.cs
- indexingfiltermarshaler.cs
- WorkflowOperationFault.cs
- FieldToken.cs
- TimerTable.cs
- PresentationSource.cs
- PageParser.cs
- PrintPageEvent.cs
- CompilationSection.cs
- SecurityTokenProviderContainer.cs
- SafeLibraryHandle.cs
- VersionedStream.cs
- SmiRequestExecutor.cs
- Registry.cs
- OrCondition.cs
- SmiMetaDataProperty.cs
- IPPacketInformation.cs
- FontStretchConverter.cs
- connectionpool.cs
- Html32TextWriter.cs
- FormsAuthenticationUser.cs
- CustomExpression.cs
- TraceContextEventArgs.cs
- AxHost.cs
- FrameworkElementFactory.cs
- TraceHandler.cs
- DelimitedListTraceListener.cs
- MembershipUser.cs
- UidManager.cs
- HostedImpersonationContext.cs
- TcpProcessProtocolHandler.cs
- WindowsAuthenticationModule.cs
- ConnectionStringSettings.cs
- WinEventWrap.cs
- EnlistmentTraceIdentifier.cs
- TextTreeUndoUnit.cs
- TextContainerChangeEventArgs.cs
- RSAOAEPKeyExchangeFormatter.cs
- CommandDevice.cs
- altserialization.cs
- CreateUserWizardStep.cs
- EnumerableRowCollectionExtensions.cs
- SqlBulkCopyColumnMapping.cs
- BooleanAnimationBase.cs
- KerberosTokenFactoryCredential.cs
- Span.cs
- Vector3DConverter.cs
- BindingObserver.cs
- RSAPKCS1SignatureDeformatter.cs
- ResourceReferenceKeyNotFoundException.cs
- EntitySet.cs
- RelationshipConverter.cs
- ASCIIEncoding.cs
- TransformationRules.cs
- StrokeNodeData.cs
- PageSetupDialog.cs
- PenCursorManager.cs
- FillErrorEventArgs.cs
- WindowsEditBox.cs
- RuntimeHandles.cs
- EntityContainer.cs
- MetadataPropertyAttribute.cs
- EditableTreeList.cs
- SkipQueryOptionExpression.cs
- ListViewItemMouseHoverEvent.cs
- DataRecordInternal.cs
- ParallelForEach.cs
- QueryStatement.cs
- SymbolDocumentInfo.cs
- ConstraintEnumerator.cs
- SeverityFilter.cs
- TransactionCache.cs
- EventNotify.cs
- MailAddressCollection.cs
- GenericWebPart.cs
- AssemblyInfo.cs
- ImpersonateTokenRef.cs
- DesignerLabelAdapter.cs
- IriParsingElement.cs
- HelpProvider.cs
- XslVisitor.cs
- DataGridTextBox.cs
- Control.cs
- OleDbException.cs
- RegexCapture.cs