Example #1
0
        /// <summary>
        /// Adds an object.
        /// </summary>
        /// <param name="o"></param>
        /// <returns>The object's ID. IDs are unique within any any given object type but not across types.</returns>
        public int Add(object o)
        {
            if (o == null)
            {
                return(-1);
            }
            var type = o.GetType();

            if (!KnownTypes.ContainsKey(type.AssemblyQualifiedName))
            {
                KnownTypes.Add(type.AssemblyQualifiedName, type);
            }
            if (!KnownObjects.ContainsKey(type))
            {
                KnownObjects.Add(type, new List <object>());
            }
//			if (!KnownObjects[type].Contains(o))
            KnownObjects[type].Add(o);
            if (!KnownIDs.ContainsKey(type))
            {
                KnownIDs.Add(type, new SafeDictionary <object, int>());
            }
            var id = KnownObjects[type].Count - 1;

            KnownIDs[type].Add(o, id);
            AddProperties(type);
            return(id);
        }
Example #2
0
        /// <summary>
        /// Gets the ID for an object, or null if the object is unknown.
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public int?GetID(object o)
        {
            if (o == null)
            {
                return(null);
            }
            var type = o.GetType();

            if (KnownIDs.ContainsKey(type) && KnownIDs[type].ContainsKey(o))
            {
                return(KnownIDs[type][o]);
            }
            return(null);
        }