Code:
/ Dotnetfx_Win7_3.5.1 / Dotnetfx_Win7_3.5.1 / 3.5.1 / DEVDIV / depot / DevDiv / releases / Orcas / NetFXw7 / wpf / src / Framework / System / Windows / Documents / DPTypeDescriptorContext.cs / 1 / DPTypeDescriptorContext.cs
//----------------------------------------------------------------------------
//
// File: TextRangeSerialization.cs
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// Description: Set of static methods implementing text range serialization
//
//---------------------------------------------------------------------------
namespace System.Windows.Documents
{
using MS.Internal;
using System.Windows;
using System.Globalization;
using System.Windows.Media;
///
/// An object implementing ITypeDescriptorContext intended to be used in serialization
/// scenarios for checking whether a particular value can be converted to a string
///
internal class DPTypeDescriptorContext : System.ComponentModel.ITypeDescriptorContext
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
private DPTypeDescriptorContext(DependencyProperty property, object propertyValue)
{
Invariant.Assert(property != null, "property == null");
Invariant.Assert(propertyValue != null, "propertyValue == null");
Invariant.Assert(property.IsValidValue(propertyValue), "propertyValue must be of suitable type for the given dependency property");
_property = property;
_propertyValue = propertyValue;
}
#endregion Constructors
//------------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
// Returns non-null string if this value can be converted to a string,
// null otherwise.
internal static string GetStringValue(DependencyProperty property, object propertyValue)
{
string stringValue = null;
// Special cases working around incorrectly implemented type converters
if (property == UIElement.BitmapEffectProperty)
{
return null; // Always treat BitmapEffects as complex value
}
if (property == Inline.TextDecorationsProperty)
{
stringValue = TextDecorationsFixup((TextDecorationCollection)propertyValue);
}
else if (typeof(CultureInfo).IsAssignableFrom(property.PropertyType)) //NumberSubstitution.CultureOverrideProperty
{
stringValue = CultureInfoFixup(property, (CultureInfo)propertyValue);
}
if (stringValue == null)
{
DPTypeDescriptorContext context = new DPTypeDescriptorContext(property, propertyValue);
System.ComponentModel.TypeConverter typeConverter = System.ComponentModel.TypeDescriptor.GetConverter(property.PropertyType);
Invariant.Assert(typeConverter != null);
if (typeConverter.CanConvertTo(context, typeof(string)))
{
stringValue = (string)typeConverter.ConvertTo(
context, System.Globalization.CultureInfo.InvariantCulture, propertyValue, typeof(string));
}
}
return stringValue;
}
#endregion Internal Methods
#region Private Methods
private static string TextDecorationsFixup(TextDecorationCollection textDecorations)
{
string stringValue = null;
// Work around for incorrect serialization for TextDecorations property
//
// Special case for TextDecorations serialization
if (TextDecorations.Underline.ValueEquals(textDecorations))
{
stringValue = "Underline";
}
else if (TextDecorations.Strikethrough.ValueEquals(textDecorations))
{
stringValue = "Strikethrough";
}
else if (TextDecorations.OverLine.ValueEquals(textDecorations))
{
stringValue = "OverLine";
}
else if (TextDecorations.Baseline.ValueEquals(textDecorations))
{
stringValue = "Baseline";
}
else if (textDecorations.Count == 0)
{
stringValue = string.Empty;
}
return stringValue;
}
private static string CultureInfoFixup(DependencyProperty property, CultureInfo cultureInfo)
{
string stringValue = null;
// Parser uses a specific type coverter for converting instances of other types to and from CultureInfo.
// This class differs from System.ComponentModel.CultureInfoConverter, the default type converter
// for the CultureInfo class.
// It uses a string representation based on the IetfLanguageTag property rather than the Name property
// (i.e., RFC 3066 rather than RFC 1766).
// In order to guarantee roundtripability of serialized xaml, textrange serialization needs to use
// this type coverter for CultureInfo types.
DPTypeDescriptorContext context = new DPTypeDescriptorContext(property, cultureInfo);
System.ComponentModel.TypeConverter typeConverter = new CultureInfoIetfLanguageTagConverter();
if (typeConverter.CanConvertTo(context, typeof(string)))
{
stringValue = (string)typeConverter.ConvertTo(
context, System.Globalization.CultureInfo.InvariantCulture, cultureInfo, typeof(string));
}
return stringValue;
}
#endregion Private Methods
//------------------------------------------------------
//
// Interface ITypeDescriptorContext
//
//------------------------------------------------------
#region ITypeDescriptorContext Members
System.ComponentModel.IContainer System.ComponentModel.ITypeDescriptorContext.Container
{
get { return null; }
}
// Returns a value of a property - to be detected for convertability to string in a type converter
object System.ComponentModel.ITypeDescriptorContext.Instance
{
get
{
return _propertyValue;
}
}
void System.ComponentModel.ITypeDescriptorContext.OnComponentChanged()
{
}
bool System.ComponentModel.ITypeDescriptorContext.OnComponentChanging()
{
return false;
}
System.ComponentModel.PropertyDescriptor System.ComponentModel.ITypeDescriptorContext.PropertyDescriptor
{
get { return null; }
}
#endregion
#region IServiceProvider Members
object IServiceProvider.GetService(Type serviceType)
{
return null;
}
#endregion
#region Private Fields
private DependencyProperty _property;
private object _propertyValue;
#endregion
}
}
// File provided for Reference Use Only by Microsoft Corporation (c) 2007.
// Copyright (c) Microsoft Corporation. All rights reserved.
//----------------------------------------------------------------------------
//
// File: TextRangeSerialization.cs
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// Description: Set of static methods implementing text range serialization
//
//---------------------------------------------------------------------------
namespace System.Windows.Documents
{
using MS.Internal;
using System.Windows;
using System.Globalization;
using System.Windows.Media;
///
/// An object implementing ITypeDescriptorContext intended to be used in serialization
/// scenarios for checking whether a particular value can be converted to a string
///
internal class DPTypeDescriptorContext : System.ComponentModel.ITypeDescriptorContext
{
//-----------------------------------------------------
//
// Constructors
//
//-----------------------------------------------------
#region Constructors
private DPTypeDescriptorContext(DependencyProperty property, object propertyValue)
{
Invariant.Assert(property != null, "property == null");
Invariant.Assert(propertyValue != null, "propertyValue == null");
Invariant.Assert(property.IsValidValue(propertyValue), "propertyValue must be of suitable type for the given dependency property");
_property = property;
_propertyValue = propertyValue;
}
#endregion Constructors
//------------------------------------------------------
//
// Internal Methods
//
//-----------------------------------------------------
#region Internal Methods
// Returns non-null string if this value can be converted to a string,
// null otherwise.
internal static string GetStringValue(DependencyProperty property, object propertyValue)
{
string stringValue = null;
// Special cases working around incorrectly implemented type converters
if (property == UIElement.BitmapEffectProperty)
{
return null; // Always treat BitmapEffects as complex value
}
if (property == Inline.TextDecorationsProperty)
{
stringValue = TextDecorationsFixup((TextDecorationCollection)propertyValue);
}
else if (typeof(CultureInfo).IsAssignableFrom(property.PropertyType)) //NumberSubstitution.CultureOverrideProperty
{
stringValue = CultureInfoFixup(property, (CultureInfo)propertyValue);
}
if (stringValue == null)
{
DPTypeDescriptorContext context = new DPTypeDescriptorContext(property, propertyValue);
System.ComponentModel.TypeConverter typeConverter = System.ComponentModel.TypeDescriptor.GetConverter(property.PropertyType);
Invariant.Assert(typeConverter != null);
if (typeConverter.CanConvertTo(context, typeof(string)))
{
stringValue = (string)typeConverter.ConvertTo(
context, System.Globalization.CultureInfo.InvariantCulture, propertyValue, typeof(string));
}
}
return stringValue;
}
#endregion Internal Methods
#region Private Methods
private static string TextDecorationsFixup(TextDecorationCollection textDecorations)
{
string stringValue = null;
// Work around for incorrect serialization for TextDecorations property
//
// Special case for TextDecorations serialization
if (TextDecorations.Underline.ValueEquals(textDecorations))
{
stringValue = "Underline";
}
else if (TextDecorations.Strikethrough.ValueEquals(textDecorations))
{
stringValue = "Strikethrough";
}
else if (TextDecorations.OverLine.ValueEquals(textDecorations))
{
stringValue = "OverLine";
}
else if (TextDecorations.Baseline.ValueEquals(textDecorations))
{
stringValue = "Baseline";
}
else if (textDecorations.Count == 0)
{
stringValue = string.Empty;
}
return stringValue;
}
private static string CultureInfoFixup(DependencyProperty property, CultureInfo cultureInfo)
{
string stringValue = null;
// Parser uses a specific type coverter for converting instances of other types to and from CultureInfo.
// This class differs from System.ComponentModel.CultureInfoConverter, the default type converter
// for the CultureInfo class.
// It uses a string representation based on the IetfLanguageTag property rather than the Name property
// (i.e., RFC 3066 rather than RFC 1766).
// In order to guarantee roundtripability of serialized xaml, textrange serialization needs to use
// this type coverter for CultureInfo types.
DPTypeDescriptorContext context = new DPTypeDescriptorContext(property, cultureInfo);
System.ComponentModel.TypeConverter typeConverter = new CultureInfoIetfLanguageTagConverter();
if (typeConverter.CanConvertTo(context, typeof(string)))
{
stringValue = (string)typeConverter.ConvertTo(
context, System.Globalization.CultureInfo.InvariantCulture, cultureInfo, typeof(string));
}
return stringValue;
}
#endregion Private Methods
//------------------------------------------------------
//
// Interface ITypeDescriptorContext
//
//------------------------------------------------------
#region ITypeDescriptorContext Members
System.ComponentModel.IContainer System.ComponentModel.ITypeDescriptorContext.Container
{
get { return null; }
}
// Returns a value of a property - to be detected for convertability to string in a type converter
object System.ComponentModel.ITypeDescriptorContext.Instance
{
get
{
return _propertyValue;
}
}
void System.ComponentModel.ITypeDescriptorContext.OnComponentChanged()
{
}
bool System.ComponentModel.ITypeDescriptorContext.OnComponentChanging()
{
return false;
}
System.ComponentModel.PropertyDescriptor System.ComponentModel.ITypeDescriptorContext.PropertyDescriptor
{
get { return null; }
}
#endregion
#region IServiceProvider Members
object IServiceProvider.GetService(Type serviceType)
{
return null;
}
#endregion
#region Private Fields
private DependencyProperty _property;
private object _propertyValue;
#endregion
}
}
// 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
- ProxyWebPart.cs
- PagerSettings.cs
- DtcInterfaces.cs
- RepeaterItemCollection.cs
- Decorator.cs
- ImageFormat.cs
- CounterSample.cs
- DataControlFieldCollection.cs
- MarkerProperties.cs
- SQLMembershipProvider.cs
- ResourceAssociationSet.cs
- SqlMethodTransformer.cs
- CompositionTarget.cs
- DocumentPageHost.cs
- SqlFactory.cs
- SmuggledIUnknown.cs
- XPathException.cs
- ToolTipService.cs
- XamlHostingConfiguration.cs
- LockCookie.cs
- XamlToRtfParser.cs
- IndexedString.cs
- Group.cs
- FrameworkReadOnlyPropertyMetadata.cs
- SessionEndedEventArgs.cs
- SqlDataSourceWizardForm.cs
- TypeConstant.cs
- DetailsView.cs
- OdbcReferenceCollection.cs
- SqlCharStream.cs
- DomNameTable.cs
- ScriptManager.cs
- CroppedBitmap.cs
- ExpandCollapsePattern.cs
- AnchorEditor.cs
- XmlArrayItemAttributes.cs
- XsdDataContractExporter.cs
- CatalogPartChrome.cs
- ValidationErrorCollection.cs
- CounterCreationData.cs
- HttpWriter.cs
- TaiwanLunisolarCalendar.cs
- _LocalDataStore.cs
- TableProviderWrapper.cs
- RepeaterItemCollection.cs
- ReadContentAsBinaryHelper.cs
- WhileDesigner.cs
- BindingExpressionBase.cs
- BitmapFrame.cs
- RewritingSimplifier.cs
- ReadOnlyCollectionBuilder.cs
- IncrementalCompileAnalyzer.cs
- EllipseGeometry.cs
- FaultContractInfo.cs
- PLINQETWProvider.cs
- SoundPlayer.cs
- SymDocumentType.cs
- RecognizedWordUnit.cs
- CompensatableTransactionScopeActivity.cs
- DbConnectionPoolGroupProviderInfo.cs
- HtmlAnchor.cs
- dtdvalidator.cs
- ListViewGroupItemCollection.cs
- SystemDiagnosticsSection.cs
- TemplateControlBuildProvider.cs
- Token.cs
- ItemContainerProviderWrapper.cs
- ToolStripMenuItem.cs
- XpsImage.cs
- TextEndOfLine.cs
- EndpointDiscoveryMetadata11.cs
- CatalogZoneBase.cs
- RequestSecurityTokenForRemoteTokenFactory.cs
- GenericsNotImplementedException.cs
- SmiGettersStream.cs
- CultureInfo.cs
- Compensate.cs
- DatagridviewDisplayedBandsData.cs
- RawKeyboardInputReport.cs
- TextReader.cs
- GacUtil.cs
- SQLBytesStorage.cs
- NullableFloatAverageAggregationOperator.cs
- OutgoingWebResponseContext.cs
- UrlRoutingModule.cs
- OleCmdHelper.cs
- XhtmlBasicImageAdapter.cs
- ObjectDataSourceEventArgs.cs
- RemotingConfiguration.cs
- GraphicsState.cs
- TextBlockAutomationPeer.cs
- WinEventWrap.cs
- MobileUserControl.cs
- ExtendedPropertyCollection.cs
- PackWebResponse.cs
- __ConsoleStream.cs
- IntranetCredentialPolicy.cs
- ErrorTableItemStyle.cs
- JournalEntry.cs
- ShaderRenderModeValidation.cs