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
- SystemIPInterfaceProperties.cs
- WindowHideOrCloseTracker.cs
- ParameterToken.cs
- FormDesigner.cs
- WebPartConnectionsCancelVerb.cs
- ProfileManager.cs
- MailAddress.cs
- AncestorChangedEventArgs.cs
- ExtendedProtectionPolicyElement.cs
- DesignerDeviceConfig.cs
- DetailsViewUpdatedEventArgs.cs
- UnwrappedTypesXmlSerializerManager.cs
- TableCell.cs
- ContainerControl.cs
- StreamFormatter.cs
- FileIOPermission.cs
- GenericsInstances.cs
- SyntaxCheck.cs
- CallbackValidator.cs
- TextPatternIdentifiers.cs
- MenuCommand.cs
- JavascriptCallbackMessageInspector.cs
- DateTimeOffsetStorage.cs
- UserControl.cs
- CodeNamespace.cs
- streamingZipPartStream.cs
- CallSiteHelpers.cs
- DynamicMethod.cs
- InstalledFontCollection.cs
- IdnMapping.cs
- ValidationError.cs
- ThaiBuddhistCalendar.cs
- DataGridViewIntLinkedList.cs
- Pair.cs
- ContextMarshalException.cs
- X509IssuerSerialKeyIdentifierClause.cs
- MailMessageEventArgs.cs
- Camera.cs
- TransformCollection.cs
- SemanticAnalyzer.cs
- ListDictionaryInternal.cs
- StrongNameIdentityPermission.cs
- XmlDataProvider.cs
- LabelEditEvent.cs
- TextEffect.cs
- EntityTypeEmitter.cs
- PostBackOptions.cs
- XmlSerializerNamespaces.cs
- FileLogRecordEnumerator.cs
- DefaultEventAttribute.cs
- RenameRuleObjectDialog.Designer.cs
- CalloutQueueItem.cs
- ClaimSet.cs
- SortedSet.cs
- DBCommandBuilder.cs
- SmtpClient.cs
- IntranetCredentialPolicy.cs
- FeatureSupport.cs
- XmlSiteMapProvider.cs
- StreamGeometryContext.cs
- XmlSchemaObject.cs
- DataDocumentXPathNavigator.cs
- sqlnorm.cs
- QilScopedVisitor.cs
- ProfileEventArgs.cs
- MachineKeyConverter.cs
- WindowsSpinner.cs
- WpfWebRequestHelper.cs
- NativeActivityMetadata.cs
- WS2007HttpBindingElement.cs
- StringArrayConverter.cs
- CultureMapper.cs
- ProviderMetadata.cs
- SapiGrammar.cs
- ListItemParagraph.cs
- HttpProcessUtility.cs
- EntityChangedParams.cs
- DynamicFilterExpression.cs
- DateRangeEvent.cs
- SoapInteropTypes.cs
- ListBoxAutomationPeer.cs
- BitVector32.cs
- DataSourceProvider.cs
- CalendarModeChangedEventArgs.cs
- HtmlContainerControl.cs
- DataSourceSelectArguments.cs
- Byte.cs
- ToolStripRendererSwitcher.cs
- InputScopeAttribute.cs
- DataGridBoolColumn.cs
- SqlParameter.cs
- ByteRangeDownloader.cs
- XmlQualifiedNameTest.cs
- RectangleF.cs
- TraceInternal.cs
- XsltConvert.cs
- TrackingProfile.cs
- TextBlockAutomationPeer.cs
- UserValidatedEventArgs.cs
- DataGridParentRows.cs