Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / fx / src / Services / Messaging / System / Messaging / Design / SizeConverter.cs / 1305376 / SizeConverter.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Messaging.Design { using System.Messaging; using System.ComponentModel; using System.Diagnostics; using System; using System.ComponentModel.Design.Serialization; using System.Reflection; using System.Collections; using System.Globalization; ///internal class SizeConverter : TypeConverter { /// /// /// Determines if this converter can convert an object in the given source /// type to the native type of the converter. /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } ////// /// Converts the given object to the converter's native type. /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { string text = ((string)value).Trim(); if (text.Length == 0 || string.Compare(text, Res.GetString(Res.InfiniteValue), true, CultureInfo.CurrentCulture) == 0) return(long)uint.MaxValue; else { long size = Convert.ToInt64(text, culture); return size; } } return base.ConvertFrom(context, culture, value); } ////// /// Converts the given object to another type. The most common types to convert /// are to and from a string object. The default implementation will make a call /// to ToString on the object if the object is valid and if the destination /// type is string. If this cannot convert to the desitnation type, this will /// throw a NotSupportedException. /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(string)) { if (value != null) { if ((long)value == uint.MaxValue) return Res.GetString(Res.InfiniteValue); else return value.ToString(); } } return base.ConvertTo(context, culture, value, destinationType); } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- namespace System.Messaging.Design { using System.Messaging; using System.ComponentModel; using System.Diagnostics; using System; using System.ComponentModel.Design.Serialization; using System.Reflection; using System.Collections; using System.Globalization; ///internal class SizeConverter : TypeConverter { /// /// /// Determines if this converter can convert an object in the given source /// type to the native type of the converter. /// public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType) { if (sourceType == typeof(string)) { return true; } return base.CanConvertFrom(context, sourceType); } ////// /// Converts the given object to the converter's native type. /// public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string) { string text = ((string)value).Trim(); if (text.Length == 0 || string.Compare(text, Res.GetString(Res.InfiniteValue), true, CultureInfo.CurrentCulture) == 0) return(long)uint.MaxValue; else { long size = Convert.ToInt64(text, culture); return size; } } return base.ConvertFrom(context, culture, value); } ////// /// Converts the given object to another type. The most common types to convert /// are to and from a string object. The default implementation will make a call /// to ToString on the object if the object is valid and if the destination /// type is string. If this cannot convert to the desitnation type, this will /// throw a NotSupportedException. /// public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType) { if (destinationType == null) { throw new ArgumentNullException("destinationType"); } if (destinationType == typeof(string)) { if (value != null) { if ((long)value == uint.MaxValue) return Res.GetString(Res.InfiniteValue); else return value.ToString(); } } return base.ConvertTo(context, culture, value, destinationType); } } } // 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
- ReferencedType.cs
- CachedFontFamily.cs
- KeyPullup.cs
- WarningException.cs
- TextComposition.cs
- RequestQueryProcessor.cs
- NeutralResourcesLanguageAttribute.cs
- pingexception.cs
- ObjectSet.cs
- PointHitTestResult.cs
- ComplexTypeEmitter.cs
- OutgoingWebRequestContext.cs
- MutexSecurity.cs
- DataBindingHandlerAttribute.cs
- Themes.cs
- MenuItem.cs
- XPathNodePointer.cs
- BindingExpressionUncommonField.cs
- CodeVariableReferenceExpression.cs
- TraceSource.cs
- ClockGroup.cs
- DataListItemCollection.cs
- DetailsViewRowCollection.cs
- GPStream.cs
- QuaternionValueSerializer.cs
- Update.cs
- PeerNearMe.cs
- DocumentAutomationPeer.cs
- PerspectiveCamera.cs
- ContactManager.cs
- ScrollBarRenderer.cs
- WinEventHandler.cs
- HeaderCollection.cs
- DBCSCodePageEncoding.cs
- ObjectComplexPropertyMapping.cs
- GeometryDrawing.cs
- RowsCopiedEventArgs.cs
- TextureBrush.cs
- RowCache.cs
- SimpleWorkerRequest.cs
- MarshalDirectiveException.cs
- SortedDictionary.cs
- CopyAttributesAction.cs
- WmlPhoneCallAdapter.cs
- MimeTypeAttribute.cs
- GlobalizationAssembly.cs
- Point3DAnimationBase.cs
- ShapingWorkspace.cs
- WindowsFormsLinkLabel.cs
- XmlDocumentType.cs
- DataControlField.cs
- GorillaCodec.cs
- ComPlusSynchronizationContext.cs
- DeviceContexts.cs
- NullableConverter.cs
- TreeViewItem.cs
- GridView.cs
- CompositeTypefaceMetrics.cs
- TreeViewTemplateSelector.cs
- Latin1Encoding.cs
- WebPartDescriptionCollection.cs
- AtlasWeb.Designer.cs
- SafeProcessHandle.cs
- RsaSecurityTokenAuthenticator.cs
- UndirectedGraph.cs
- TextUtf8RawTextWriter.cs
- TypeLibConverter.cs
- storepermissionattribute.cs
- RequiredFieldValidator.cs
- DSACryptoServiceProvider.cs
- ObjectStateEntryBaseUpdatableDataRecord.cs
- TemplateColumn.cs
- ArglessEventHandlerProxy.cs
- xsdvalidator.cs
- ReliabilityContractAttribute.cs
- DBConnectionString.cs
- METAHEADER.cs
- StateFinalizationActivity.cs
- SafeRegistryHandle.cs
- AstTree.cs
- LockedHandleGlyph.cs
- Calendar.cs
- SystemIcmpV4Statistics.cs
- ProfessionalColors.cs
- ObjectDesignerDataSourceView.cs
- SoapTypeAttribute.cs
- HitTestResult.cs
- IncomingWebResponseContext.cs
- AVElementHelper.cs
- SQLSingle.cs
- KeyBinding.cs
- WindowsAuthenticationEventArgs.cs
- QueryServiceConfigHandle.cs
- BindingCompleteEventArgs.cs
- Hex.cs
- dsa.cs
- SByte.cs
- TextProperties.cs
- SQLBytes.cs
- Size3DValueSerializer.cs