Code:
/ DotNET / DotNET / 8.0 / untmp / whidbey / REDBITS / ndp / fx / src / Designer / CompMod / System / ComponentModel / Design / Serialization / PrimitiveCodeDomSerializer.cs / 1 / PrimitiveCodeDomSerializer.cs
//------------------------------------------------------------------------------ //// Copyright (c) Microsoft Corporation. All rights reserved. // //----------------------------------------------------------------------------- /* */ namespace System.ComponentModel.Design.Serialization { using System; using System.CodeDom; using System.CodeDom.Compiler; using System.Collections; using System.ComponentModel; using System.ComponentModel.Design; using System.Diagnostics; using System.Reflection; ////// /// Code model serializer for primitive types. /// internal class PrimitiveCodeDomSerializer : CodeDomSerializer { private static readonly string JSharpFileExtension = ".jsl"; private static PrimitiveCodeDomSerializer defaultSerializer; ////// /// Retrieves a default static instance of this serializer. /// internal new static PrimitiveCodeDomSerializer Default { get { if (defaultSerializer == null) { defaultSerializer = new PrimitiveCodeDomSerializer(); } return defaultSerializer; } } ////// /// Serializes the given object into a CodeDom object. /// public override object Serialize(IDesignerSerializationManager manager, object value) { using (TraceScope("PrimitiveCodeDomSerializer::Serialize")) { Trace("Value: {0}", (value == null ? "(null)" : value.ToString())); } CodeExpression expression = new CodePrimitiveExpression(value); if (value != null) { if (value is bool || value is char || value is int || value is float || value is double) { // Hack for J#, since they don't support auto-boxing of value types yet. CodeDomProvider codeProvider = manager.GetService(typeof(CodeDomProvider)) as CodeDomProvider; if (codeProvider != null && String.Equals(codeProvider.FileExtension, JSharpFileExtension)) { // See if we are boxing - if so, insert a cast. ExpressionContext cxt = manager.Context[typeof(ExpressionContext)] as ExpressionContext; Debug.Assert(cxt != null, "No expression context on stack - J# boxing cast will not be inserted"); if (cxt != null) { if (cxt.ExpressionType == typeof(object)) { expression = new CodeCastExpression(value.GetType(), expression); expression.UserData.Add("CastIsBoxing", true); } } } } else if (value is string) { string stringValue = value as string; if (stringValue != null && stringValue.Length > 200) { expression = SerializeToResourceExpression(manager, stringValue); } } else { // Generate a cast for all other types because we won't parse them properly otherwise // because we won't know to convert them to the narrow form. expression = new CodeCastExpression(new CodeTypeReference(value.GetType()), expression); } } return expression; } } } // 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
- SqlClientPermission.cs
- TimeEnumHelper.cs
- TextServicesCompartmentContext.cs
- ServiceMetadataPublishingElement.cs
- EntityWrapper.cs
- StringReader.cs
- SystemIPInterfaceProperties.cs
- RSAPKCS1KeyExchangeFormatter.cs
- ArraySegment.cs
- ExplicitDiscriminatorMap.cs
- CalendarButtonAutomationPeer.cs
- BehaviorEditorPart.cs
- BitmapDownload.cs
- SubpageParagraph.cs
- ContextStack.cs
- Comparer.cs
- WebEventTraceProvider.cs
- DoubleIndependentAnimationStorage.cs
- XmlValidatingReaderImpl.cs
- BufferCache.cs
- LicenseManager.cs
- UriScheme.cs
- WindowsListViewItem.cs
- ControlSerializer.cs
- EditorZoneDesigner.cs
- MsmqHostedTransportManager.cs
- FileAuthorizationModule.cs
- FlowDocumentReader.cs
- Freezable.cs
- ConfigViewGenerator.cs
- _AcceptOverlappedAsyncResult.cs
- RowToFieldTransformer.cs
- DeviceFilterEditorDialog.cs
- CacheMemory.cs
- CDSsyncETWBCLProvider.cs
- AsymmetricSignatureFormatter.cs
- RoleBoolean.cs
- JsonDataContract.cs
- XmlElementAttribute.cs
- TCEAdapterGenerator.cs
- QilXmlReader.cs
- WebBrowserProgressChangedEventHandler.cs
- MenuRendererClassic.cs
- SocketStream.cs
- OperationCanceledException.cs
- RedirectionProxy.cs
- SQLDateTime.cs
- WebControlAdapter.cs
- listviewsubitemcollectioneditor.cs
- IisTraceListener.cs
- PartitionResolver.cs
- XmlDigitalSignatureProcessor.cs
- StrongNamePublicKeyBlob.cs
- ResXBuildProvider.cs
- ScrollProperties.cs
- CompositionTarget.cs
- RemotingServices.cs
- StringReader.cs
- WebBrowserUriTypeConverter.cs
- NativeMethods.cs
- xsdvalidator.cs
- TextEditorThreadLocalStore.cs
- SchemaComplexType.cs
- messageonlyhwndwrapper.cs
- GridViewColumn.cs
- SchemaElementDecl.cs
- StrokeNode.cs
- QilLiteral.cs
- NameTable.cs
- XmlObjectSerializer.cs
- _MultipleConnectAsync.cs
- SymmetricCryptoHandle.cs
- MsmqActivation.cs
- MenuAdapter.cs
- SslSecurityTokenParameters.cs
- ConfigXmlSignificantWhitespace.cs
- DataSetMappper.cs
- SafeCoTaskMem.cs
- PageBreakRecord.cs
- MessageCredentialType.cs
- RoleManagerEventArgs.cs
- RenderDataDrawingContext.cs
- EditorBrowsableAttribute.cs
- IxmlLineInfo.cs
- SubqueryRules.cs
- PropertyDescriptorGridEntry.cs
- ResourceDescriptionAttribute.cs
- DataTableExtensions.cs
- SerializationSectionGroup.cs
- ByteStreamGeometryContext.cs
- CheckBoxField.cs
- PerfCounterSection.cs
- TableItemStyle.cs
- KoreanLunisolarCalendar.cs
- PersonalizationStateInfo.cs
- UdpDiscoveryEndpointElement.cs
- TabletDevice.cs
- StylusCollection.cs
- CompilerErrorCollection.cs
- MetadataItem_Static.cs