Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / 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
- Emitter.cs
- X509SubjectKeyIdentifierClause.cs
- FixedSOMTableRow.cs
- ComboBox.cs
- FieldNameLookup.cs
- WebSysDisplayNameAttribute.cs
- ReaderWriterLockWrapper.cs
- HierarchicalDataBoundControlAdapter.cs
- HTMLTagNameToTypeMapper.cs
- ToolStripProfessionalLowResolutionRenderer.cs
- CodeMethodReturnStatement.cs
- RepeatBehaviorConverter.cs
- WebScriptServiceHost.cs
- GridViewDeletedEventArgs.cs
- FlowDocumentView.cs
- WebPartDisplayModeCancelEventArgs.cs
- DataColumnMappingCollection.cs
- EntityDataSourceStatementEditorForm.cs
- WSUtilitySpecificationVersion.cs
- SqlDataSourceCommandEventArgs.cs
- StateBag.cs
- SmtpSpecifiedPickupDirectoryElement.cs
- SqlLiftIndependentRowExpressions.cs
- BitmapEffectCollection.cs
- SQLInt64Storage.cs
- ChangesetResponse.cs
- OutOfProcStateClientManager.cs
- RectAnimationClockResource.cs
- SqlFormatter.cs
- ControlBindingsCollection.cs
- TypeConstant.cs
- _TLSstream.cs
- ListBindableAttribute.cs
- AnnotationComponentManager.cs
- AssemblyBuilderData.cs
- HtmlInputImage.cs
- TemplateComponentConnector.cs
- ArgumentException.cs
- DBCommandBuilder.cs
- _TLSstream.cs
- Matrix.cs
- TextTreeTextNode.cs
- CompositeControl.cs
- DataGridViewRowCollection.cs
- PropertyValueChangedEvent.cs
- Activity.cs
- TypeAccessException.cs
- CollectionViewSource.cs
- OleServicesContext.cs
- IImplicitResourceProvider.cs
- IsolatedStorage.cs
- SqlRetyper.cs
- GlobalAllocSafeHandle.cs
- ServiceDescription.cs
- StringFormat.cs
- ServerIdentity.cs
- OutOfMemoryException.cs
- UIElementAutomationPeer.cs
- SQLBytesStorage.cs
- SoapObjectInfo.cs
- SystemInfo.cs
- ShapingWorkspace.cs
- CompensationDesigner.cs
- ModelItemImpl.cs
- WindowHideOrCloseTracker.cs
- OrthographicCamera.cs
- DbDataReader.cs
- DetailsViewCommandEventArgs.cs
- WarningException.cs
- MatrixAnimationUsingKeyFrames.cs
- IWorkflowDebuggerService.cs
- CommandBinding.cs
- StorageEntitySetMapping.cs
- Base64Encoder.cs
- SQLInt32.cs
- baseaxisquery.cs
- COM2ICategorizePropertiesHandler.cs
- ToolBar.cs
- SQLDecimal.cs
- ColorConvertedBitmap.cs
- TemplateBuilder.cs
- MiniModule.cs
- BitmapFrameDecode.cs
- FastEncoderWindow.cs
- UniqueSet.cs
- BindableTemplateBuilder.cs
- LinkTarget.cs
- TdsParserStateObject.cs
- RadioButtonBaseAdapter.cs
- InputScopeAttribute.cs
- PhysicalFontFamily.cs
- CacheHelper.cs
- DropDownHolder.cs
- SqlUDTStorage.cs
- InternalBase.cs
- DynamicRendererThreadManager.cs
- ExternalFile.cs
- RowBinding.cs
- ReadWriteSpinLock.cs
- DependencyObject.cs