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 / Animation / RepeatBehaviorConverter.cs / 1 / RepeatBehaviorConverter.cs
//------------------------------------------------------------------------------
// Microsoft Windows Client Platform
// Copyright (c) Microsoft Corporation, 2004
//
// File: RepeatBehaviorConverter.cs
//-----------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Security;
namespace System.Windows.Media.Animation
{
///
///
///
public sealed class RepeatBehaviorConverter : TypeConverter
{
#region Data
private static char[] _iterationCharacter = new char[] { 'x' };
#endregion
///
/// 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;
}
else
{
return false;
}
}
///
/// ConvertFrom
///
///
public override object ConvertFrom(
ITypeDescriptorContext td,
CultureInfo cultureInfo,
object value)
{
string stringValue = value as string;
if (stringValue != null)
{
stringValue = stringValue.Trim();
if (stringValue == "Forever")
{
return RepeatBehavior.Forever;
}
else if ( stringValue.Length > 0
&& stringValue[stringValue.Length - 1] == _iterationCharacter[0])
{
string stringDoubleValue = stringValue.TrimEnd(_iterationCharacter);
double doubleValue = (double)TypeDescriptor.GetConverter(typeof(double)).ConvertFrom(td, cultureInfo, stringDoubleValue);
return new RepeatBehavior(doubleValue);
}
}
// The value is not Forever or an iteration count so it's either a TimeSpan
// or we'll let the TimeSpanConverter raise the appropriate exception.
TimeSpan timeSpanValue = (TimeSpan)TypeDescriptor.GetConverter(typeof(TimeSpan)).ConvertFrom(td, cultureInfo, stringValue);
return new RepeatBehavior(timeSpanValue);
}
///
/// 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 RepeatBehavior, not an arbitrary class
///
[SecurityCritical]
public override object ConvertTo(
ITypeDescriptorContext context,
CultureInfo cultureInfo,
object value,
Type destinationType)
{
if ( value is RepeatBehavior
&& destinationType != null)
{
RepeatBehavior repeatBehavior = (RepeatBehavior)value;
if (destinationType == typeof(InstanceDescriptor))
{
MemberInfo mi;
if (repeatBehavior == RepeatBehavior.Forever)
{
mi = typeof(RepeatBehavior).GetProperty("Forever");
return new InstanceDescriptor(mi, null);
}
else if (repeatBehavior.HasCount)
{
mi = typeof(RepeatBehavior).GetConstructor(new Type[] { typeof(double) });
return new InstanceDescriptor(mi, new object[] { repeatBehavior.Count });
}
else if (repeatBehavior.HasDuration)
{
mi = typeof(RepeatBehavior).GetConstructor(new Type[] { typeof(TimeSpan) });
return new InstanceDescriptor(mi, new object[] { repeatBehavior.Duration });
}
else
{
Debug.Fail("Unknown type of RepeatBehavior passed to RepeatBehaviorConverter.");
}
}
else if (destinationType == typeof(string))
{
return repeatBehavior.InternalToString(null, cultureInfo);
}
}
// We can't do the conversion, let the base class raise the
// appropriate exception.
return base.ConvertTo(context, cultureInfo, value, destinationType);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//------------------------------------------------------------------------------
// Microsoft Windows Client Platform
// Copyright (c) Microsoft Corporation, 2004
//
// File: RepeatBehaviorConverter.cs
//-----------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Security;
namespace System.Windows.Media.Animation
{
///
///
///
public sealed class RepeatBehaviorConverter : TypeConverter
{
#region Data
private static char[] _iterationCharacter = new char[] { 'x' };
#endregion
///
/// 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;
}
else
{
return false;
}
}
///
/// ConvertFrom
///
///
public override object ConvertFrom(
ITypeDescriptorContext td,
CultureInfo cultureInfo,
object value)
{
string stringValue = value as string;
if (stringValue != null)
{
stringValue = stringValue.Trim();
if (stringValue == "Forever")
{
return RepeatBehavior.Forever;
}
else if ( stringValue.Length > 0
&& stringValue[stringValue.Length - 1] == _iterationCharacter[0])
{
string stringDoubleValue = stringValue.TrimEnd(_iterationCharacter);
double doubleValue = (double)TypeDescriptor.GetConverter(typeof(double)).ConvertFrom(td, cultureInfo, stringDoubleValue);
return new RepeatBehavior(doubleValue);
}
}
// The value is not Forever or an iteration count so it's either a TimeSpan
// or we'll let the TimeSpanConverter raise the appropriate exception.
TimeSpan timeSpanValue = (TimeSpan)TypeDescriptor.GetConverter(typeof(TimeSpan)).ConvertFrom(td, cultureInfo, stringValue);
return new RepeatBehavior(timeSpanValue);
}
///
/// 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 RepeatBehavior, not an arbitrary class
///
[SecurityCritical]
public override object ConvertTo(
ITypeDescriptorContext context,
CultureInfo cultureInfo,
object value,
Type destinationType)
{
if ( value is RepeatBehavior
&& destinationType != null)
{
RepeatBehavior repeatBehavior = (RepeatBehavior)value;
if (destinationType == typeof(InstanceDescriptor))
{
MemberInfo mi;
if (repeatBehavior == RepeatBehavior.Forever)
{
mi = typeof(RepeatBehavior).GetProperty("Forever");
return new InstanceDescriptor(mi, null);
}
else if (repeatBehavior.HasCount)
{
mi = typeof(RepeatBehavior).GetConstructor(new Type[] { typeof(double) });
return new InstanceDescriptor(mi, new object[] { repeatBehavior.Count });
}
else if (repeatBehavior.HasDuration)
{
mi = typeof(RepeatBehavior).GetConstructor(new Type[] { typeof(TimeSpan) });
return new InstanceDescriptor(mi, new object[] { repeatBehavior.Duration });
}
else
{
Debug.Fail("Unknown type of RepeatBehavior passed to RepeatBehaviorConverter.");
}
}
else if (destinationType == typeof(string))
{
return repeatBehavior.InternalToString(null, cultureInfo);
}
}
// We can't do the conversion, let the base class raise the
// appropriate exception.
return base.ConvertTo(context, cultureInfo, value, destinationType);
}
}
}
// 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
- OuterGlowBitmapEffect.cs
- TransactionManager.cs
- DbParameterHelper.cs
- CustomAttributeBuilder.cs
- securitycriticaldataClass.cs
- Stroke.cs
- NameSpaceEvent.cs
- QuaternionAnimation.cs
- QilReplaceVisitor.cs
- CryptoHelper.cs
- DataGridViewCell.cs
- MultipartContentParser.cs
- OracleTimeSpan.cs
- EventMappingSettingsCollection.cs
- CodeChecksumPragma.cs
- IFormattable.cs
- Vector3DAnimation.cs
- MediaTimeline.cs
- AssemblyBuilderData.cs
- TimerElapsedEvenArgs.cs
- TemplateKeyConverter.cs
- TargetFrameworkUtil.cs
- OleDbCommand.cs
- StringUtil.cs
- DefaultDiscoveryServiceExtension.cs
- ChildrenQuery.cs
- ParameterToken.cs
- OracleParameter.cs
- QilUnary.cs
- SafeNativeMemoryHandle.cs
- GregorianCalendar.cs
- TableParaClient.cs
- ParallelDesigner.cs
- DocumentAutomationPeer.cs
- CollectionConverter.cs
- CollectionBuilder.cs
- Attachment.cs
- BamlTreeMap.cs
- DataGridViewTextBoxColumn.cs
- messageonlyhwndwrapper.cs
- HashHelpers.cs
- RegexReplacement.cs
- Size.cs
- XmlNullResolver.cs
- WebPartManager.cs
- BinaryObjectReader.cs
- InsufficientMemoryException.cs
- BevelBitmapEffect.cs
- ResourcePermissionBaseEntry.cs
- NonVisualControlAttribute.cs
- EncryptedType.cs
- ISAPIWorkerRequest.cs
- CodeRemoveEventStatement.cs
- securitycriticaldataformultiplegetandset.cs
- IISMapPath.cs
- WebPartConnectionsConfigureVerb.cs
- DispatcherObject.cs
- TextRange.cs
- PeerResolverSettings.cs
- PerformanceCounterCategory.cs
- TypeSystem.cs
- TextRangeEdit.cs
- ByeOperationCD1AsyncResult.cs
- MatrixAnimationBase.cs
- Renderer.cs
- SqlCacheDependencyDatabaseCollection.cs
- Atom10FormatterFactory.cs
- DecimalStorage.cs
- LabelDesigner.cs
- ClientConfigPaths.cs
- WebPartsPersonalization.cs
- TemplatedMailWebEventProvider.cs
- ScopelessEnumAttribute.cs
- ObjectListGeneralPage.cs
- EFTableProvider.cs
- InternalCache.cs
- WindowsUpDown.cs
- ProcessInputEventArgs.cs
- TemplateControlBuildProvider.cs
- TypeConverterValueSerializer.cs
- ACL.cs
- XmlSchemas.cs
- PerfCounters.cs
- WriterOutput.cs
- FrameworkContentElement.cs
- MessageQueueConverter.cs
- LabelDesigner.cs
- DiscoveryReferences.cs
- SecurityTokenSerializer.cs
- ActivityMarkupSerializer.cs
- ColorAnimationUsingKeyFrames.cs
- DataControlImageButton.cs
- PeerNameResolver.cs
- SecurityKeyIdentifierClause.cs
- StateMachineWorkflowDesigner.cs
- CommandDevice.cs
- StringValidatorAttribute.cs
- CheckBoxField.cs
- ToolStripDropDownClosedEventArgs.cs
- MsmqProcessProtocolHandler.cs