Code:
/ Net / Net / 3.5.50727.3053 / DEVDIV / depot / DevDiv / releases / Orcas / SP / wpf / src / Framework / System / Windows / ResourceReferenceExpressionConverter.cs / 1 / ResourceReferenceExpressionConverter.cs
//----------------------------------------------------------------------------
//
// File: ResourceReferenceExpressionConverter.cs
//
// Description:
// TypeConverter for a resource value expression
//
// Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Globalization;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Windows;
namespace System.Windows.Markup
{
///
/// TypeConverter for a resource value expression
///
public class ResourceReferenceExpressionConverter : ExpressionConverter
{
///
/// TypeConverter method override.
///
///
/// ITypeDescriptorContext
///
///
/// Type to convert from
///
///
/// true if conversion is possible
///
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return base.CanConvertFrom(context, sourceType);
}
///
/// TypeConverter method override.
///
///
/// For avalon serialization this converter
/// returns true for string types only if the
/// target element with the resource
/// dictionary for the current resource
/// reference is also being serialized. Else
/// it returns false and the serialization
/// engine must serialize the evaluated
/// value of the expression.
///
///
/// ITypeDescriptorContext
///
///
/// Type to convert to
///
///
/// true if conversion is possible
///
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
// Validate Input Arguments
if (destinationType == null)
{
throw new ArgumentNullException("destinationType");
}
//MarkupExtention
if (destinationType == typeof(MarkupExtension))
return true;
return base.CanConvertTo(context, destinationType);
}
///
/// TypeConverter method implementation.
///
///
/// ITypeDescriptorContext
///
///
/// current culture (see CLR specs)
///
///
/// value to convert from
///
///
/// value that is result of conversion
///
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return base.ConvertFrom(context, culture, value);
}
///
/// TypeConverter method implementation.
///
///
/// ITypeDescriptorContext
///
///
/// current culture (see CLR specs)
///
///
/// value to convert from
///
///
/// Type to convert to
///
///
/// converted value
///
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
// Validate Input Arguments
ResourceReferenceExpression expr = value as ResourceReferenceExpression;
if (expr == null)
{
throw new ArgumentException(SR.Get(SRID.MustBeOfType, "value", "ResourceReferenceExpression"));
}
if (destinationType == null)
{
throw new ArgumentNullException("destinationType");
}
// MarkupExtension
if (destinationType == typeof(MarkupExtension))
{
return new DynamicResourceExtension(expr.ResourceKey);
}
return base.ConvertTo(context, culture, value, destinationType);
}
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// File: ResourceReferenceExpressionConverter.cs
//
// Description:
// TypeConverter for a resource value expression
//
// Copyright (C) 2003 by Microsoft Corporation. All rights reserved.
//
//---------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Globalization;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Windows;
namespace System.Windows.Markup
{
///
/// TypeConverter for a resource value expression
///
public class ResourceReferenceExpressionConverter : ExpressionConverter
{
///
/// TypeConverter method override.
///
///
/// ITypeDescriptorContext
///
///
/// Type to convert from
///
///
/// true if conversion is possible
///
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return base.CanConvertFrom(context, sourceType);
}
///
/// TypeConverter method override.
///
///
/// For avalon serialization this converter
/// returns true for string types only if the
/// target element with the resource
/// dictionary for the current resource
/// reference is also being serialized. Else
/// it returns false and the serialization
/// engine must serialize the evaluated
/// value of the expression.
///
///
/// ITypeDescriptorContext
///
///
/// Type to convert to
///
///
/// true if conversion is possible
///
public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
{
// Validate Input Arguments
if (destinationType == null)
{
throw new ArgumentNullException("destinationType");
}
//MarkupExtention
if (destinationType == typeof(MarkupExtension))
return true;
return base.CanConvertTo(context, destinationType);
}
///
/// TypeConverter method implementation.
///
///
/// ITypeDescriptorContext
///
///
/// current culture (see CLR specs)
///
///
/// value to convert from
///
///
/// value that is result of conversion
///
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
return base.ConvertFrom(context, culture, value);
}
///
/// TypeConverter method implementation.
///
///
/// ITypeDescriptorContext
///
///
/// current culture (see CLR specs)
///
///
/// value to convert from
///
///
/// Type to convert to
///
///
/// converted value
///
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
// Validate Input Arguments
ResourceReferenceExpression expr = value as ResourceReferenceExpression;
if (expr == null)
{
throw new ArgumentException(SR.Get(SRID.MustBeOfType, "value", "ResourceReferenceExpression"));
}
if (destinationType == null)
{
throw new ArgumentNullException("destinationType");
}
// MarkupExtension
if (destinationType == typeof(MarkupExtension))
{
return new DynamicResourceExtension(expr.ResourceKey);
}
return base.ConvertTo(context, culture, 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
- WhileDesigner.cs
- ResumeStoryboard.cs
- DesignerOptions.cs
- Matrix3DConverter.cs
- PenThreadWorker.cs
- XMLUtil.cs
- ObjectReferenceStack.cs
- XslTransformFileEditor.cs
- WebPartUtil.cs
- WebPartZoneCollection.cs
- GridEntryCollection.cs
- WebEventTraceProvider.cs
- StringPropertyBuilder.cs
- TextBoxLine.cs
- TypeExtensionConverter.cs
- WmpBitmapEncoder.cs
- RTLAwareMessageBox.cs
- SmtpDigestAuthenticationModule.cs
- HttpListenerRequestTraceRecord.cs
- ToolBarPanel.cs
- SchemaAttDef.cs
- Win32.cs
- VisualTarget.cs
- Matrix3DStack.cs
- XsltSettings.cs
- _SslState.cs
- OleDbConnectionFactory.cs
- Tuple.cs
- basemetadatamappingvisitor.cs
- SelectionEditor.cs
- newitemfactory.cs
- MediaTimeline.cs
- ComAwareEventInfo.cs
- OutputCacheSettings.cs
- CredentialCache.cs
- WorkflowItemPresenter.cs
- LeftCellWrapper.cs
- CreateUserWizardStep.cs
- TreeNodeStyleCollection.cs
- MouseActionValueSerializer.cs
- COM2PictureConverter.cs
- _ProxyRegBlob.cs
- TextProperties.cs
- OutputScope.cs
- DataGridCellItemAutomationPeer.cs
- ToggleButton.cs
- SynchronizationContext.cs
- HostingEnvironmentSection.cs
- AuthorizationRuleCollection.cs
- CachingHintValidation.cs
- PropertyNames.cs
- OdbcPermission.cs
- TreeNodeBinding.cs
- JulianCalendar.cs
- Misc.cs
- ToolStripRenderEventArgs.cs
- UriPrefixTable.cs
- OAVariantLib.cs
- SecureStringHasher.cs
- AssociationType.cs
- LineSegment.cs
- EncoderParameter.cs
- UpdateException.cs
- OperationAbortedException.cs
- _NegoState.cs
- ValueUnavailableException.cs
- RSAPKCS1SignatureDeformatter.cs
- BCLDebug.cs
- ProviderSettings.cs
- AdPostCacheSubstitution.cs
- SerializableAttribute.cs
- Column.cs
- InputLanguageCollection.cs
- Application.cs
- DeclarationUpdate.cs
- NumericPagerField.cs
- PackagePart.cs
- MembershipPasswordException.cs
- EventLogPermissionEntry.cs
- ItemsControl.cs
- WebPartExportVerb.cs
- EFTableProvider.cs
- GeometryDrawing.cs
- SettingsAttributes.cs
- BitmapDecoder.cs
- DebugViewWriter.cs
- ParserHooks.cs
- ExpressionReplacer.cs
- PrintPreviewControl.cs
- Point4DValueSerializer.cs
- WebContentFormatHelper.cs
- SimpleRecyclingCache.cs
- PrivacyNoticeBindingElement.cs
- ControlCachePolicy.cs
- TextBoxLine.cs
- PropertyPathConverter.cs
- ParallelQuery.cs
- UnionQueryOperator.cs
- FormsAuthenticationConfiguration.cs
- GeometryHitTestParameters.cs