Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Core / CSharp / System / Windows / Media / PixelFormatConverter.cs / 1 / PixelFormatConverter.cs
//------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, 2001 // // File: PixelFormatConverter.cs // //----------------------------------------------------------------------------- using System; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Reflection; using MS.Internal; using System.Text; using System.Collections; using System.Globalization; using System.Windows; using System.Windows.Media; using System.Runtime.InteropServices; using System.Diagnostics; using System.Security; using SR=MS.Internal.PresentationCore.SR; using SRID=MS.Internal.PresentationCore.SRID; namespace System.Windows.Media { #region PixelFormatConverter //----------------------------------------------------------------------------- // PixelFormatConverter //----------------------------------------------------------------------------- ////// PixelFormatConverter /// public sealed class PixelFormatConverter : TypeConverter { ////// CanConvertFrom - Returns whether or not this class can convert from a given type /// public override bool CanConvertFrom(ITypeDescriptorContext td, Type t) { if (t == typeof(string)) { return true; } else { return false; } } ////// TypeConverter method override. /// /// ITypeDescriptorContext /// Type to convert to ///true if conversion is possible public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor) || destinationType == typeof(string)) { return true; } return base.CanConvertTo(context, destinationType); } ////// test /// public new object ConvertFromString(String value) { if ( null == value) { return null; } return new PixelFormat (value); } ////// test /// public override object ConvertFrom(ITypeDescriptorContext td, System.Globalization.CultureInfo ci, object o) { if ( null == o) { return null; } return new PixelFormat(o as string); } ////// TypeConverter method implementation. /// /// ITypeDescriptorContext /// current culture (see CLR specs) /// value to convert from /// Type to convert to ///converted value ////// Critical: calls InstanceDescriptor ctor which LinkDemands /// PublicOK: can only make an InstanceDescriptor for PixelFormat, not an arbitrary class /// [SecurityCritical] public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (null == destinationType) { throw new ArgumentNullException("destinationType"); } if (null == value) { throw new ArgumentNullException("value"); } if (!(value is PixelFormat)) { throw new ArgumentException(SR.Get(SRID.General_Expected_Type,"PixelFormat")); } if (destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(PixelFormat).GetConstructor(new Type[]{typeof(string)}); PixelFormat p = (PixelFormat)value; return new InstanceDescriptor(ci, new object[]{p.ToString()}); } else if (destinationType == typeof(string)) { PixelFormat p = (PixelFormat)value; return p.ToString (); } return base.ConvertTo(context, culture, value, destinationType); } } #endregion // PixelFormatConverter } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. //------------------------------------------------------------------------------ // Microsoft Avalon // Copyright (c) Microsoft Corporation, 2001 // // File: PixelFormatConverter.cs // //----------------------------------------------------------------------------- using System; using System.ComponentModel; using System.ComponentModel.Design.Serialization; using System.Reflection; using MS.Internal; using System.Text; using System.Collections; using System.Globalization; using System.Windows; using System.Windows.Media; using System.Runtime.InteropServices; using System.Diagnostics; using System.Security; using SR=MS.Internal.PresentationCore.SR; using SRID=MS.Internal.PresentationCore.SRID; namespace System.Windows.Media { #region PixelFormatConverter //----------------------------------------------------------------------------- // PixelFormatConverter //----------------------------------------------------------------------------- ////// PixelFormatConverter /// public sealed class PixelFormatConverter : TypeConverter { ////// CanConvertFrom - Returns whether or not this class can convert from a given type /// public override bool CanConvertFrom(ITypeDescriptorContext td, Type t) { if (t == typeof(string)) { return true; } else { return false; } } ////// TypeConverter method override. /// /// ITypeDescriptorContext /// Type to convert to ///true if conversion is possible public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType) { if (destinationType == typeof(InstanceDescriptor) || destinationType == typeof(string)) { return true; } return base.CanConvertTo(context, destinationType); } ////// test /// public new object ConvertFromString(String value) { if ( null == value) { return null; } return new PixelFormat (value); } ////// test /// public override object ConvertFrom(ITypeDescriptorContext td, System.Globalization.CultureInfo ci, object o) { if ( null == o) { return null; } return new PixelFormat(o as string); } ////// TypeConverter method implementation. /// /// ITypeDescriptorContext /// current culture (see CLR specs) /// value to convert from /// Type to convert to ///converted value ////// Critical: calls InstanceDescriptor ctor which LinkDemands /// PublicOK: can only make an InstanceDescriptor for PixelFormat, not an arbitrary class /// [SecurityCritical] public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (null == destinationType) { throw new ArgumentNullException("destinationType"); } if (null == value) { throw new ArgumentNullException("value"); } if (!(value is PixelFormat)) { throw new ArgumentException(SR.Get(SRID.General_Expected_Type,"PixelFormat")); } if (destinationType == typeof(InstanceDescriptor)) { ConstructorInfo ci = typeof(PixelFormat).GetConstructor(new Type[]{typeof(string)}); PixelFormat p = (PixelFormat)value; return new InstanceDescriptor(ci, new object[]{p.ToString()}); } else if (destinationType == typeof(string)) { PixelFormat p = (PixelFormat)value; return p.ToString (); } return base.ConvertTo(context, culture, value, destinationType); } } #endregion // PixelFormatConverter } // 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
- _AutoWebProxyScriptWrapper.cs
- Annotation.cs
- RegexCompiler.cs
- RtfControls.cs
- Clipboard.cs
- TraceInternal.cs
- StructureChangedEventArgs.cs
- VisualBrush.cs
- Decoder.cs
- GrowingArray.cs
- DbProviderSpecificTypePropertyAttribute.cs
- TextEditorMouse.cs
- UpdatableGenericsFeature.cs
- Expr.cs
- TargetConverter.cs
- CharacterShapingProperties.cs
- Win32KeyboardDevice.cs
- AttributeEmitter.cs
- ComponentTray.cs
- SettingsSection.cs
- WindowsListViewItem.cs
- IpcChannel.cs
- DoubleAnimation.cs
- BaseParser.cs
- TraceHwndHost.cs
- GeneralTransform2DTo3DTo2D.cs
- CreateDataSourceDialog.cs
- UnsafeNativeMethods.cs
- MediaElementAutomationPeer.cs
- DataGridViewAutoSizeColumnsModeEventArgs.cs
- ResourceContainer.cs
- EnvelopeVersion.cs
- IPGlobalProperties.cs
- TypeConverterMarkupExtension.cs
- ToolStripProgressBar.cs
- SafeNativeMemoryHandle.cs
- Zone.cs
- ListParagraph.cs
- WebRequestModuleElementCollection.cs
- TextLineBreak.cs
- BufferedGraphicsManager.cs
- DesignerHelpers.cs
- CommandBinding.cs
- SqlClientWrapperSmiStreamChars.cs
- TemplateControlCodeDomTreeGenerator.cs
- LinkClickEvent.cs
- MsmqIntegrationValidationBehavior.cs
- ConfigXmlComment.cs
- SqlConnectionHelper.cs
- SelectionItemPattern.cs
- DataBindingHandlerAttribute.cs
- NumberFunctions.cs
- FlowDocumentPageViewerAutomationPeer.cs
- CrossContextChannel.cs
- RegexRunner.cs
- ADRole.cs
- SqlUDTStorage.cs
- StyleModeStack.cs
- IndexedDataBuffer.cs
- SqlCacheDependency.cs
- SelectionChangedEventArgs.cs
- EncryptedPackage.cs
- AdCreatedEventArgs.cs
- ProcessThreadCollection.cs
- EventRouteFactory.cs
- RangeValuePattern.cs
- GroupByQueryOperator.cs
- counter.cs
- DefaultTextStore.cs
- XmlDictionaryWriter.cs
- OleDbTransaction.cs
- WhitespaceReader.cs
- SynchronizationScope.cs
- MetadataArtifactLoaderFile.cs
- ObsoleteAttribute.cs
- ShadowGlyph.cs
- GridItem.cs
- Gdiplus.cs
- PasswordRecoveryDesigner.cs
- MailMessage.cs
- AudioBase.cs
- LineServicesRun.cs
- EditCommandColumn.cs
- DirectionalLight.cs
- Serializer.cs
- DataSourceSelectArguments.cs
- XhtmlCssHandler.cs
- SmiEventSink_Default.cs
- UnionQueryOperator.cs
- wgx_commands.cs
- SendMailErrorEventArgs.cs
- TaiwanLunisolarCalendar.cs
- VisualCollection.cs
- HttpCapabilitiesBase.cs
- ProfileEventArgs.cs
- MailFileEditor.cs
- InheritedPropertyChangedEventArgs.cs
- RequestedSignatureDialog.cs
- ResourceReader.cs
- IdentityReference.cs