112 lines
4.0 KiB
C#
112 lines
4.0 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Runtime.InteropServices;
|
|
|
|
namespace System.Runtime.Serialization
|
|
{
|
|
/// <summary>Generates IDs for objects.</summary>
|
|
// Token: 0x02000481 RID: 1153
|
|
[ComVisible(true)]
|
|
[MonoTODO("Serialization format not compatible with.NET")]
|
|
[Serializable]
|
|
public class ObjectIDGenerator
|
|
{
|
|
/// <summary>Initializes a new instance of the <see cref="T:System.Runtime.Serialization.ObjectIDGenerator" /> class.</summary>
|
|
// Token: 0x06002C01 RID: 11265 RVA: 0x00090BB0 File Offset: 0x0008EDB0
|
|
public ObjectIDGenerator()
|
|
{
|
|
this.table = new Hashtable(ObjectIDGenerator.comparer, ObjectIDGenerator.comparer);
|
|
this.current = 1L;
|
|
}
|
|
|
|
/// <summary>Returns the ID for the specified object, generating a new ID if the specified object has not already been identified by the <see cref="T:System.Runtime.Serialization.ObjectIDGenerator" />.</summary>
|
|
/// <returns>The object's ID is used for serialization. <paramref name="firstTime" /> is set to true if this is the first time the object has been identified; otherwise, it is set to false.</returns>
|
|
/// <param name="obj">The object you want an ID for. </param>
|
|
/// <param name="firstTime">true if <paramref name="obj" /> was not previously known to the <see cref="T:System.Runtime.Serialization.ObjectIDGenerator" />; otherwise, false. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="obj" /> parameter is null. </exception>
|
|
/// <exception cref="T:System.Runtime.Serialization.SerializationException">The <see cref="T:System.Runtime.Serialization.ObjectIDGenerator" /> has been asked to keep track of too many objects. </exception>
|
|
// Token: 0x06002C03 RID: 11267 RVA: 0x00090BE4 File Offset: 0x0008EDE4
|
|
public virtual long GetId(object obj, out bool firstTime)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
throw new ArgumentNullException("obj");
|
|
}
|
|
object obj2 = this.table[obj];
|
|
if (obj2 != null)
|
|
{
|
|
firstTime = false;
|
|
return (long)obj2;
|
|
}
|
|
firstTime = true;
|
|
this.table.Add(obj, this.current);
|
|
long num;
|
|
this.current = (num = this.current) + 1L;
|
|
return num;
|
|
}
|
|
|
|
/// <summary>Determines whether an object has already been assigned an ID.</summary>
|
|
/// <returns>The object ID of <paramref name="obj" /> if previously known to the <see cref="T:System.Runtime.Serialization.ObjectIDGenerator" />; otherwise, zero.</returns>
|
|
/// <param name="obj">The object you are asking for. </param>
|
|
/// <param name="firstTime">true if <paramref name="obj" /> was not previously known to the <see cref="T:System.Runtime.Serialization.ObjectIDGenerator" />; otherwise, false. </param>
|
|
/// <exception cref="T:System.ArgumentNullException">The <paramref name="obj" /> parameter is null. </exception>
|
|
// Token: 0x06002C04 RID: 11268 RVA: 0x00090C4C File Offset: 0x0008EE4C
|
|
public virtual long HasId(object obj, out bool firstTime)
|
|
{
|
|
if (obj == null)
|
|
{
|
|
throw new ArgumentNullException("obj");
|
|
}
|
|
object obj2 = this.table[obj];
|
|
if (obj2 != null)
|
|
{
|
|
firstTime = false;
|
|
return (long)obj2;
|
|
}
|
|
firstTime = true;
|
|
return 0L;
|
|
}
|
|
|
|
// Token: 0x1700089A RID: 2202
|
|
// (get) Token: 0x06002C05 RID: 11269 RVA: 0x00090C8C File Offset: 0x0008EE8C
|
|
internal long NextId
|
|
{
|
|
get
|
|
{
|
|
long num;
|
|
this.current = (num = this.current) + 1L;
|
|
return num;
|
|
}
|
|
}
|
|
|
|
// Token: 0x04001100 RID: 4352
|
|
private Hashtable table;
|
|
|
|
// Token: 0x04001101 RID: 4353
|
|
private long current;
|
|
|
|
// Token: 0x04001102 RID: 4354
|
|
private static ObjectIDGenerator.InstanceComparer comparer = new ObjectIDGenerator.InstanceComparer();
|
|
|
|
// Token: 0x02000482 RID: 1154
|
|
private class InstanceComparer : IComparer, IHashCodeProvider
|
|
{
|
|
// Token: 0x06002C07 RID: 11271 RVA: 0x00090CB4 File Offset: 0x0008EEB4
|
|
int IComparer.Compare(object o1, object o2)
|
|
{
|
|
if (o1 is string)
|
|
{
|
|
return (!o1.Equals(o2)) ? 1 : 0;
|
|
}
|
|
return (o1 != o2) ? 1 : 0;
|
|
}
|
|
|
|
// Token: 0x06002C08 RID: 11272 RVA: 0x00090CE4 File Offset: 0x0008EEE4
|
|
int IHashCodeProvider.GetHashCode(object o)
|
|
{
|
|
return object.InternalGetHashCode(o);
|
|
}
|
|
}
|
|
}
|
|
}
|