Code:
/ 4.0 / 4.0 / DEVDIV_TFS / Dev10 / Releases / RTMRel / ndp / clr / src / BCL / System / Runtime / Serialization / SerializationInfo.cs / 1305376 / SerializationInfo.cs
// ==++== // // Copyright (c) Microsoft Corporation. All rights reserved. // // ==--== /*============================================================ ** ** Class: SerializationInfo ** ** ** Purpose: The structure for holding all of the data needed ** for object serialization and deserialization. ** ** ===========================================================*/ namespace System.Runtime.Serialization { using System; using System.Reflection; using System.Runtime.Remoting; #if FEATURE_REMOTING using System.Runtime.Remoting.Proxies; #endif using System.Globalization; using System.Diagnostics.Contracts; [System.Runtime.InteropServices.ComVisible(true)] public sealed class SerializationInfo { private const int defaultSize = 4; internal String[] m_members; internal Object[] m_data; internal Type[] m_types; internal int m_currMember; internal IFormatterConverter m_converter; private String m_fullTypeName; private String m_assemName; private Type objectType; private bool isFullTypeNameSetExplicit; private bool isAssemblyNameSetExplicit; [CLSCompliant(false)] public SerializationInfo(Type type, IFormatterConverter converter) { if ((object)type == null) { throw new ArgumentNullException("type"); } if (converter==null) { throw new ArgumentNullException("converter"); } Contract.EndContractBlock(); objectType = type; m_fullTypeName = type.FullName; m_assemName = type.Module.Assembly.FullName; m_members = new String[defaultSize]; m_data = new Object[defaultSize]; m_types = new Type[defaultSize]; m_converter = converter; m_currMember = 0; } public String FullTypeName { get { return m_fullTypeName; } set { if (null==value) { throw new ArgumentNullException("value"); } Contract.EndContractBlock(); m_fullTypeName = value; isFullTypeNameSetExplicit = true; } } public String AssemblyName { get { return m_assemName; } set { if (null==value) { throw new ArgumentNullException("value"); } Contract.EndContractBlock(); m_assemName = value; isAssemblyNameSetExplicit = true; } } public void SetType(Type type) { if ((object)type == null) { throw new ArgumentNullException("type"); } Contract.EndContractBlock(); if (!Object.ReferenceEquals(objectType, type)) { objectType = type; m_fullTypeName = type.FullName; m_assemName = type.Module.Assembly.FullName; isFullTypeNameSetExplicit = false; isAssemblyNameSetExplicit = false; } } public int MemberCount { get { return m_currMember; } } public Type ObjectType { get { return objectType; } } public bool IsFullTypeNameSetExplicit { get { return isFullTypeNameSetExplicit; } } public bool IsAssemblyNameSetExplicit { get { return isAssemblyNameSetExplicit; } } public SerializationInfoEnumerator GetEnumerator() { return new SerializationInfoEnumerator(m_members, m_data, m_types, m_currMember); } private void ExpandArrays() { int newSize; Contract.Assert(m_members.Length == m_currMember, "[SerializationInfo.ExpandArrays]m_members.Length == m_currMember"); newSize = (m_currMember * 2); // // In the pathological case, we may wrap // if (newSizem_currMember) { newSize = Int32.MaxValue; } } // // Allocate more space and copy the data // String[] newMembers = new String[newSize]; Object[] newData = new Object[newSize]; Type[] newTypes = new Type[newSize]; Array.Copy(m_members, newMembers, m_currMember); Array.Copy(m_data, newData, m_currMember); Array.Copy(m_types, newTypes, m_currMember); // // Assign the new arrys back to the member vars. // m_members = newMembers; m_data = newData; m_types = newTypes; } public void AddValue(String name, Object value, Type type) { if (null==name) { throw new ArgumentNullException("name"); } if ((object)type == null) { throw new ArgumentNullException("type"); } Contract.EndContractBlock(); // // Walk until we find a member by the same name or until // we reach the end. If we find a member by the same name, // throw. for (int i=0; i =m_members.Length) { ExpandArrays(); } // // Add the data and then advance the counter. // m_members[index] = name; m_data[index] = value; m_types[index] = type; m_currMember++; } /*=================================UpdateValue================================== **Action: Finds the value if it exists in the current data. If it does, we replace ** the values, if not, we append it to the end. This is useful to the ** ObjectManager when it's performing fixups, but shouldn't be used by ** clients. Exposing out this functionality would allow children to overwrite ** their parent's values. **Returns: void **Arguments: name -- the name of the data to be updated. ** value -- the new value. ** type -- the type of the data being added. **Exceptions: None. All error checking is done with asserts. ==============================================================================*/ internal void UpdateValue(String name, Object value, Type type) { Contract.Assert(null!=name, "[SerializationInfo.UpdateValue]name!=null"); Contract.Assert(null!=value, "[SerializationInfo.UpdateValue]value!=null"); Contract.Assert(null!=(object)type, "[SerializationInfo.UpdateValue]type!=null"); int index = FindElement(name); if (index<0) { AddValue(name, value, type, m_currMember); } else { m_members[index] = name; m_data[index] = value; m_types[index] = type; } } private int FindElement (String name) { if (null==name) { throw new ArgumentNullException("name"); } Contract.EndContractBlock(); BCLDebug.Trace("SER", "[SerializationInfo.FindElement]Looking for ", name, " CurrMember is: ", m_currMember); for (int i=0; i m_currMember) { newSize = Int32.MaxValue; } } // // Allocate more space and copy the data // String[] newMembers = new String[newSize]; Object[] newData = new Object[newSize]; Type[] newTypes = new Type[newSize]; Array.Copy(m_members, newMembers, m_currMember); Array.Copy(m_data, newData, m_currMember); Array.Copy(m_types, newTypes, m_currMember); // // Assign the new arrys back to the member vars. // m_members = newMembers; m_data = newData; m_types = newTypes; } public void AddValue(String name, Object value, Type type) { if (null==name) { throw new ArgumentNullException("name"); } if ((object)type == null) { throw new ArgumentNullException("type"); } Contract.EndContractBlock(); // // Walk until we find a member by the same name or until // we reach the end. If we find a member by the same name, // throw. for (int i=0; i =m_members.Length) { ExpandArrays(); } // // Add the data and then advance the counter. // m_members[index] = name; m_data[index] = value; m_types[index] = type; m_currMember++; } /*=================================UpdateValue================================== **Action: Finds the value if it exists in the current data. If it does, we replace ** the values, if not, we append it to the end. This is useful to the ** ObjectManager when it's performing fixups, but shouldn't be used by ** clients. Exposing out this functionality would allow children to overwrite ** their parent's values. **Returns: void **Arguments: name -- the name of the data to be updated. ** value -- the new value. ** type -- the type of the data being added. **Exceptions: None. All error checking is done with asserts. ==============================================================================*/ internal void UpdateValue(String name, Object value, Type type) { Contract.Assert(null!=name, "[SerializationInfo.UpdateValue]name!=null"); Contract.Assert(null!=value, "[SerializationInfo.UpdateValue]value!=null"); Contract.Assert(null!=(object)type, "[SerializationInfo.UpdateValue]type!=null"); int index = FindElement(name); if (index<0) { AddValue(name, value, type, m_currMember); } else { m_members[index] = name; m_data[index] = value; m_types[index] = type; } } private int FindElement (String name) { if (null==name) { throw new ArgumentNullException("name"); } Contract.EndContractBlock(); BCLDebug.Trace("SER", "[SerializationInfo.FindElement]Looking for ", name, " CurrMember is: ", m_currMember); for (int i=0; i
Link Menu

This book is available now!
Buy at Amazon US or
Buy at Amazon UK
- Switch.cs
- Vector3D.cs
- FixedSOMImage.cs
- UnitySerializationHolder.cs
- ListViewTableCell.cs
- XamlRtfConverter.cs
- AppDomainFactory.cs
- SmtpDigestAuthenticationModule.cs
- ConfigXmlWhitespace.cs
- MailMessageEventArgs.cs
- NonBatchDirectoryCompiler.cs
- CalculatedColumn.cs
- XamlFigureLengthSerializer.cs
- SharedStatics.cs
- TrackingProfile.cs
- StylusOverProperty.cs
- CanonicalFontFamilyReference.cs
- DataSourceXmlAttributeAttribute.cs
- TransformPatternIdentifiers.cs
- RC2.cs
- WebPart.cs
- PrintDialog.cs
- CheckBox.cs
- TreeNodeEventArgs.cs
- DataSourceView.cs
- ObjectFactoryCodeDomTreeGenerator.cs
- ObjectIDGenerator.cs
- FixedDSBuilder.cs
- RemotingConfiguration.cs
- TailCallAnalyzer.cs
- BuildProviderAppliesToAttribute.cs
- columnmapfactory.cs
- TreeView.cs
- ServiceOperationInvoker.cs
- IssuedTokenParametersElement.cs
- FileRegion.cs
- uribuilder.cs
- NamespaceList.cs
- hwndwrapper.cs
- BaseProcessProtocolHandler.cs
- ImageListStreamer.cs
- OleDbConnectionPoolGroupProviderInfo.cs
- MonthChangedEventArgs.cs
- EmissiveMaterial.cs
- RichTextBox.cs
- OdbcRowUpdatingEvent.cs
- WebPartConnectionsDisconnectVerb.cs
- Point3DCollection.cs
- DecimalSumAggregationOperator.cs
- XmlRawWriter.cs
- DateBoldEvent.cs
- ExpressionValueEditor.cs
- StringUtil.cs
- FormViewDesigner.cs
- XmlExpressionDumper.cs
- BoundsDrawingContextWalker.cs
- Condition.cs
- ModelToObjectValueConverter.cs
- MemberExpression.cs
- Evaluator.cs
- PassportAuthentication.cs
- GraphicsContext.cs
- AVElementHelper.cs
- FileClassifier.cs
- CommandPlan.cs
- HtmlInputRadioButton.cs
- ReadOnlyDataSource.cs
- PageTheme.cs
- FragmentNavigationEventArgs.cs
- DataObjectPastingEventArgs.cs
- Attribute.cs
- Encoder.cs
- CodeAttributeArgumentCollection.cs
- _BasicClient.cs
- HttpServerVarsCollection.cs
- SamlAttribute.cs
- DataSvcMapFileSerializer.cs
- OledbConnectionStringbuilder.cs
- GlobalizationAssembly.cs
- CodeDomSerializerException.cs
- FunctionDefinition.cs
- ToolStripSplitButton.cs
- WorkflowWebService.cs
- MimeMultiPart.cs
- ArrangedElement.cs
- XsltFunctions.cs
- Trace.cs
- RefreshPropertiesAttribute.cs
- CollectionsUtil.cs
- _ConnectionGroup.cs
- GridViewColumnCollectionChangedEventArgs.cs
- TypeBuilder.cs
- DictionaryEntry.cs
- AtomContentProperty.cs
- ActivityAction.cs
- ActiveXContainer.cs
- CallbackException.cs
- CellIdBoolean.cs
- CodeComment.cs
- AssemblyHash.cs