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)); }
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); }
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); }
public ResId registerObject(Resource obj, OnNewObjectAdded onAddCallback = null) { return(getId(obj, true, onAddCallback, false, false)); }