Code:
/ DotNET / DotNET / 8.0 / untmp / WIN_WINDOWS / lh_tools_devdiv_wpf / Windows / wcp / Print / Reach / Serialization / manager / ReachObjectContext.cs / 1 / ReachObjectContext.cs
/*++ Copyright (C) 2004- 2005 Microsoft Corporation All rights reserved. Module Name: ReachObjectContext.cs Abstract: This file contains the implementation representing the context of a Serializable object. This woudl include information about the object itself and all the properties contained within that object Author: [....] ([....]) 1-December-2004 Revision History: --*/ using System; using System.Collections; using System.Collections.Specialized; using System.ComponentModel; using System.Diagnostics; using System.Reflection; using System.Xml; using System.IO; using System.Security; using System.Security.Permissions; using System.ComponentModel.Design.Serialization; using System.Windows.Xps.Packaging; using System.Windows.Documents; using System.Windows.Media; using System.Windows.Markup; namespace System.Windows.Xps.Serialization { internal class SerializableObjectContext : BasicContext { #region Constructor static SerializableObjectContext( ) { _recycableSerializableObjectContexts = new Stack(); } ////// Instantiates an ObjectContext /// /// /// The name of type of the object. /// /// /// The perfix (namespace) of the type of the object. /// /// /// The instance of the object which contained this object as /// one of its properties. /// /// /// The property from which this object was driven to serialization. /// public SerializableObjectContext( string name, string prefix, object target, SerializablePropertyContext serializablePropertyContext ) : base(name, prefix) { // // Validate Input Arguments // if (target == null) { throw new ArgumentNullException("target"); } _targetObject = target; _isComplexValue = false; _backingPropertyContext = serializablePropertyContext; } ////// Instantiates an ObjectContext /// /// /// The instance of the object which contained this object as /// one of its properties. /// /// /// The property from which this object was driven to serialization. /// public SerializableObjectContext( object target, SerializablePropertyContext serializablePropertyContext ) { Initialize(target, serializablePropertyContext); } #endregion Constructor #region Internal Methods ////// Factory method to create ObjectContexts /// /// /// The manager controllig the serialization process. /// /// /// The instance of the object which contained this object as /// one of its properties. /// /// /// The ObjectContext of the parent object of this object. /// /// /// The property from which this object was driven to serialization. /// ////// Critical - Access the SerializationManager GraphContextStack which is a /// ContextStack which is link critical /// /// TreatAsSafe - The context stack is used local to the function. /// All access to the GraphContextStack is marked security critical /// [SecurityCritical, SecurityTreatAsSafe] internal static SerializableObjectContext CreateContext( PackageSerializationManager serializationManager, object serializableObject, SerializableObjectContext serializableObjectParentContext, SerializablePropertyContext serializablePropertyContext ) { // // Check for element pre-existance to avoid infinite loops // in the process of serialization // int stackIndex = 0; object currentObject = null; for(currentObject = serializationManager.GraphContextStack[stackIndex]; currentObject != null; currentObject = serializationManager.GraphContextStack[++stackIndex]) { SerializableObjectContext currentObjectContext = currentObject as SerializableObjectContext; if(currentObjectContext!=null && currentObjectContext.TargetObject == serializableObject) { throw new XpsSerializationException(ReachSR.Get(ReachSRID.ReachSerialization_CycleDetectedInSerialization)); } } SerializableObjectContext serializableObjectContext = _recycableSerializableObjectContexts.Count == 0 ? null : (SerializableObjectContext)_recycableSerializableObjectContexts.Pop(); if(serializableObjectContext == null) { serializableObjectContext = new SerializableObjectContext(serializableObject, serializablePropertyContext); } else { serializableObjectContext.Initialize(serializableObject, serializablePropertyContext); } { // // Namespace related creation within the context // MetroSerializationNamespaceTable parentNamespaceTable = serializableObjectParentContext != null ? serializableObjectParentContext.NamespaceTable : null; if (serializableObjectContext.NamespaceTable == null) { serializableObjectContext.NamespaceTable = new MetroSerializationNamespaceTable(parentNamespaceTable); } } { // // Properties related creation within the context // if(serializableObjectContext.PropertiesCollection == null) { serializableObjectContext.PropertiesCollection = new SerializablePropertyCollection(serializationManager, serializableObject); } else { serializableObjectContext.PropertiesCollection.Initialize(serializationManager, serializableObject); } } serializableObjectContext.Name = serializableObjectContext.TargetObject.GetType().Name; return serializableObjectContext; } ////// To optimize, we build a cache of created contexts /// and recycle them instead of desposing them. /// /// /// Context to recycle. /// internal static void RecycleContext( SerializableObjectContext serializableObjectContext ) { serializableObjectContext.Clear(); _recycableSerializableObjectContexts.Push(serializableObjectContext); } #endregion Internal Methods #region Public Properties ////// Query target object /// public object TargetObject { get { return _targetObject; } } ////// Query/Set namespace informaiton table /// public MetroSerializationNamespaceTable NamespaceTable { get { return _namespaceTable; } set { _namespaceTable = value; } } ////// Query/Set the collection containing all /// the properties of the current object /// public SerializablePropertyCollection PropertiesCollection { get { return _propertiesCollection; } set { _propertiesCollection = value; } } ////// Query/Set the type of the property / object being /// considered for serialization. /// public bool IsComplexValue { get { return _isComplexValue; } set { _isComplexValue = value; } } ////// Query / Set the readability type of the object /// public bool IsReadOnlyValue { get { return _isReadOnlyValue; } set { _isReadOnlyValue = value; } } #endregion Public Properties #region Public Methods ////// Initialize the context /// public void Initialize( object target, SerializablePropertyContext serializablePropertyContext ) { Initialize(); _targetObject = target; _isComplexValue = false; _backingPropertyContext = serializablePropertyContext; if(_backingPropertyContext!=null) { _isComplexValue = _backingPropertyContext.IsComplex; _isReadOnlyValue = _backingPropertyContext.IsReadOnly; } else { _isComplexValue = true; _isReadOnlyValue = false; } } ////// Clear the Context /// public override void Clear() { _targetObject = null; _isComplexValue = false; _isReadOnlyValue = false; _namespaceTable = null; if (_propertiesCollection != null) { _propertiesCollection.Clear(); } base.Clear(); } #endregion Public Methods #region Private Data private object _targetObject; private MetroSerializationNamespaceTable _namespaceTable; private SerializablePropertyCollection _propertiesCollection; private bool _isComplexValue; private bool _isReadOnlyValue; private SerializablePropertyContext _backingPropertyContext; static Stack _recycableSerializableObjectContexts; #endregion Private Data }; } // 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
- AsyncResult.cs
- HttpCacheVary.cs
- PowerEase.cs
- TextParagraphProperties.cs
- MSAAWinEventWrap.cs
- BorderGapMaskConverter.cs
- HttpListenerResponse.cs
- EntityContainerEmitter.cs
- TranslateTransform.cs
- ExtensibleSyndicationObject.cs
- CustomWebEventKey.cs
- CodeRemoveEventStatement.cs
- DataTableTypeConverter.cs
- DefaultShape.cs
- DbExpressionVisitor.cs
- NotifyParentPropertyAttribute.cs
- MessageCredentialType.cs
- MemberPathMap.cs
- Monitor.cs
- EdmTypeAttribute.cs
- AuthenticationModuleElementCollection.cs
- ObjectStateManager.cs
- XPathNodeInfoAtom.cs
- ListViewAutomationPeer.cs
- DragStartedEventArgs.cs
- RtfToXamlLexer.cs
- Brushes.cs
- Cursors.cs
- UnsafeNativeMethodsTablet.cs
- XmlSchemaValidationException.cs
- XmlSchemaSimpleContentRestriction.cs
- ThumbAutomationPeer.cs
- OrthographicCamera.cs
- BindingListCollectionView.cs
- ImageSourceConverter.cs
- Point3DCollectionValueSerializer.cs
- DateTimePicker.cs
- MethodCallExpression.cs
- ServiceTimeoutsBehavior.cs
- GridLengthConverter.cs
- MimeTypeAttribute.cs
- AffineTransform3D.cs
- DataServiceException.cs
- ThicknessAnimationUsingKeyFrames.cs
- MethodRental.cs
- SequenceNumber.cs
- dbdatarecord.cs
- QueryStringParameter.cs
- ModuleBuilderData.cs
- DefaultTextStore.cs
- Expression.cs
- CalculatedColumn.cs
- HybridDictionary.cs
- ICspAsymmetricAlgorithm.cs
- XmlNullResolver.cs
- RequestCachePolicyConverter.cs
- IndentedTextWriter.cs
- LicenseContext.cs
- WindowsAuthenticationEventArgs.cs
- RtfFormatStack.cs
- SQLInt32.cs
- DataGridViewCellParsingEventArgs.cs
- DataGridHeaderBorder.cs
- GetPageCompletedEventArgs.cs
- CapabilitiesRule.cs
- SystemWebExtensionsSectionGroup.cs
- SqlProcedureAttribute.cs
- EmptyQuery.cs
- PolyQuadraticBezierSegment.cs
- TextEndOfSegment.cs
- ResourceAssociationTypeEnd.cs
- SystemEvents.cs
- XmlEnumAttribute.cs
- ObjectDataSource.cs
- PersonalizationAdministration.cs
- DataGridDefaultColumnWidthTypeConverter.cs
- BasicDesignerLoader.cs
- KeySpline.cs
- AmbientValueAttribute.cs
- Rect3D.cs
- PointCollection.cs
- ACE.cs
- CollectionMarkupSerializer.cs
- WebPartConnectionsConnectVerb.cs
- EventArgs.cs
- GridViewRowPresenterBase.cs
- DataGridViewRowHeightInfoNeededEventArgs.cs
- InteropBitmapSource.cs
- CodeBlockBuilder.cs
- XmlFormatExtensionPrefixAttribute.cs
- QuotedStringFormatReader.cs
- SmtpFailedRecipientsException.cs
- SQLBinary.cs
- OutputCacheProfileCollection.cs
- WmlPageAdapter.cs
- base64Transforms.cs
- PropertyChangeTracker.cs
- itemelement.cs
- WorkflowMarkupSerializer.cs
- CRYPTPROTECT_PROMPTSTRUCT.cs