Example #1
0
        public ResId getId(Resource obj, bool createMissing, OnNewObjectAdded onAddCallback = null, bool throwIfMissing = false, bool throwIfExists = false)
        {
            //int result = ExportUtility.invalidId;
            var result = ResId.invalid;

            if (!isValidObject(obj))
            {
                return(result);
            }
            if (objectMap.TryGetValue(obj, out result))
            {
                if (throwIfExists)
                {
                    throw new System.InvalidOperationException(
                              string.Format("Object {0} already exists with id {1}", obj, result)
                              );
                }
                return(result);
            }
            if (!createMissing)
            {
                if (throwIfMissing)
                {
                    throw new System.InvalidOperationException(
                              string.Format("Could not find id for resource {0}", obj)
                              );
                }
                return(ResId.invalid);
            }

            return(addNewObjectInternal(obj, onAddCallback));
        }
Example #2
0
        protected ResId addNewObjectInternal(Resource obj, OnNewObjectAdded onAddCallback = null)
        {
            if (objectMap.ContainsKey(obj))
            {
                throw new System.ArgumentException("Logic error: duplicate registertation");
            }
            var result = new ResId(objectList.Count);

            objectMap.Add(obj, result);
            objectList.Add(obj);

            if (onAddCallback != null)
            {
                onAddCallback(obj);
            }
            return(result);
        }
Example #3
0
            public int getId(Resource obj, OnNewObjectAdded onAddCallback = null)
            {
                int result = -1;

                if (Object.Equals(obj, null))
                {
                    return(result);
                }
                if (objectMap.TryGetValue(obj, out result))
                {
                    return(result);
                }
                result         = nextId;
                objectMap[obj] = result;
                objectList.Add(obj);
                nextId++;
                if (onAddCallback != null)
                {
                    onAddCallback(obj);
                }
                return(result);
            }
Example #4
0
 public ResId registerObject(Resource obj, OnNewObjectAdded onAddCallback = null)
 {
     return(getId(obj, true, onAddCallback, false, false));
 }