Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Messaging / System / Messaging / Design / MessageFormatterConverter.cs / 1305376 / MessageFormatterConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Messaging.Design { using System.Messaging; using System.Threading; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Reflection; using System.Diagnostics; using System; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.Design; using System.Windows.Forms.ComponentModel; using System.Messaging.Interop; using System.Collections; using System.Runtime.Serialization.Formatters; using System.Globalization; ////// internal class MessageFormatterConverter : ExpandableObjectConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return (sourceType == typeof(string)); } /// /// /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { return true; } return base.CanConvertTo(context, destinationType); } ///Gets a value indicating whether this converter can /// convert an object to the given destination type using the context. ////// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value != null && value is string) { if (((string)value) == typeof(ActiveXMessageFormatter).Name) return new ActiveXMessageFormatter(); if (((string)value) == typeof(BinaryMessageFormatter).Name) return new BinaryMessageFormatter(); if (((string)value) == typeof(XmlMessageFormatter).Name) return new XmlMessageFormatter(); } return null; } /// /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType != null && destinationType == typeof(string)) { if (value == null) return Res.GetString(Res.toStringNone); return value.GetType().Name; } if (destinationType == typeof(InstanceDescriptor)) { if (value is XmlMessageFormatter) { XmlMessageFormatter f = (XmlMessageFormatter)value; ConstructorInfo ctor = typeof(XmlMessageFormatter).GetConstructor(new Type[] {typeof(string[])}); if (ctor != null) { return new InstanceDescriptor(ctor, new object[] {f.TargetTypeNames}); } } else if (value is ActiveXMessageFormatter) { ConstructorInfo ctor = typeof(ActiveXMessageFormatter).GetConstructor(new Type[0]); if (ctor != null) { return new InstanceDescriptor(ctor, new object[0]); } } else if (value is BinaryMessageFormatter) { BinaryMessageFormatter f = (BinaryMessageFormatter)value; ConstructorInfo ctor = typeof(BinaryMessageFormatter).GetConstructor(new Type[] { typeof(FormatterAssemblyStyle), typeof(FormatterTypeStyle)}); if (ctor != null) { return new InstanceDescriptor(ctor, new object[] {f.TopObjectFormat, f.TypeFormat}); } } } return base.ConvertTo(context, culture, value, destinationType); } /// /// public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { StandardValuesCollection values = new StandardValuesCollection(new object[] {new ActiveXMessageFormatter(), new BinaryMessageFormatter(), new XmlMessageFormatter(), null}); return values; } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } /// /// public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return true; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ // // Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Messaging.Design { using System.Messaging; using System.Threading; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Reflection; using System.Diagnostics; using System; using System.Drawing; using System.Windows.Forms; using System.Windows.Forms.Design; using System.Windows.Forms.ComponentModel; using System.Messaging.Interop; using System.Collections; using System.Runtime.Serialization.Formatters; using System.Globalization; ////// internal class MessageFormatterConverter : ExpandableObjectConverter { public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { return (sourceType == typeof(string)); } /// /// /// public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor)) { return true; } return base.CanConvertTo(context, destinationType); } ///Gets a value indicating whether this converter can /// convert an object to the given destination type using the context. ////// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value != null && value is string) { if (((string)value) == typeof(ActiveXMessageFormatter).Name) return new ActiveXMessageFormatter(); if (((string)value) == typeof(BinaryMessageFormatter).Name) return new BinaryMessageFormatter(); if (((string)value) == typeof(XmlMessageFormatter).Name) return new XmlMessageFormatter(); } return null; } /// /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType != null && destinationType == typeof(string)) { if (value == null) return Res.GetString(Res.toStringNone); return value.GetType().Name; } if (destinationType == typeof(InstanceDescriptor)) { if (value is XmlMessageFormatter) { XmlMessageFormatter f = (XmlMessageFormatter)value; ConstructorInfo ctor = typeof(XmlMessageFormatter).GetConstructor(new Type[] {typeof(string[])}); if (ctor != null) { return new InstanceDescriptor(ctor, new object[] {f.TargetTypeNames}); } } else if (value is ActiveXMessageFormatter) { ConstructorInfo ctor = typeof(ActiveXMessageFormatter).GetConstructor(new Type[0]); if (ctor != null) { return new InstanceDescriptor(ctor, new object[0]); } } else if (value is BinaryMessageFormatter) { BinaryMessageFormatter f = (BinaryMessageFormatter)value; ConstructorInfo ctor = typeof(BinaryMessageFormatter).GetConstructor(new Type[] { typeof(FormatterAssemblyStyle), typeof(FormatterTypeStyle)}); if (ctor != null) { return new InstanceDescriptor(ctor, new object[] {f.TopObjectFormat, f.TypeFormat}); } } } return base.ConvertTo(context, culture, value, destinationType); } /// /// public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context) { StandardValuesCollection values = new StandardValuesCollection(new object[] {new ActiveXMessageFormatter(), new BinaryMessageFormatter(), new XmlMessageFormatter(), null}); return values; } public override bool GetStandardValuesExclusive(ITypeDescriptorContext context) { return true; } /// /// public override bool GetStandardValuesSupported(ITypeDescriptorContext context) { return 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
- ContextMenuStripGroup.cs
- HasCopySemanticsAttribute.cs
- ProviderException.cs
- ToolStripContainerActionList.cs
- CodeArrayIndexerExpression.cs
- OptionUsage.cs
- UTF7Encoding.cs
- ContentType.cs
- RawKeyboardInputReport.cs
- WebPartUserCapability.cs
- BuildProvider.cs
- ISAPIWorkerRequest.cs
- TempEnvironment.cs
- OdbcInfoMessageEvent.cs
- WinFormsComponentEditor.cs
- DataGridViewTextBoxColumn.cs
- DbgUtil.cs
- DbConnectionPoolGroupProviderInfo.cs
- XmlTypeMapping.cs
- ThicknessAnimation.cs
- PlanCompilerUtil.cs
- PartialCachingControl.cs
- ReflectionPermission.cs
- AppDomainEvidenceFactory.cs
- ColorAnimation.cs
- _TimerThread.cs
- SocketElement.cs
- EmptyWorkItem.cs
- SubpageParaClient.cs
- SettingsProperty.cs
- BaseParaClient.cs
- ChildrenQuery.cs
- InstanceNormalEvent.cs
- RegistrySecurity.cs
- StandardOleMarshalObject.cs
- MeasurementDCInfo.cs
- ReadOnlyNameValueCollection.cs
- DiagnosticsConfigurationHandler.cs
- AutoGeneratedField.cs
- MouseDevice.cs
- CodeTryCatchFinallyStatement.cs
- XhtmlBasicImageAdapter.cs
- ThreadInterruptedException.cs
- XmlSchemas.cs
- ComponentSerializationService.cs
- SchemaInfo.cs
- ClientUrlResolverWrapper.cs
- FileLoadException.cs
- QilPatternFactory.cs
- SQLBoolean.cs
- HtmlTableCell.cs
- FileDialogCustomPlace.cs
- HGlobalSafeHandle.cs
- SQLInt16.cs
- ImageBrush.cs
- loginstatus.cs
- SimpleWebHandlerParser.cs
- NativeMsmqMessage.cs
- GPStream.cs
- WindowsGraphicsCacheManager.cs
- ToolStripSettings.cs
- MouseOverProperty.cs
- PermissionListSet.cs
- EncodingTable.cs
- DocumentDesigner.cs
- DataGridViewDataErrorEventArgs.cs
- SystemWebExtensionsSectionGroup.cs
- XmlElementElementCollection.cs
- DesignTimeTemplateParser.cs
- DocumentSequence.cs
- WizardStepBase.cs
- DTCTransactionManager.cs
- ValueSerializer.cs
- ReadOnlyCollection.cs
- Mappings.cs
- StylusPointDescription.cs
- SqlBuffer.cs
- SchemaSetCompiler.cs
- _BasicClient.cs
- TextEditorTables.cs
- HttpDictionary.cs
- SegmentInfo.cs
- WebServiceParameterData.cs
- DbProviderFactoriesConfigurationHandler.cs
- SendingRequestEventArgs.cs
- EditCommandColumn.cs
- UInt16.cs
- StorageFunctionMapping.cs
- DragDropHelper.cs
- Panel.cs
- XmlElement.cs
- KeyValueConfigurationCollection.cs
- InteropAutomationProvider.cs
- ControlIdConverter.cs
- Transaction.cs
- AsyncOperationLifetimeManager.cs
- TypedElement.cs
- QueryOutputWriterV1.cs
- TableItemProviderWrapper.cs
- XmlIncludeAttribute.cs