Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / NetFx40 / Tools / System.Activities.Presentation / System / Activities / Presentation / Base / Core / Internal / PropertyEditing / State / CategoryState.cs / 1305376 / CategoryState.cs
//---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.Internal.PropertyEditing.State { using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime; //// Simple category state object that knows how to remember // two boolean flags: the expansion state of the category itself and the // expansion state of its advanced section. // internal class CategoryState : PersistedState { private const bool DefaultCategoryExpanded = true; private const bool DefaultAdvancedSectionExpanded = true; private string _categoryName; private bool _categoryExpanded = DefaultCategoryExpanded; private bool _advancedSectionExpanded = DefaultAdvancedSectionExpanded; //// Basic ctor // // Name of the contained category [SuppressMessage("Microsoft.Performance", "CA1805:DoNotInitializeUnnecessarily")] public CategoryState(string categoryName) { Fx.Assert(!string.IsNullOrEmpty(categoryName), "Expected a full category name"); _categoryName = categoryName; } //// We key these state objects by the category names // public override object Key { get { return _categoryName; } } //// Returns true if any of the contained values differ from the default // public override bool IsSignificant { get { return _categoryExpanded != DefaultCategoryExpanded || _advancedSectionExpanded != DefaultAdvancedSectionExpanded; } } //// Gets or sets a flag indicating whether this category should be expanded or collapsed // public bool CategoryExpanded { get { return _categoryExpanded; } set { _categoryExpanded = value; } } //// Gets or sets a flag indicating whether this category should have its advanced section // expanded or collapsed // public bool AdvancedSectionExpanded { get { return _advancedSectionExpanded; } set { _advancedSectionExpanded = value; } } //// Serializes this object into a simple string (AppDomains like strings). // // Format: CategoryName,CategoryExpanded,AdvancedExpanded;NextCategoryName,CategoryExpanded,AdvancedExpanded;... // Where bools are recorded as 0 = false and 1 = true and ';' and ',' are escaped // //Serialized version of this state object (may be null) protected override string SerializeCore() { return string.Concat( PersistedStateUtilities.Escape(_categoryName), ',', PersistedStateUtilities.BoolToDigit(_categoryExpanded), ',', PersistedStateUtilities.BoolToDigit(_advancedSectionExpanded)); } //// Attempts to deserialize a string into a CategoryState object // // String to deserialize //Instance of CategoryState if the serialized string was valid, null otherwise. public static CategoryState Deserialize(string categoryStateString) { string[] args = categoryStateString.Split(','); if (args == null || args.Length != 3) { return null; } bool? categoryExpanded = PersistedStateUtilities.DigitToBool(args[1]); bool? advancedSectionExpanded = PersistedStateUtilities.DigitToBool(args[2]); if (categoryExpanded == null || advancedSectionExpanded == null) { return null; } string categoryName = PersistedStateUtilities.Unescape(args[0]); if (string.IsNullOrEmpty(categoryName)) { return null; } CategoryState categoryState = new CategoryState(categoryName); categoryState.CategoryExpanded = (bool)categoryExpanded; categoryState.AdvancedSectionExpanded = (bool)advancedSectionExpanded; return categoryState; } } } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. //---------------------------------------------------------------- // Copyright (c) Microsoft Corporation. All rights reserved. //--------------------------------------------------------------- namespace System.Activities.Presentation.Internal.PropertyEditing.State { using System; using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.Runtime; //// Simple category state object that knows how to remember // two boolean flags: the expansion state of the category itself and the // expansion state of its advanced section. // internal class CategoryState : PersistedState { private const bool DefaultCategoryExpanded = true; private const bool DefaultAdvancedSectionExpanded = true; private string _categoryName; private bool _categoryExpanded = DefaultCategoryExpanded; private bool _advancedSectionExpanded = DefaultAdvancedSectionExpanded; //// Basic ctor // // Name of the contained category [SuppressMessage("Microsoft.Performance", "CA1805:DoNotInitializeUnnecessarily")] public CategoryState(string categoryName) { Fx.Assert(!string.IsNullOrEmpty(categoryName), "Expected a full category name"); _categoryName = categoryName; } //// We key these state objects by the category names // public override object Key { get { return _categoryName; } } //// Returns true if any of the contained values differ from the default // public override bool IsSignificant { get { return _categoryExpanded != DefaultCategoryExpanded || _advancedSectionExpanded != DefaultAdvancedSectionExpanded; } } //// Gets or sets a flag indicating whether this category should be expanded or collapsed // public bool CategoryExpanded { get { return _categoryExpanded; } set { _categoryExpanded = value; } } //// Gets or sets a flag indicating whether this category should have its advanced section // expanded or collapsed // public bool AdvancedSectionExpanded { get { return _advancedSectionExpanded; } set { _advancedSectionExpanded = value; } } //// Serializes this object into a simple string (AppDomains like strings). // // Format: CategoryName,CategoryExpanded,AdvancedExpanded;NextCategoryName,CategoryExpanded,AdvancedExpanded;... // Where bools are recorded as 0 = false and 1 = true and ';' and ',' are escaped // //Serialized version of this state object (may be null) protected override string SerializeCore() { return string.Concat( PersistedStateUtilities.Escape(_categoryName), ',', PersistedStateUtilities.BoolToDigit(_categoryExpanded), ',', PersistedStateUtilities.BoolToDigit(_advancedSectionExpanded)); } //// Attempts to deserialize a string into a CategoryState object // // String to deserialize //Instance of CategoryState if the serialized string was valid, null otherwise. public static CategoryState Deserialize(string categoryStateString) { string[] args = categoryStateString.Split(','); if (args == null || args.Length != 3) { return null; } bool? categoryExpanded = PersistedStateUtilities.DigitToBool(args[1]); bool? advancedSectionExpanded = PersistedStateUtilities.DigitToBool(args[2]); if (categoryExpanded == null || advancedSectionExpanded == null) { return null; } string categoryName = PersistedStateUtilities.Unescape(args[0]); if (string.IsNullOrEmpty(categoryName)) { return null; } CategoryState categoryState = new CategoryState(categoryName); categoryState.CategoryExpanded = (bool)categoryExpanded; categoryState.AdvancedSectionExpanded = (bool)advancedSectionExpanded; return categoryState; } } } // 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
- SmiRecordBuffer.cs
- httpserverutility.cs
- Lasso.cs
- ToolStripManager.cs
- ZipIOLocalFileHeader.cs
- TextServicesManager.cs
- TranslateTransform3D.cs
- Message.cs
- ItemCheckedEvent.cs
- DbParameterHelper.cs
- ChangeInterceptorAttribute.cs
- EventLog.cs
- ConfigurationLockCollection.cs
- ExecutionContext.cs
- DataGridAddNewRow.cs
- TypeLibraryHelper.cs
- WebPartExportVerb.cs
- ConnectionStringsSection.cs
- DynamicDocumentPaginator.cs
- SafeViewOfFileHandle.cs
- CancelEventArgs.cs
- VoiceInfo.cs
- Latin1Encoding.cs
- ToolStripItemClickedEventArgs.cs
- NameValueConfigurationElement.cs
- ReaderOutput.cs
- BatchWriter.cs
- ValidationPropertyAttribute.cs
- sqlpipe.cs
- filewebresponse.cs
- DataException.cs
- DataListItemEventArgs.cs
- TextDecorations.cs
- HostingEnvironmentSection.cs
- HttpCacheParams.cs
- HeaderedItemsControl.cs
- PropertyFilterAttribute.cs
- IgnoreDataMemberAttribute.cs
- FormViewInsertEventArgs.cs
- SystemInfo.cs
- SHA1Managed.cs
- SimpleFileLog.cs
- FlowDocumentScrollViewer.cs
- CodeTypeParameterCollection.cs
- EndOfStreamException.cs
- WindowsTooltip.cs
- RegexWorker.cs
- ReadWriteSpinLock.cs
- AliasedSlot.cs
- ModuleBuilder.cs
- RangeContentEnumerator.cs
- ScriptReference.cs
- FormsAuthenticationUserCollection.cs
- Rect.cs
- Light.cs
- XamlFrame.cs
- Sql8ConformanceChecker.cs
- PolyQuadraticBezierSegment.cs
- SqlWorkflowPersistenceService.cs
- VisualBrush.cs
- TransportChannelFactory.cs
- ContentElement.cs
- MexHttpsBindingCollectionElement.cs
- HelpInfo.cs
- UriTemplateQueryValue.cs
- ColorTransformHelper.cs
- UTF7Encoding.cs
- DataGridViewColumnDesignTimeVisibleAttribute.cs
- ParagraphVisual.cs
- SettingsProperty.cs
- Style.cs
- EventLogPermissionEntryCollection.cs
- NumericUpDownAcceleration.cs
- DrawListViewSubItemEventArgs.cs
- PixelFormatConverter.cs
- InitializeCorrelation.cs
- ECDiffieHellmanPublicKey.cs
- ParameterCollection.cs
- DataListItem.cs
- RequiredAttributeAttribute.cs
- RenderData.cs
- InkCanvasSelectionAdorner.cs
- TraceSection.cs
- NativeMethods.cs
- RoleManagerEventArgs.cs
- Popup.cs
- XmlSerializerAssemblyAttribute.cs
- DataServices.cs
- IndicShape.cs
- XPathDocumentIterator.cs
- DisposableCollectionWrapper.cs
- ErrorProvider.cs
- ExtensionQuery.cs
- BamlResourceDeserializer.cs
- NamespaceDecl.cs
- HtmlFormWrapper.cs
- QueryResultOp.cs
- HasCopySemanticsAttribute.cs
- NativeMethods.cs
- TimeSpanMinutesConverter.cs