Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / cdf / src / WF / Common / AuthoringOM / Serializer / PrimitiveCodeDomSerializer.cs / 1305376 / PrimitiveCodeDomSerializer.cs
namespace System.Workflow.ComponentModel.Serialization { using System; using System.CodeDom; using System.ComponentModel; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Collections; using System.Resources; using System.Workflow.ComponentModel.Design; using System.Collections.Generic; using Microsoft.CSharp; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Compiler; using System.CodeDom.Compiler; using System.IO; using System.Reflection; using System.Diagnostics; #region Class PrimitiveCodeDomSerializer // work around : PD7's PrimitiveCodeDomSerializer does not handle well strings bigger than 200 characters, // we push our own version to fix it. internal class PrimitiveCodeDomSerializer : CodeDomSerializer { private static readonly string JSharpFileExtension = ".jsl"; private static PrimitiveCodeDomSerializer defaultSerializer; internal static PrimitiveCodeDomSerializer Default { get { if (defaultSerializer == null) { defaultSerializer = new PrimitiveCodeDomSerializer(); } return defaultSerializer; } } public override object Serialize(IDesignerSerializationManager manager, object value) { CodeExpression expression = new CodePrimitiveExpression(value); if (value == null || value is bool || value is char || value is int || value is float || value is double) { // work aroundf 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); } } } return expression; } String stringValue = value as string; if (stringValue != null) { // WinWS: The commented code breaks us when we have long strings //if (stringValue.Length > 200) //{ // return SerializeToResourceExpression(manager, stringValue); //} //else return expression; } // generate a cast for non-int types because we won't parse them properly otherwise because we won't know to convert // them to the narrow form. // return new CodeCastExpression(new CodeTypeReference(value.GetType()), expression); } } #endregion } // File provided for Reference Use Only by Microsoft Corporation (c) 2007. // Copyright (c) Microsoft Corporation. All rights reserved. namespace System.Workflow.ComponentModel.Serialization { using System; using System.CodeDom; using System.ComponentModel; using System.ComponentModel.Design; using System.ComponentModel.Design.Serialization; using System.Collections; using System.Resources; using System.Workflow.ComponentModel.Design; using System.Collections.Generic; using Microsoft.CSharp; using System.Workflow.ComponentModel; using System.Workflow.ComponentModel.Compiler; using System.CodeDom.Compiler; using System.IO; using System.Reflection; using System.Diagnostics; #region Class PrimitiveCodeDomSerializer // work around : PD7's PrimitiveCodeDomSerializer does not handle well strings bigger than 200 characters, // we push our own version to fix it. internal class PrimitiveCodeDomSerializer : CodeDomSerializer { private static readonly string JSharpFileExtension = ".jsl"; private static PrimitiveCodeDomSerializer defaultSerializer; internal static PrimitiveCodeDomSerializer Default { get { if (defaultSerializer == null) { defaultSerializer = new PrimitiveCodeDomSerializer(); } return defaultSerializer; } } public override object Serialize(IDesignerSerializationManager manager, object value) { CodeExpression expression = new CodePrimitiveExpression(value); if (value == null || value is bool || value is char || value is int || value is float || value is double) { // work aroundf 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); } } } return expression; } String stringValue = value as string; if (stringValue != null) { // WinWS: The commented code breaks us when we have long strings //if (stringValue.Length > 200) //{ // return SerializeToResourceExpression(manager, stringValue); //} //else return expression; } // generate a cast for non-int types because we won't parse them properly otherwise because we won't know to convert // them to the narrow form. // return new CodeCastExpression(new CodeTypeReference(value.GetType()), expression); } } #endregion } // 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
- DefinitionBase.cs
- UnsafeNativeMethods.cs
- VirtualDirectoryMapping.cs
- Block.cs
- CallbackBehaviorAttribute.cs
- RectangleConverter.cs
- HostExecutionContextManager.cs
- DataGridRowClipboardEventArgs.cs
- LateBoundBitmapDecoder.cs
- OracleLob.cs
- HwndKeyboardInputProvider.cs
- CachingHintValidation.cs
- DefaultMemberAttribute.cs
- UshortList2.cs
- LocalizationComments.cs
- CommandBindingCollection.cs
- SmiEventSink_Default.cs
- OleDbRowUpdatingEvent.cs
- _Win32.cs
- KeyTime.cs
- WorkflowItemsPresenter.cs
- AuthenticatingEventArgs.cs
- SettingsAttributeDictionary.cs
- DependencyObjectProvider.cs
- x509store.cs
- COMException.cs
- QilIterator.cs
- CalendarDateRange.cs
- ApplicationHost.cs
- RequestBringIntoViewEventArgs.cs
- XamlToRtfWriter.cs
- Timeline.cs
- GenericWebPart.cs
- DoubleIndependentAnimationStorage.cs
- UshortList2.cs
- SchemaInfo.cs
- LookupBindingPropertiesAttribute.cs
- TraceShell.cs
- Package.cs
- WebConfigurationHost.cs
- WindowsTitleBar.cs
- DefaultEventAttribute.cs
- SHA256Managed.cs
- BufferBuilder.cs
- PropertyEmitter.cs
- Light.cs
- ResourceExpressionEditor.cs
- SessionPageStatePersister.cs
- ExecutionPropertyManager.cs
- SoundPlayerAction.cs
- WebControlParameterProxy.cs
- HtmlMeta.cs
- RadioButtonAutomationPeer.cs
- FlowDocumentReader.cs
- WindowsAuthenticationModule.cs
- SplineKeyFrames.cs
- SQLCharsStorage.cs
- CultureInfoConverter.cs
- Operators.cs
- ExtenderProvidedPropertyAttribute.cs
- ReversePositionQuery.cs
- CodeGotoStatement.cs
- MembershipUser.cs
- SizeFConverter.cs
- DataService.cs
- HWStack.cs
- QuadraticBezierSegment.cs
- Image.cs
- PermissionToken.cs
- XslAst.cs
- BufferedGraphicsManager.cs
- InstanceCompleteException.cs
- XmlSchemaAnnotated.cs
- ACL.cs
- DispatcherEventArgs.cs
- _OSSOCK.cs
- RoleService.cs
- KnownColorTable.cs
- InvalidCastException.cs
- CustomAttributeFormatException.cs
- XmlnsPrefixAttribute.cs
- TdsRecordBufferSetter.cs
- CompoundFileDeflateTransform.cs
- DataControlPagerLinkButton.cs
- ConsumerConnectionPointCollection.cs
- UserControlBuildProvider.cs
- Triangle.cs
- PackWebRequestFactory.cs
- XmlValidatingReaderImpl.cs
- RemotingServices.cs
- PluralizationService.cs
- __Error.cs
- XmlToDatasetMap.cs
- CodeCompileUnit.cs
- SynchronousReceiveElement.cs
- CompilerTypeWithParams.cs
- XmlEntityReference.cs
- QilScopedVisitor.cs
- CopyNamespacesAction.cs
- MarkupWriter.cs