[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Serialization
From: |
Rhys Weatherley <address@hidden> |
Subject: |
[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Serialization Formatter.cs, 1.3, 1.4 FormatterServices.cs, 1.4, 1.5 SerializationInfo.cs, 1.6, 1.7 SurrogateSelector.cs, 1.3, 1.4 |
Date: |
Sat, 02 Aug 2003 21:21:26 -0400 |
Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Serialization
In directory subversions:/tmp/cvs-serv13632/runtime/System/Runtime/Serialization
Modified Files:
Formatter.cs FormatterServices.cs SerializationInfo.cs
SurrogateSelector.cs
Log Message:
Implement some TODO's in "System.Runtime.Serialization".
Index: Formatter.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Serialization/Formatter.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** Formatter.cs 26 May 2003 04:41:21 -0000 1.3
--- Formatter.cs 3 Aug 2003 01:21:24 -0000 1.4
***************
*** 101,109 ****
protected abstract void WriteDateTime(DateTime val, String name);
protected abstract void WriteDecimal(Decimal val, String name);
- [TODO]
- protected virtual void WriteMember(String memberName, Object data)
- {
- // TODO
- }
protected abstract void WriteObjectRef(Object obj, String name,
Type memberType);
--- 101,104 ----
***************
*** 111,114 ****
--- 106,190 ----
protected abstract void WriteValueType(Object obj, String name,
Type memberType);
+
+ // Write a member to the serialization stream.
+ protected virtual void WriteMember(String memberName, Object data)
+ {
+ if(data == null)
+ {
+ WriteObjectRef(null, memberName,
typeof(Object));
+ }
+ else if(data is Array)
+ {
+ WriteArray(data, memberName,
data.GetType());
+ }
+ else if(data is bool)
+ {
+ WriteBoolean((bool)data, memberName);
+ }
+ else if(data is byte)
+ {
+ WriteByte((byte)data, memberName);
+ }
+ else if(data is sbyte)
+ {
+ WriteSByte((sbyte)data, memberName);
+ }
+ else if(data is short)
+ {
+ WriteInt16((short)data, memberName);
+ }
+ else if(data is ushort)
+ {
+ WriteUInt16((ushort)data, memberName);
+ }
+ else if(data is int)
+ {
+ WriteInt32((int)data, memberName);
+ }
+ else if(data is uint)
+ {
+ WriteUInt32((uint)data, memberName);
+ }
+ else if(data is long)
+ {
+ WriteInt64((long)data, memberName);
+ }
+ else if(data is ulong)
+ {
+ WriteUInt64((ulong)data, memberName);
+ }
+ else if(data is float)
+ {
+ WriteSingle((float)data, memberName);
+ }
+ else if(data is double)
+ {
+ WriteDouble((double)data, memberName);
+ }
+ else if(data is DateTime)
+ {
+ WriteDateTime((DateTime)data,
memberName);
+ }
+ else if(data is Decimal)
+ {
+ WriteDecimal((Decimal)data, memberName);
+ }
+ else if(data is TimeSpan)
+ {
+ WriteTimeSpan((TimeSpan)data,
memberName);
+ }
+ else
+ {
+ Type type = data.GetType();
+ if(type.IsValueType)
+ {
+ WriteValueType(data,
memberName, type);
+ }
+ else
+ {
+ WriteObjectRef(data,
memberName, type);
+ }
+ }
+ }
}; // class Formatter
Index: FormatterServices.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Serialization/FormatterServices.cs,v
retrieving revision 1.4
retrieving revision 1.5
diff -C2 -r1.4 -r1.5
*** FormatterServices.cs 26 May 2003 04:41:21 -0000 1.4
--- FormatterServices.cs 3 Aug 2003 01:21:24 -0000 1.5
***************
*** 26,30 ****
--- 26,33 ----
using System.Reflection;
+ using System.Security;
using System.Security.Permissions;
+ using System.Runtime.Remoting;
+ using System.Runtime.Remoting.Lifetime;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization.Formatters;
***************
*** 36,43 ****
// Check whether a type can be deserialized.
- [TODO]
public static void CheckTypeSecurity(Type t, TypeFilterLevel
securityLevel)
{
! // TODO
}
--- 39,56 ----
// Check whether a type can be deserialized.
public static void CheckTypeSecurity(Type t, TypeFilterLevel
securityLevel)
{
! #if CONFIG_REMOTING
! if(securityLevel == TypeFilterLevel.Low)
! {
!
if(typeof(IEnvoyInfo).IsAssignableFrom(t) ||
! typeof(ISponsor).IsAssignableFrom(t)
||
! typeof(ObjRef).IsAssignableFrom(t))
! {
! throw new SecurityException
!
(String.Format(_("Security_RemotingCheckType"), t));
! }
! }
! #endif
}
Index: SerializationInfo.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Serialization/SerializationInfo.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -r1.6 -r1.7
*** SerializationInfo.cs 26 May 2003 04:41:21 -0000 1.6
--- SerializationInfo.cs 3 Aug 2003 01:21:24 -0000 1.7
***************
*** 293,296 ****
--- 293,335 ----
}
+ // Get values from this info object, while ignoring case
+ // during name matches.
+ internal String GetStringIgnoreCase(String name)
+ {
+ return (String)GetValueIgnoreCase(name,
typeof(String));
+ }
+ internal Object GetValueIgnoreCase(String name, Type type)
+ {
+ int index;
+ Object value;
+ if(name == null)
+ {
+ throw new ArgumentNullException("name");
+ }
+ if(type == null)
+ {
+ throw new ArgumentNullException("type");
+ }
+ for(index = 0; index < names.Count; ++index)
+ {
+
if(String.Compare((String)(names[index]), name, true) == 0)
+ {
+ value = values[index];
+ if(value != null)
+ {
+
if(type.IsAssignableFrom((Type)(types[index])))
+ {
+ return value;
+ }
+ else
+ {
+ return
converter.Convert(value, type);
+ }
+ }
+ }
+ }
+ return null;
+ }
+
// Get an enumerator for iterating over this information object.
public SerializationInfoEnumerator GetEnumerator()
Index: SurrogateSelector.cs
===================================================================
RCS file:
/cvsroot/dotgnu-pnet/pnetlib/runtime/System/Runtime/Serialization/SurrogateSelector.cs,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -r1.3 -r1.4
*** SurrogateSelector.cs 26 May 2003 04:41:21 -0000 1.3
--- SurrogateSelector.cs 3 Aug 2003 01:21:24 -0000 1.4
***************
*** 25,45 ****
#if CONFIG_SERIALIZATION
public class SurrogateSelector : ISurrogateSelector
{
// Internal state.
private ISurrogateSelector nextSelector;
// Constructor.
- [TODO]
public SurrogateSelector()
{
! // TODO
}
// Implement the ISurrogateSelector interface.
- [TODO]
public virtual void ChainSelector(ISurrogateSelector selector)
{
! // TODO
}
public virtual ISurrogateSelector GetNextSelector()
--- 25,121 ----
#if CONFIG_SERIALIZATION
+ using System.Collections;
+
public class SurrogateSelector : ISurrogateSelector
{
// Internal state.
private ISurrogateSelector nextSelector;
+ private Hashtable table;
+
+ // Key value for the surrogate table.
+ private class KeyInfo
+ {
+ // Internal state.
+ private Type type;
+ private StreamingContext context;
+
+ // Constructor.
+ public KeyInfo(Type type, StreamingContext context)
+ {
+ this.type = type;
+ this.context = context;
+ }
+
+ // Check two KeyInfo objects for equality.
+ public override bool Equals(Object obj)
+ {
+ KeyInfo info = (obj as KeyInfo);
+ if(info != null)
+ {
+ return (info.type == type &&
+
info.context.Equals(context));
+ }
+ return false;
+ }
+
+ }; // class KeyInfo
// Constructor.
public SurrogateSelector()
{
! table = new Hashtable();
! }
!
! // Determine if a selector is in a list of selectors.
! private static bool IsInList(ISurrogateSelector selector,
!
ISurrogateSelector list)
! {
! while(list != null)
! {
! if(list == selector)
! {
! return true;
! }
! list = list.GetNextSelector();
! }
! return false;
}
// Implement the ISurrogateSelector interface.
public virtual void ChainSelector(ISurrogateSelector selector)
{
! // Validate the parameter.
! if(selector == null)
! {
! throw new
ArgumentNullException("selector");
! }
! else if(IsInList(this, selector))
! {
! throw new ArgumentException
! (_("Security_SelectorCycle"));
! }
! ISurrogateSelector temp = selector;
! ISurrogateSelector last = null;
! while(temp != null)
! {
! if(IsInList(temp, this))
! {
! throw new ArgumentException
!
(_("Security_SelectorCycle"));
! }
! last = temp;
! temp = temp.GetNextSelector();
! }
!
! // Add the selector just after this one.
! temp = nextSelector;
! nextSelector = selector;
!
! // Move the original "next selector" to the end
! // of the list for "selector".
! if(temp != null)
! {
! last.ChainSelector(temp);
! }
}
public virtual ISurrogateSelector GetNextSelector()
***************
*** 48,54 ****
}
public virtual ISerializationSurrogate GetSurrogate
! (Type type, StreamingContext context, out ISurrogateSelector
selector)
{
! // TODO
return null;
}
--- 124,155 ----
}
public virtual ISerializationSurrogate GetSurrogate
! (Type type, StreamingContext context,
! out ISurrogateSelector selector)
{
! // Validate the type parameter.
! if(type == null)
! {
! throw new ArgumentNullException("type");
! }
!
! // Look for a surrogate in this selector.
! ISerializationSurrogate surrogate;
! surrogate = (table[new KeyInfo(type, context)]
! as
ISerializationSurrogate);
! if(surrogate != null)
! {
! selector = this;
! return surrogate;
! }
!
! // Look for a surrogate in the next selector.
! if(nextSelector != null)
! {
! return nextSelector.GetSurrogate
! (type, context, out selector);
! }
!
! // We were unable to find a surrogate.
! selector = this;
return null;
}
***************
*** 58,62 ****
ISerializationSurrogate surrogate)
{
! // TODO
}
--- 159,171 ----
ISerializationSurrogate surrogate)
{
! if(type == null)
! {
! throw new ArgumentNullException("type");
! }
! if(surrogate == null)
! {
! throw new
ArgumentNullException("surrogate");
! }
! table.Add(new KeyInfo(type, context),
surrogate);
}
***************
*** 64,68 ****
public virtual void RemoveSurrogate(Type type, StreamingContext context)
{
! // TODO
}
--- 173,181 ----
public virtual void RemoveSurrogate(Type type, StreamingContext context)
{
! if(type == null)
! {
! throw new ArgumentNullException("type");
! }
! table.Remove(new KeyInfo(type, context));
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System/Runtime/Serialization Formatter.cs, 1.3, 1.4 FormatterServices.cs, 1.4, 1.5 SerializationInfo.cs, 1.6, 1.7 SurrogateSelector.cs, 1.3, 1.4,
Rhys Weatherley <address@hidden> <=