Code:
/ Dotnetfx_Vista_SP2 / Dotnetfx_Vista_SP2 / 8.0.50727.4016 / DEVDIV / depot / DevDiv / releases / Orcas / QFE / wpf / src / Framework / System / Windows / PropertyPathConverter.cs / 1 / PropertyPathConverter.cs
//----------------------------------------------------------------------------
//
// Copyright (C) Microsoft Corporation. All rights reserved.
//
// File: PropertyPathConverter.cs
//
// Description: Contains converter for creating PropertyPath from string
// and saving PropertyPath to string
//
// History:
// 05/15/2004 - peterost - Initial implementation
//
//---------------------------------------------------------------------------
using System;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Text;
using System.ComponentModel.Design.Serialization;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Windows;
using System.Windows.Markup;
using MS.Internal;
using MS.Utility;
#pragma warning disable 1634, 1691 // suppressing PreSharp warnings
namespace System.Windows
{
///
/// PropertyPathConverter - Converter class for converting instances of other types
/// to and from PropertyPath instances.
///
public sealed class PropertyPathConverter: TypeConverter
{
//-------------------------------------------------------------------
//
// Public Methods
//
//-------------------------------------------------------------------
#region Public Methods
///
/// CanConvertFrom - Returns whether or not this class can convert from a given type.
///
///
/// bool - True if this converter can convert from the provided type, false if not.
///
/// The ITypeDescriptorContext for this call.
/// The Type being queried for support.
public override bool CanConvertFrom(ITypeDescriptorContext typeDescriptorContext, Type sourceType)
{
// We can only handle strings
if (sourceType == typeof(string))
{
return true;
}
else
{
return false;
}
}
///
/// CanConvertTo - Returns whether or not this class can convert to a given type.
///
///
/// bool - True if this converter can convert to the provided type, false if not.
///
/// The ITypeDescriptorContext for this call.
/// The Type being queried for support.
public override bool CanConvertTo(ITypeDescriptorContext typeDescriptorContext, Type destinationType)
{
// We can convert to a string.
if (destinationType == typeof(string))
{
return true;
}
else
{
return false;
}
}
///
/// ConvertFrom - Attempt to convert to a PropertyPath from the given object
///
///
/// The PropertyPath which was constructed.
///
///
/// An ArgumentNullException is thrown if the example object is null.
///
///
/// An ArgumentException is thrown if the example object is not null and is not a valid type
/// which can be converted to a PropertyPath.
///
/// The ITypeDescriptorContext for this call.
/// The CultureInfo which is respected when converting.
/// The object to convert to a PropertyPath.
public override object ConvertFrom(ITypeDescriptorContext typeDescriptorContext,
CultureInfo cultureInfo,
object source)
{
if (source == null)
{
throw new ArgumentNullException("source");
}
if (source is string)
{
return new PropertyPath((string)source, typeDescriptorContext);
}
#pragma warning suppress 6506 // source is obviously not null
throw new ArgumentException(SR.Get(SRID.CannotConvertType, source.GetType().FullName, typeof(PropertyPath)));
}
///
/// ConvertTo - Attempt to convert a PropertyPath to the given type
///
///
/// The object which was constructed.
///
///
/// An ArgumentNullException is thrown if the example object is null.
///
///
/// An ArgumentException is thrown if the example object is not null and is not a Brush,
/// or if the destinationType isn't one of the valid destination types.
///
/// The ITypeDescriptorContext for this call.
/// If this is null, then no namespace prefixes will be included.
/// The CultureInfo which is respected when converting.
/// The PropertyPath to convert.
/// The type to which to convert the PropertyPath instance.
public override object ConvertTo(ITypeDescriptorContext typeDescriptorContext,
CultureInfo cultureInfo,
object value,
Type destinationType)
{
if (null == value)
{
throw new ArgumentNullException("value");
}
if (null == destinationType)
{
throw new ArgumentNullException("destinationType");
}
if (destinationType != typeof(String))
{
throw new ArgumentException(SR.Get(SRID.CannotConvertType, typeof(PropertyPath), destinationType.FullName));
}
PropertyPath path = value as PropertyPath;
if (path == null)
{
throw new ArgumentException(SR.Get(SRID.UnexpectedParameterType, value.GetType(), typeof(PropertyPath)), "value");
}
if (path.PathParameters.Count == 0)
{
// if the path didn't use paramaters, just write it out as it is
return path.Path;
}
else
{
// if the path used parameters, convert them to (NamespacePrefix:OwnerType.DependencyPropertyName) syntax
string originalPath = path.Path;
Collection
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- DtrList.cs
- RevocationPoint.cs
- XmlSchemaObjectTable.cs
- Pool.cs
- GeometryDrawing.cs
- BaseTreeIterator.cs
- XmlObjectSerializerWriteContextComplexJson.cs
- Int16Animation.cs
- WebConfigurationHostFileChange.cs
- DataTemplateKey.cs
- BooleanFunctions.cs
- AuthenticationException.cs
- PowerStatus.cs
- XmlAttribute.cs
- Converter.cs
- XpsResource.cs
- ApplicationDirectoryMembershipCondition.cs
- SizeFConverter.cs
- XLinq.cs
- SequentialUshortCollection.cs
- DefaultBinder.cs
- WebMethodAttribute.cs
- HttpCachePolicy.cs
- AsymmetricKeyExchangeDeformatter.cs
- Mapping.cs
- PrintController.cs
- BuildProvider.cs
- JsonServiceDocumentSerializer.cs
- ResourceDictionaryCollection.cs
- AmbiguousMatchException.cs
- ScaleTransform3D.cs
- ListParaClient.cs
- ConnectionManagementElementCollection.cs
- DrawingCollection.cs
- WsatServiceCertificate.cs
- EmbeddedMailObjectsCollection.cs
- TargetParameterCountException.cs
- RewritingProcessor.cs
- ColorConvertedBitmap.cs
- SerializationInfoEnumerator.cs
- Simplifier.cs
- SmiRecordBuffer.cs
- CodeTryCatchFinallyStatement.cs
- AbstractDataSvcMapFileLoader.cs
- AppDomainManager.cs
- _SafeNetHandles.cs
- TreeNodeConverter.cs
- ProfilePropertySettings.cs
- IndicShape.cs
- SqlDelegatedTransaction.cs
- ScriptingProfileServiceSection.cs
- RenderCapability.cs
- ModuleBuilderData.cs
- ZipIOBlockManager.cs
- VisualTreeHelper.cs
- contentDescriptor.cs
- TranslateTransform3D.cs
- ViewKeyConstraint.cs
- FixedSOMFixedBlock.cs
- WmlTextViewAdapter.cs
- TripleDESCryptoServiceProvider.cs
- Light.cs
- TextEditorDragDrop.cs
- TimelineGroup.cs
- SchemaExporter.cs
- OdbcError.cs
- UriTemplateTrieNode.cs
- CallSite.cs
- TreeWalker.cs
- MissingMethodException.cs
- CompilerTypeWithParams.cs
- HostingEnvironmentSection.cs
- TypeKeyValue.cs
- SqlResolver.cs
- SimpleParser.cs
- ConfigurationProperty.cs
- Symbol.cs
- ScrollBarRenderer.cs
- TextTreeInsertElementUndoUnit.cs
- UriWriter.cs
- storagemappingitemcollection.viewdictionary.cs
- CatalogPartChrome.cs
- WebConfigurationManager.cs
- EnumMember.cs
- DataGridViewColumnConverter.cs
- TypedReference.cs
- ArrayElementGridEntry.cs
- DeviceContext.cs
- CharStorage.cs
- SystemResourceHost.cs
- XmlSchemaGroupRef.cs
- CommonDialog.cs
- OdbcReferenceCollection.cs
- FixedSOMLineRanges.cs
- Geometry3D.cs
- ProjectionCamera.cs
- DelimitedListTraceListener.cs
- StrokeIntersection.cs
- EnumMember.cs
- DataGridViewAdvancedBorderStyle.cs