Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Framework / System / Windows / ResourceReferenceExpressionConverter.cs / 1305600 / 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
- XhtmlBasicPanelAdapter.cs
- TextEffect.cs
- SafeNativeMethods.cs
- PageBreakRecord.cs
- FileUtil.cs
- SmiEventStream.cs
- MultipartIdentifier.cs
- SqlFactory.cs
- WebHttpEndpoint.cs
- ConvertTextFrag.cs
- XmlEventCache.cs
- SchemaNames.cs
- PerformanceCounterManager.cs
- ExtractedStateEntry.cs
- Calendar.cs
- SimpleType.cs
- ContainerControl.cs
- HierarchicalDataBoundControlAdapter.cs
- SourceElementsCollection.cs
- TemplateBindingExpression.cs
- BuildProviderAppliesToAttribute.cs
- DetailsViewCommandEventArgs.cs
- CollectionViewGroupInternal.cs
- ParameterCollection.cs
- Token.cs
- StateDesigner.cs
- GridViewActionList.cs
- StyleSheetRefUrlEditor.cs
- XsdBuildProvider.cs
- RemoteWebConfigurationHostStream.cs
- ConditionValidator.cs
- ConfigurationSchemaErrors.cs
- ListCollectionView.cs
- OperandQuery.cs
- BitFlagsGenerator.cs
- Attributes.cs
- CursorConverter.cs
- ExecutionEngineException.cs
- XmlImplementation.cs
- SingleStorage.cs
- StreamGeometryContext.cs
- WebBrowser.cs
- ResourceDisplayNameAttribute.cs
- ZipFileInfoCollection.cs
- DataListItemEventArgs.cs
- IndexOutOfRangeException.cs
- NumberFormatter.cs
- _TLSstream.cs
- HandleCollector.cs
- Attribute.cs
- FilterQueryOptionExpression.cs
- Cursors.cs
- SystemFonts.cs
- TagMapInfo.cs
- SourceItem.cs
- Point4DValueSerializer.cs
- ExceptQueryOperator.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- AsyncOperation.cs
- RenderOptions.cs
- StyleSheet.cs
- RunClient.cs
- SQLChars.cs
- HebrewCalendar.cs
- CompositeDataBoundControl.cs
- OrthographicCamera.cs
- AutomationPropertyInfo.cs
- filewebresponse.cs
- OdbcConnectionPoolProviderInfo.cs
- ZoomPercentageConverter.cs
- LockedBorderGlyph.cs
- XmlSerializationWriter.cs
- CrossAppDomainChannel.cs
- DynamicField.cs
- XhtmlBasicValidationSummaryAdapter.cs
- CipherData.cs
- SchemaImporterExtension.cs
- FontNamesConverter.cs
- InternalSafeNativeMethods.cs
- Logging.cs
- TextCollapsingProperties.cs
- Bitmap.cs
- NotifyInputEventArgs.cs
- BackgroundFormatInfo.cs
- RuleConditionDialog.cs
- ParallelEnumerableWrapper.cs
- MenuCommand.cs
- SerializationInfoEnumerator.cs
- DataGridCommandEventArgs.cs
- httpstaticobjectscollection.cs
- Style.cs
- AnnotationDocumentPaginator.cs
- XhtmlBasicLabelAdapter.cs
- HtmlWindow.cs
- ToolStripDropDownClosingEventArgs.cs
- WebResponse.cs
- TabletDeviceInfo.cs
- OleDbPropertySetGuid.cs
- XmlExceptionHelper.cs
- TransformerInfoCollection.cs