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 / DependencyPropertyValueSerializer.cs / 1 / DependencyPropertyValueSerializer.cs
//------------------------------------------------------------------------
//
// Microsoft Windows Client Platform
// Copyright (C) Microsoft Corporation, 2005
//
// File: CommandValueSerializer.cs
//
// Contents: ValueSerializer for DependencyProperty
//
// Created: 04/28/2005 [....]
//
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Markup;
namespace System.Windows
{
internal class DependencyPropertyValueSerializer : ValueSerializer
{
public override bool CanConvertToString(object value, IValueSerializerContext context)
{
return ValueSerializer.GetSerializerFor(typeof(Type), context) != null;
}
public override bool CanConvertFromString(string value, IValueSerializerContext context)
{
return ValueSerializer.GetSerializerFor(typeof(Type), context) != null;
}
public override string ConvertToString(object value, IValueSerializerContext context)
{
DependencyProperty property = value as DependencyProperty;
if (property != null)
{
ValueSerializer typeSerializer = ValueSerializer.GetSerializerFor(typeof(Type), context);
if (typeSerializer != null)
{
return typeSerializer.ConvertToString(property.OwnerType, context) + "." + property.Name;
}
}
throw GetConvertToException(value, typeof(string));
}
public override IEnumerable TypeReferences(object value, IValueSerializerContext context)
{
DependencyProperty property = value as DependencyProperty;
if (property != null)
{
return new Type[] { property.OwnerType };
}
else
{
return base.TypeReferences(value, context);
}
}
public override object ConvertFromString(string value, IValueSerializerContext context)
{
ValueSerializer typeSerializer = ValueSerializer.GetSerializerFor(typeof(Type), context);
if (typeSerializer != null)
{
int dotIndex = value.IndexOf('.');
if (dotIndex >= 0)
{
string typeName = value.Substring(0, dotIndex - 1);
Type ownerType = typeSerializer.ConvertFromString(typeName, context) as Type;
if (ownerType != null)
{
return DependencyProperty.FromName(typeName, ownerType);
}
}
}
throw GetConvertFromException(value);
}
}
}
// 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, 2005
//
// File: CommandValueSerializer.cs
//
// Contents: ValueSerializer for DependencyProperty
//
// Created: 04/28/2005 [....]
//
//-----------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Markup;
namespace System.Windows
{
internal class DependencyPropertyValueSerializer : ValueSerializer
{
public override bool CanConvertToString(object value, IValueSerializerContext context)
{
return ValueSerializer.GetSerializerFor(typeof(Type), context) != null;
}
public override bool CanConvertFromString(string value, IValueSerializerContext context)
{
return ValueSerializer.GetSerializerFor(typeof(Type), context) != null;
}
public override string ConvertToString(object value, IValueSerializerContext context)
{
DependencyProperty property = value as DependencyProperty;
if (property != null)
{
ValueSerializer typeSerializer = ValueSerializer.GetSerializerFor(typeof(Type), context);
if (typeSerializer != null)
{
return typeSerializer.ConvertToString(property.OwnerType, context) + "." + property.Name;
}
}
throw GetConvertToException(value, typeof(string));
}
public override IEnumerable TypeReferences(object value, IValueSerializerContext context)
{
DependencyProperty property = value as DependencyProperty;
if (property != null)
{
return new Type[] { property.OwnerType };
}
else
{
return base.TypeReferences(value, context);
}
}
public override object ConvertFromString(string value, IValueSerializerContext context)
{
ValueSerializer typeSerializer = ValueSerializer.GetSerializerFor(typeof(Type), context);
if (typeSerializer != null)
{
int dotIndex = value.IndexOf('.');
if (dotIndex >= 0)
{
string typeName = value.Substring(0, dotIndex - 1);
Type ownerType = typeSerializer.ConvertFromString(typeName, context) as Type;
if (ownerType != null)
{
return DependencyProperty.FromName(typeName, ownerType);
}
}
}
throw GetConvertFromException(value);
}
}
}
// 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
- CodeObject.cs
- Parameter.cs
- DoWorkEventArgs.cs
- EncryptedKey.cs
- DefaultParameterValueAttribute.cs
- MessageBuilder.cs
- PriorityChain.cs
- designeractionbehavior.cs
- SqlConnectionHelper.cs
- EntityDataReader.cs
- Helper.cs
- DependencyPropertyValueSerializer.cs
- DotExpr.cs
- ListBoxDesigner.cs
- RecommendedAsConfigurableAttribute.cs
- ApplicationTrust.cs
- StreamSecurityUpgradeInitiator.cs
- RequestCacheEntry.cs
- TokenizerHelper.cs
- WebRequestModuleElementCollection.cs
- Rect3D.cs
- CheckPair.cs
- CommandBindingCollection.cs
- DBCSCodePageEncoding.cs
- HashHelper.cs
- Int32EqualityComparer.cs
- WebPartConnectionsConnectVerb.cs
- Command.cs
- SqlConnectionPoolGroupProviderInfo.cs
- WebUtil.cs
- PointCollection.cs
- SqlDuplicator.cs
- CultureTable.cs
- TitleStyle.cs
- RelatedPropertyManager.cs
- UserNamePasswordServiceCredential.cs
- SqlClientPermission.cs
- PasswordValidationException.cs
- MultiDataTrigger.cs
- AuthorizationSection.cs
- NativeWindow.cs
- ContainerVisual.cs
- SimpleTypeResolver.cs
- ThreadPoolTaskScheduler.cs
- FlowDocumentReader.cs
- PerformanceCounterCategory.cs
- WebBrowser.cs
- ExecutionContext.cs
- PeerCollaboration.cs
- ObjectTokenCategory.cs
- XpsFixedPageReaderWriter.cs
- ProfessionalColors.cs
- dataprotectionpermission.cs
- StreamGeometry.cs
- GifBitmapDecoder.cs
- XPathAncestorQuery.cs
- ToolStripContentPanel.cs
- ToolBar.cs
- RuntimeHelpers.cs
- AuthenticationSection.cs
- ArgumentNullException.cs
- ConfigurationManagerInternal.cs
- ExpressionBinding.cs
- ExpressionVisitorHelpers.cs
- ColumnHeader.cs
- BamlTreeNode.cs
- Stylus.cs
- Win32KeyboardDevice.cs
- PrincipalPermission.cs
- TextEditorMouse.cs
- WindowsButton.cs
- ParameterElementCollection.cs
- AnnotationMap.cs
- SizeAnimation.cs
- NativeObjectSecurity.cs
- TPLETWProvider.cs
- TCPClient.cs
- DataServiceContext.cs
- ClientProxyGenerator.cs
- ComponentResourceManager.cs
- ApplyTemplatesAction.cs
- TypeReference.cs
- SettingsPropertyValueCollection.cs
- TdsRecordBufferSetter.cs
- ComPlusAuthorization.cs
- Label.cs
- RedirectionProxy.cs
- ContractType.cs
- TokenizerHelper.cs
- Socket.cs
- ClientSettingsStore.cs
- streamingZipPartStream.cs
- ZoneLinkButton.cs
- ContextActivityUtils.cs
- OverflowException.cs
- SimpleTextLine.cs
- EntityDataSourceWizardForm.cs
- PropertyRef.cs
- ObjectStateEntryOriginalDbUpdatableDataRecord.cs
- XmlHelper.cs