Code:
/ 4.0 / 4.0 / untmp / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Configuration / System / Configuration / GenericEnumConverter.cs / 1305376 / GenericEnumConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- using System; using System.Collections; using System.IO; using System.Reflection; using System.Security.Permissions; using System.Xml; using System.Collections.Specialized; using System.Globalization; using System.ComponentModel; using System.Security; using System.Text; namespace System.Configuration { public sealed class GenericEnumConverter : ConfigurationConverterBase { private Type _enumType; public GenericEnumConverter(Type typeEnum) { if (typeEnum == null) { throw new ArgumentNullException("typeEnum"); } _enumType = typeEnum; } public override object ConvertTo(ITypeDescriptorContext ctx, CultureInfo ci, object value, Type type) { Debug.Assert(typeof(System.Enum).IsAssignableFrom(value.GetType()), "typeof(System.Enum).IsAssignableFrom(value.GetType())"); return value.ToString(); } public override object ConvertFrom(ITypeDescriptorContext ctx, CultureInfo ci, object data) { object result = null; // // For any error, throw the ArgumentException with SR.Invalid_enum_value // try { string value = (string)data; if (String.IsNullOrEmpty(value)) { throw new Exception(); } // Disallow numeric values for enums. if (!String.IsNullOrEmpty(value) && (Char.IsDigit(value[0]) || (value[0] == '-') || (value[0] == '+'))) { throw new Exception(); } if (value != value.Trim()) { // throw if the value has whitespace throw new Exception(); } result = Enum.Parse(_enumType, value); } catch { StringBuilder names = new StringBuilder(); foreach (string name in Enum.GetNames(_enumType)) { if (names.Length != 0) { names.Append(", "); } names.Append(name); } throw new ArgumentException(SR.GetString(SR.Invalid_enum_value, names.ToString())); } return result; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007.
Link Menu
This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- PathGeometry.cs
- TypeUtil.cs
- OracleCommandSet.cs
- WorkItem.cs
- PolyLineSegment.cs
- DirectionalLight.cs
- ZoneMembershipCondition.cs
- Point4DConverter.cs
- ArcSegment.cs
- SqlDataSourceCustomCommandPanel.cs
- Vector3DKeyFrameCollection.cs
- Ray3DHitTestResult.cs
- KnowledgeBase.cs
- BuildProvider.cs
- EditableRegion.cs
- PageAction.cs
- SerializationAttributes.cs
- WebPartCancelEventArgs.cs
- MatchingStyle.cs
- ButtonBase.cs
- SpellerError.cs
- MetadataCollection.cs
- XPathNodeInfoAtom.cs
- OleDbPropertySetGuid.cs
- TimeSpanStorage.cs
- StringInfo.cs
- NaturalLanguageHyphenator.cs
- CompilationLock.cs
- SystemThemeKey.cs
- PermissionListSet.cs
- UserPreferenceChangingEventArgs.cs
- LinqDataSourceValidationException.cs
- BaseWebProxyFinder.cs
- UniqueEventHelper.cs
- BitmapPalettes.cs
- DiagnosticsConfiguration.cs
- BitmapEffectInput.cs
- TimeStampChecker.cs
- RegexWriter.cs
- GridItemProviderWrapper.cs
- SafeCoTaskMem.cs
- Visual.cs
- EnumConverter.cs
- BaseServiceProvider.cs
- metrodevice.cs
- HttpCacheVaryByContentEncodings.cs
- MenuBindingsEditor.cs
- LambdaCompiler.Unary.cs
- DataSourceView.cs
- OptimizedTemplateContent.cs
- GenericEnumerator.cs
- PropertyChangedEventManager.cs
- InputMethodStateChangeEventArgs.cs
- StringAnimationUsingKeyFrames.cs
- FormViewDeletedEventArgs.cs
- DefaultHttpHandler.cs
- ContentOperations.cs
- XPathExpr.cs
- Int64.cs
- Rect3DValueSerializer.cs
- UserMapPath.cs
- SqlTriggerAttribute.cs
- XhtmlTextWriter.cs
- MouseButton.cs
- OdbcEnvironment.cs
- InputScopeManager.cs
- MoveSizeWinEventHandler.cs
- TypedReference.cs
- HiddenField.cs
- ProfileModule.cs
- EditorServiceContext.cs
- OledbConnectionStringbuilder.cs
- ProcessHost.cs
- SocketStream.cs
- SqlCommandBuilder.cs
- ChangeProcessor.cs
- WebPartCancelEventArgs.cs
- ListDictionaryInternal.cs
- Emitter.cs
- ReverseInheritProperty.cs
- ObjectContextServiceProvider.cs
- DeviceSpecificChoice.cs
- ValidationPropertyAttribute.cs
- UriTemplateMatch.cs
- MemberInfoSerializationHolder.cs
- TextBreakpoint.cs
- InertiaExpansionBehavior.cs
- TypeDelegator.cs
- KeyTimeConverter.cs
- OptimalTextSource.cs
- XmlEventCache.cs
- DataGridViewLayoutData.cs
- SequentialWorkflowHeaderFooter.cs
- CodeSnippetStatement.cs
- PathFigure.cs
- TableLayoutStyle.cs
- InstancePersistenceCommandException.cs
- SiteMapDataSourceDesigner.cs
- FlowLayoutPanel.cs
- CachedBitmap.cs