Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / WinForms / System / WinForms / Design / TableLayoutPanelCodeDomSerializer.cs / 1 / TableLayoutPanelCodeDomSerializer.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
/*
*/
[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode", Scope="member", Target="System.Windows.Forms.Design.TableLayoutPanelCodeDomSerializer..ctor()")]
namespace System.Windows.Forms.Design {
using System;
using System.CodeDom;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Windows.Forms;
using System.ComponentModel.Design.Serialization;
///
/// Custom serializer for the TableLayoutPanel. We need this so we can push the TableLayoutSettings object
/// into the resx in localization mode. This is used by loc tools like WinRes to correctly setup the
/// TableLayoutPanel with all its settings. Note that we don't serialize code to access the settings.
///
internal class TableLayoutPanelCodeDomSerializer : CodeDomSerializer {
private static readonly string LayoutSettingsPropName = "LayoutSettings";
public override object Deserialize(IDesignerSerializationManager manager, object codeObject) {
return GetBaseSerializer(manager).Deserialize(manager, codeObject);
}
private CodeDomSerializer GetBaseSerializer(IDesignerSerializationManager manager) {
return (CodeDomSerializer)manager.GetSerializer(typeof(TableLayoutPanel).BaseType, typeof(CodeDomSerializer));
}
///
/// We don't actually want to serialize any code here, so we just delegate that to the base type's
/// serializer. All we want to do is if we are in a localizable form, we want to push a
/// 'LayoutSettings' entry into the resx.
///
public override object Serialize(IDesignerSerializationManager manager, object value) {
// First call the base serializer to serialize the object.
object codeObject = GetBaseSerializer(manager).Serialize(manager, value);
// Now push our layout settings stuff into the resx if we are not inherited read only and
// are in a localizable Form.
TableLayoutPanel tlp = value as TableLayoutPanel;
Debug.Assert(tlp != null, "Huh? We were expecting to be serializing a TableLayoutPanel here.");
if (tlp != null) {
InheritanceAttribute ia = (InheritanceAttribute)TypeDescriptor.GetAttributes(tlp)[typeof(InheritanceAttribute)];
if (ia == null || ia.InheritanceLevel != InheritanceLevel.InheritedReadOnly) {
IDesignerHost host = (IDesignerHost)manager.GetService(typeof(IDesignerHost));
if (IsLocalizable(host)) {
PropertyDescriptor lsProp = TypeDescriptor.GetProperties(tlp)[LayoutSettingsPropName];
object val = (lsProp != null) ? lsProp.GetValue(tlp) : null;
if (val != null) {
string key = manager.GetName(tlp) + "." + LayoutSettingsPropName;
SerializeResourceInvariant(manager, key, val);
}
}
}
}
return codeObject;
}
private bool IsLocalizable(IDesignerHost host) {
if (host != null) {
PropertyDescriptor prop = TypeDescriptor.GetProperties(host.RootComponent)["Localizable"];
if (prop != null && prop.PropertyType == typeof(bool)) {
return (bool) prop.GetValue(host.RootComponent);
}
}
return false;
}
}
}
// 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
- DataGridViewUtilities.cs
- MetadataPropertyvalue.cs
- MetadataProperty.cs
- PeerApplication.cs
- StyleModeStack.cs
- WebPartZoneBase.cs
- HelpExampleGenerator.cs
- FolderBrowserDialogDesigner.cs
- SystemSounds.cs
- UnionExpr.cs
- Roles.cs
- Cell.cs
- SafeUserTokenHandle.cs
- Calendar.cs
- PngBitmapDecoder.cs
- Quad.cs
- WebBrowserEvent.cs
- TextHidden.cs
- ClientConvert.cs
- CompositeCollectionView.cs
- NativeMethods.cs
- ExceptionNotification.cs
- DataMisalignedException.cs
- DataGridViewColumnEventArgs.cs
- DeferredReference.cs
- Int32.cs
- ListParagraph.cs
- RegistryKey.cs
- CallbackException.cs
- PhysicalFontFamily.cs
- MatrixAnimationBase.cs
- HuffmanTree.cs
- URLAttribute.cs
- WindowsListViewItemStartMenu.cs
- ParameterBuilder.cs
- RadioButtonFlatAdapter.cs
- DataViewListener.cs
- FilterRepeater.cs
- DataError.cs
- Material.cs
- WhitespaceRuleLookup.cs
- ValidatedControlConverter.cs
- ElementMarkupObject.cs
- PointAnimationBase.cs
- Helpers.cs
- RemoteWebConfigurationHost.cs
- PackageRelationshipSelector.cs
- HostProtectionException.cs
- TreeNodeCollection.cs
- AspNetHostingPermission.cs
- TreeNodeCollectionEditor.cs
- DiscoveryInnerClientManaged11.cs
- UnsafeNetInfoNativeMethods.cs
- PolicyLevel.cs
- ExceptionAggregator.cs
- Evaluator.cs
- Profiler.cs
- RuleCache.cs
- GridViewPageEventArgs.cs
- EntityType.cs
- GridItemPatternIdentifiers.cs
- SiteMapNode.cs
- AutomationElementCollection.cs
- CreateUserErrorEventArgs.cs
- LicenseContext.cs
- XamlSerializationHelper.cs
- PackWebRequestFactory.cs
- ToolTipService.cs
- ArraySubsetEnumerator.cs
- FormsAuthenticationConfiguration.cs
- ColumnMapVisitor.cs
- JsonFormatWriterGenerator.cs
- HistoryEventArgs.cs
- bidPrivateBase.cs
- WsatServiceCertificate.cs
- Unit.cs
- HttpModuleCollection.cs
- ColumnMapTranslator.cs
- HtmlToClrEventProxy.cs
- GridViewCommandEventArgs.cs
- ArrayHelper.cs
- XmlComment.cs
- LoginDesigner.cs
- SmtpException.cs
- Compensate.cs
- IImplicitResourceProvider.cs
- WrapPanel.cs
- PrintDialog.cs
- IChannel.cs
- CultureSpecificStringDictionary.cs
- InputLangChangeEvent.cs
- Cell.cs
- ErrorWrapper.cs
- UnmanagedMemoryStream.cs
- UnrecognizedPolicyAssertionElement.cs
- MulticastNotSupportedException.cs
- OdbcParameterCollection.cs
- ValueTable.cs
- SecurityTokenTypes.cs
- XmlSchemaSet.cs