Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / xsp / System / DynamicData / DynamicData / Util / DictionaryCustomTypeDescriptor.cs / 1305376 / DictionaryCustomTypeDescriptor.cs
namespace System.Web.DynamicData.Util {
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
internal class DictionaryCustomTypeDescriptor : CustomTypeDescriptor {
private IDictionary _values;
private PropertyDescriptorCollection _properties;
public DictionaryCustomTypeDescriptor(IDictionary values) {
if (values == null) {
throw new ArgumentNullException("values");
}
_values = values;
}
public object GetValue(string name) {
object value;
if (_values.TryGetValue(name, out value)) {
return value;
}
return null;
}
public override PropertyDescriptorCollection GetProperties() {
if (_properties == null) {
var dictionaryProps = _values.Keys.Select(propName => new DictionaryPropertyDescriptor(propName));
_properties = new PropertyDescriptorCollection(dictionaryProps.ToArray());
}
return _properties;
}
}
internal class DictionaryPropertyDescriptor : PropertyDescriptor {
public DictionaryPropertyDescriptor(string name)
: base(name, null /* attrs */) {
}
public override bool CanResetValue(object component) {
throw new NotSupportedException();
}
public override Type ComponentType {
get {
throw new NotSupportedException();
}
}
public override object GetValue(object component) {
// Try to cast the component to a DictionaryCustomTypeDescriptor and get the value in the dictonary
// that corresponds to this property
DictionaryCustomTypeDescriptor typeDescriptor = component as DictionaryCustomTypeDescriptor;
if (typeDescriptor == null) {
return null;
}
return typeDescriptor.GetValue(Name);
}
public override bool IsReadOnly {
get {
throw new NotSupportedException();
}
}
public override Type PropertyType {
get {
throw new NotSupportedException();
}
}
public override void ResetValue(object component) {
throw new NotSupportedException();
}
public override void SetValue(object component, object value) {
throw new NotSupportedException();
}
public override bool ShouldSerializeValue(object component) {
throw new NotSupportedException();
}
}
}
// 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
- XPathAncestorIterator.cs
- IncrementalHitTester.cs
- WebServiceParameterData.cs
- SolidColorBrush.cs
- Utility.cs
- ElementMarkupObject.cs
- ToolboxItemAttribute.cs
- HGlobalSafeHandle.cs
- XmlText.cs
- OdbcConnection.cs
- ChannelManager.cs
- PropertyTab.cs
- SvcMapFileSerializer.cs
- StoragePropertyMapping.cs
- HttpSessionStateBase.cs
- SoapAttributes.cs
- _TransmitFileOverlappedAsyncResult.cs
- RelationHandler.cs
- ScriptingAuthenticationServiceSection.cs
- NumericExpr.cs
- VScrollBar.cs
- JsonGlobals.cs
- UpdateExpressionVisitor.cs
- Annotation.cs
- HwndSourceParameters.cs
- SynchronizationFilter.cs
- UnmanagedMarshal.cs
- CompiledRegexRunner.cs
- MouseGestureValueSerializer.cs
- ContentDesigner.cs
- ContextStaticAttribute.cs
- XmlAutoDetectWriter.cs
- AsyncDataRequest.cs
- XmlNodeComparer.cs
- TokenBasedSetEnumerator.cs
- XdrBuilder.cs
- NullableDoubleSumAggregationOperator.cs
- TextTreeUndo.cs
- PropertyDescriptorGridEntry.cs
- DocumentPageViewAutomationPeer.cs
- DataGrid.cs
- CollectionConverter.cs
- ProfileServiceManager.cs
- ValidatingPropertiesEventArgs.cs
- HttpContext.cs
- WebRequestModuleElement.cs
- Cursor.cs
- ModelItem.cs
- XmlSchemaInclude.cs
- Rethrow.cs
- RadialGradientBrush.cs
- Latin1Encoding.cs
- TimeSpan.cs
- WebRequest.cs
- Overlapped.cs
- PropagatorResult.cs
- listitem.cs
- DataColumnChangeEvent.cs
- BigInt.cs
- OracleRowUpdatingEventArgs.cs
- WmlLinkAdapter.cs
- ApplicationActivator.cs
- BitmapPalette.cs
- TypeBuilderInstantiation.cs
- StrongName.cs
- DBParameter.cs
- Header.cs
- TransportConfigurationTypeElementCollection.cs
- WS2007FederationHttpBinding.cs
- AuditLogLocation.cs
- ResXResourceReader.cs
- NetSectionGroup.cs
- PersianCalendar.cs
- TemplateContent.cs
- AnonymousIdentificationModule.cs
- XsltInput.cs
- CapacityStreamGeometryContext.cs
- PassportPrincipal.cs
- CipherData.cs
- ConversionValidationRule.cs
- mediapermission.cs
- ShaderEffect.cs
- UserMapPath.cs
- MessageAction.cs
- CompiledQuery.cs
- ScriptControl.cs
- WindowAutomationPeer.cs
- Icon.cs
- SoapBinding.cs
- HtmlWindowCollection.cs
- _RegBlobWebProxyDataBuilder.cs
- ImageIndexConverter.cs
- ButtonBase.cs
- EventWaitHandle.cs
- latinshape.cs
- PrivateFontCollection.cs
- XmlBinaryWriterSession.cs
- DetailsViewPageEventArgs.cs
- DynamicHyperLink.cs
- WebPartHelpVerb.cs