Code:
/ FX-1434 / FX-1434 / 1.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / CompMod / System / ComponentModel / Design / Serialization / ContainerCodeDomSerializer.cs / 1 / ContainerCodeDomSerializer.cs
//------------------------------------------------------------------------------
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
//-----------------------------------------------------------------------------
namespace System.ComponentModel.Design.Serialization {
using System;
using System.CodeDom;
using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Design;
using System.Diagnostics;
using System.Reflection;
///
/// This class is used to serialize things of type "IContainer". We route all containers
/// to the designer host's container.
///
internal class ContainerCodeDomSerializer : CodeDomSerializer {
private const string _containerName = "components";
private static ContainerCodeDomSerializer _defaultSerializer;
///
/// Retrieves a default static instance of this serializer.
///
internal new static ContainerCodeDomSerializer Default {
get {
if (_defaultSerializer == null) {
_defaultSerializer = new ContainerCodeDomSerializer();
}
return _defaultSerializer;
}
}
///
/// We override this so we can always provide the correct container as a reference.
///
protected override object DeserializeInstance(IDesignerSerializationManager manager, Type type, object[] parameters, string name, bool addToContainer) {
if (typeof(IContainer).IsAssignableFrom(type)) {
object obj = manager.GetService(typeof(IContainer));
if (obj != null) {
Trace("Returning IContainer service as container");
manager.SetName(obj, name);
return obj;
}
}
Trace("No IContainer service, creating default container.");
return base.DeserializeInstance(manager, type, parameters, name, addToContainer);
}
///
/// Serializes the given object into a CodeDom object. We serialize an IContainer by
/// declaring an IContainer member variable and then assigning a Container into it.
///
public override object Serialize(IDesignerSerializationManager manager, object value) {
// See if there is a type declaration on the stack. If there is, create a field representing
// the container member variable.
CodeTypeDeclaration typeDecl = manager.Context[typeof(CodeTypeDeclaration)] as CodeTypeDeclaration;
RootContext rootCxt = manager.Context[typeof(RootContext)] as RootContext;
CodeStatementCollection statements = new CodeStatementCollection();
CodeExpression lhs;
if (typeDecl != null && rootCxt != null) {
CodeMemberField field = new CodeMemberField(typeof(IContainer), _containerName);
field.Attributes = MemberAttributes.Private;
typeDecl.Members.Add(field);
lhs = new CodeFieldReferenceExpression(rootCxt.Expression, _containerName);
}
else {
CodeVariableDeclarationStatement var = new CodeVariableDeclarationStatement(typeof(IContainer), _containerName);
statements.Add(var);
lhs = new CodeVariableReferenceExpression(_containerName);
}
// Now create the container
SetExpression(manager, value, lhs);
CodeObjectCreateExpression objCreate = new CodeObjectCreateExpression(typeof(Container));
CodeAssignStatement assign = new CodeAssignStatement(lhs, objCreate);
assign.UserData["IContainer"] = "IContainer";
statements.Add(assign);
return statements;
}
}
}
// 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
- TableHeaderCell.cs
- SiteMapNodeItemEventArgs.cs
- CoTaskMemSafeHandle.cs
- StructuredTypeEmitter.cs
- ColorAnimation.cs
- TextContainerHelper.cs
- ControlValuePropertyAttribute.cs
- _NativeSSPI.cs
- BinaryParser.cs
- X509ScopedServiceCertificateElementCollection.cs
- MaskInputRejectedEventArgs.cs
- ResourceReferenceExpression.cs
- ProcessModelSection.cs
- ThumbButtonInfo.cs
- ToolStripDropDownClosedEventArgs.cs
- MLangCodePageEncoding.cs
- ProtocolsConfigurationHandler.cs
- _UriTypeConverter.cs
- UnsafeNativeMethodsPenimc.cs
- FunctionDescription.cs
- ApplicationException.cs
- DesignerAutoFormatStyle.cs
- SafeFileMapViewHandle.cs
- QilSortKey.cs
- RangeValidator.cs
- ClientBuildManagerCallback.cs
- SqlProviderServices.cs
- DesignerRegionCollection.cs
- ResourcePool.cs
- WhitespaceRuleReader.cs
- UnmanagedMarshal.cs
- SingleSelectRootGridEntry.cs
- EdmSchemaAttribute.cs
- CheckBox.cs
- RadioButtonBaseAdapter.cs
- AsyncResult.cs
- ApplicationBuildProvider.cs
- TimelineClockCollection.cs
- BitmapData.cs
- MessageDescriptionCollection.cs
- SiteMapNode.cs
- IBuiltInEvidence.cs
- SamlAttributeStatement.cs
- AsyncResult.cs
- EventSinkHelperWriter.cs
- XmlSchemaObjectTable.cs
- TrueReadOnlyCollection.cs
- StoryFragments.cs
- BufferedStream.cs
- SystemIcons.cs
- PasswordPropertyTextAttribute.cs
- HealthMonitoringSection.cs
- MultiBindingExpression.cs
- Expander.cs
- ControlType.cs
- ExceptionValidationRule.cs
- CodeArrayCreateExpression.cs
- Dump.cs
- ExternalException.cs
- EnumerableRowCollectionExtensions.cs
- PointAnimationBase.cs
- SelectionGlyphBase.cs
- SchemaElementLookUpTable.cs
- SqlBuilder.cs
- ExtendedPropertiesHandler.cs
- TagNameToTypeMapper.cs
- FixUpCollection.cs
- LicenseException.cs
- CodeCommentStatement.cs
- RealizationContext.cs
- AudioFileOut.cs
- QueryTask.cs
- PenThreadPool.cs
- HealthMonitoringSection.cs
- RootBrowserWindow.cs
- ValidationSummary.cs
- DBNull.cs
- XdrBuilder.cs
- RepeaterDesigner.cs
- LayoutEvent.cs
- LinqDataView.cs
- WebBrowserDesigner.cs
- ObjectAnimationUsingKeyFrames.cs
- Pair.cs
- NumericUpDown.cs
- DateTimeEditor.cs
- _TransmitFileOverlappedAsyncResult.cs
- XPathScanner.cs
- XamlFilter.cs
- HandledMouseEvent.cs
- HttpResponseHeader.cs
- KeyInterop.cs
- MDIClient.cs
- ItemChangedEventArgs.cs
- SoapTransportImporter.cs
- ApplicationProxyInternal.cs
- DeferredTextReference.cs
- Stopwatch.cs
- AppSettingsSection.cs
- StartFileNameEditor.cs