Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / wpf / src / Base / System / Windows / DependencyPropertyValueSerializer.cs / 1305600 / 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.
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- _TimerThread.cs
- DocumentSchemaValidator.cs
- ObjectToIdCache.cs
- MimeMapping.cs
- TypeToken.cs
- _ListenerResponseStream.cs
- PropertyFilterAttribute.cs
- ConfigXmlComment.cs
- TextChange.cs
- XmlIlTypeHelper.cs
- COM2Properties.cs
- RegexFCD.cs
- WebEventTraceProvider.cs
- ListManagerBindingsCollection.cs
- StyleCollectionEditor.cs
- DropShadowBitmapEffect.cs
- SchemaSetCompiler.cs
- PngBitmapEncoder.cs
- IPipelineRuntime.cs
- CompiledQueryCacheEntry.cs
- Collection.cs
- MergeFilterQuery.cs
- DesignTimeResourceProviderFactoryAttribute.cs
- DescendantBaseQuery.cs
- DataGridViewColumnEventArgs.cs
- CommonObjectSecurity.cs
- EncodingTable.cs
- CompositeDuplexBindingElement.cs
- DurableOperationContext.cs
- BufferedConnection.cs
- NodeInfo.cs
- SchemaElementDecl.cs
- WindowVisualStateTracker.cs
- TraceListener.cs
- SecureStringHasher.cs
- Stacktrace.cs
- GrammarBuilder.cs
- CompilerInfo.cs
- Propagator.Evaluator.cs
- IdentityHolder.cs
- InternalResources.cs
- MsmqIntegrationProcessProtocolHandler.cs
- CheckBoxField.cs
- Win32.cs
- TypeSystemProvider.cs
- OleDbDataAdapter.cs
- IsolatedStorage.cs
- CallbackHandler.cs
- ApplicationProxyInternal.cs
- PageContentCollection.cs
- FixedPageAutomationPeer.cs
- ToolStripDropDownItem.cs
- XPathScanner.cs
- RepeatButton.cs
- HttpMethodConstraint.cs
- XhtmlBasicSelectionListAdapter.cs
- MetabaseServerConfig.cs
- TextEncodedRawTextWriter.cs
- AsyncPostBackTrigger.cs
- CustomAttributeFormatException.cs
- SqlXml.cs
- ObjectViewListener.cs
- TextRangeEditTables.cs
- mediaeventshelper.cs
- XmlTypeAttribute.cs
- HtmlImage.cs
- FloaterBaseParagraph.cs
- ProfileSettingsCollection.cs
- RectangleHotSpot.cs
- XmlSchemaAnyAttribute.cs
- MultiPropertyDescriptorGridEntry.cs
- DesignerSerializerAttribute.cs
- NullableFloatSumAggregationOperator.cs
- ColumnResizeAdorner.cs
- GifBitmapDecoder.cs
- StringUtil.cs
- UrlAuthorizationModule.cs
- ModuleBuilder.cs
- FileDocument.cs
- ChannelDispatcherCollection.cs
- ProxyFragment.cs
- SpeechSeg.cs
- LocalizationParserHooks.cs
- GlobalEventManager.cs
- ExceptionUtil.cs
- Roles.cs
- CalendarSelectionChangedEventArgs.cs
- StringFunctions.cs
- FixedFlowMap.cs
- StaticResourceExtension.cs
- FontCollection.cs
- StringExpressionSet.cs
- ScrollViewer.cs
- EntityDesignerUtils.cs
- HtmlWindowCollection.cs
- ZeroOpNode.cs
- DecoderExceptionFallback.cs
- BookmarkScopeHandle.cs
- OdbcRowUpdatingEvent.cs
- Canvas.cs