Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Base / System / Windows / Input / KeyValueSerializer.cs / 1 / KeyValueSerializer.cs
//----------------------------------------------------------------------------
//
// File: KeyValueSerializer.cs
//
// Description:
//
// KeyValueSerializer: Serializes a key string to a string and vice-versa
//
// Features:
//
// History:
// 08/04/2005 created: Chuck Jazdzewski
//
// Copyright (C) 2005 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.ComponentModel; // for TypeConverter
using System.Globalization; // for CultureInfo
using System.Reflection;
using System.Windows;
using System.Windows.Input;
using System.Windows.Markup;
using System.Security.Permissions;
using MS.Utility;
namespace System.Windows.Input
{
///
/// Key Serializer class for serializing a Key
///
///
public class KeyValueSerializer : ValueSerializer
{
///
/// CanConvertFromString()
///
///
///
///
///
public override bool CanConvertFromString(string value, IValueSerializerContext context)
{
return true;
}
///
/// CanConvertToString()
///
///
///
///
///
public override bool CanConvertToString(object value, IValueSerializerContext context)
{
if (!(value is Key))
return false;
Key key = (Key)value;
return ((int)key >= (int)Key.None && (int)key <= (int)Key.OemClear);
}
///
/// ConvertFromString()
///
///
///
///
public override object ConvertFromString(string value, IValueSerializerContext context)
{
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Key));
if (converter != null)
return converter.ConvertFromString(value);
else
return base.ConvertFromString(value, context);
}
///
/// ConvertToString()
///
///
///
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Key));
if (converter != null)
return converter.ConvertToInvariantString(value);
else
return base.ConvertToString(value, context);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// File: KeyValueSerializer.cs
//
// Description:
//
// KeyValueSerializer: Serializes a key string to a string and vice-versa
//
// Features:
//
// History:
// 08/04/2005 created: Chuck Jazdzewski
//
// Copyright (C) 2005 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.ComponentModel; // for TypeConverter
using System.Globalization; // for CultureInfo
using System.Reflection;
using System.Windows;
using System.Windows.Input;
using System.Windows.Markup;
using System.Security.Permissions;
using MS.Utility;
namespace System.Windows.Input
{
///
/// Key Serializer class for serializing a Key
///
///
public class KeyValueSerializer : ValueSerializer
{
///
/// CanConvertFromString()
///
///
///
///
///
public override bool CanConvertFromString(string value, IValueSerializerContext context)
{
return true;
}
///
/// CanConvertToString()
///
///
///
///
///
public override bool CanConvertToString(object value, IValueSerializerContext context)
{
if (!(value is Key))
return false;
Key key = (Key)value;
return ((int)key >= (int)Key.None && (int)key <= (int)Key.OemClear);
}
///
/// ConvertFromString()
///
///
///
///
public override object ConvertFromString(string value, IValueSerializerContext context)
{
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Key));
if (converter != null)
return converter.ConvertFromString(value);
else
return base.ConvertFromString(value, context);
}
///
/// ConvertToString()
///
///
///
///
public override string ConvertToString(object value, IValueSerializerContext context)
{
TypeConverter converter = TypeDescriptor.GetConverter(typeof(Key));
if (converter != null)
return converter.ConvertToInvariantString(value);
else
return base.ConvertToString(value, context);
}
}
}
// 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
- DetailsViewUpdateEventArgs.cs
- ExeConfigurationFileMap.cs
- TemplateLookupAction.cs
- ObjectViewListener.cs
- HtmlPanelAdapter.cs
- ToggleProviderWrapper.cs
- MergablePropertyAttribute.cs
- TextBoxRenderer.cs
- DefaultAssemblyResolver.cs
- Trigger.cs
- ThreadExceptionDialog.cs
- Formatter.cs
- DataPager.cs
- PropertyDescriptor.cs
- GlyphRun.cs
- HiddenField.cs
- DetailsViewCommandEventArgs.cs
- DataObjectAttribute.cs
- XmlIlGenerator.cs
- ScaleTransform.cs
- StringDictionaryCodeDomSerializer.cs
- HelpExampleGenerator.cs
- ActivityBindForm.Designer.cs
- PageFunction.cs
- IdentitySection.cs
- PropertiesTab.cs
- WindowsListBox.cs
- TreeViewItemAutomationPeer.cs
- CounterSample.cs
- TraceHandler.cs
- BinaryMessageEncodingBindingElement.cs
- ellipse.cs
- FontStretches.cs
- PropertySegmentSerializer.cs
- DataSourceXmlElementAttribute.cs
- XamlSerializationHelper.cs
- EventLog.cs
- DbParameterCollectionHelper.cs
- SQLByteStorage.cs
- BatchParser.cs
- safemediahandle.cs
- PointHitTestParameters.cs
- DoubleCollectionConverter.cs
- RMPublishingDialog.cs
- SystemGatewayIPAddressInformation.cs
- FilteredDataSetHelper.cs
- ServiceReference.cs
- ExpressionWriter.cs
- MasterPageCodeDomTreeGenerator.cs
- Decorator.cs
- PropertyDescriptor.cs
- ExistsInCollection.cs
- SelectingProviderEventArgs.cs
- TextServicesDisplayAttributePropertyRanges.cs
- EventProviderWriter.cs
- AssociationEndMember.cs
- MissingMemberException.cs
- Scene3D.cs
- BuildTopDownAttribute.cs
- Mappings.cs
- DesignerOptions.cs
- DeleteHelper.cs
- BmpBitmapEncoder.cs
- IconBitmapDecoder.cs
- FigureParagraph.cs
- SamlConstants.cs
- ContainerUtilities.cs
- ViewStateModeByIdAttribute.cs
- ColorConvertedBitmap.cs
- ExtensionDataObject.cs
- CheckBox.cs
- MiniAssembly.cs
- EventProviderWriter.cs
- ObjectDataSourceDisposingEventArgs.cs
- PersonalizationProvider.cs
- RefreshPropertiesAttribute.cs
- ErrorEventArgs.cs
- BinHexDecoder.cs
- XPathSingletonIterator.cs
- PassportPrincipal.cs
- AssertFilter.cs
- XmlNamespaceMappingCollection.cs
- StyleBamlRecordReader.cs
- StickyNote.cs
- MediaPlayerState.cs
- Splitter.cs
- RuntimeConfigLKG.cs
- Splitter.cs
- CollectionViewGroupInternal.cs
- DesignerDataTableBase.cs
- ThemeDictionaryExtension.cs
- X509Utils.cs
- DialogResultConverter.cs
- PerformanceCounterPermission.cs
- TimeSpanSecondsConverter.cs
- BuildResultCache.cs
- URL.cs
- WindowsIdentity.cs
- MetadataElement.cs
- RepeatButtonAutomationPeer.cs