public static IntPtr FindDataBlockPtrByName(string name) { ISimObject obj = SimDictionary.Find <ISimObject>(name); if (obj != null) { return(obj.ObjectPtr); } return(InternalUnsafeMethods.FindDataBlockByName(name)); }
public static T FindObjectById <T>(uint id) where T : class, ISimObject { IntPtr objPtr = FindObjectPtrById(id); T obj = SimDictionary.Find <T>(id); if (obj != null && obj.ObjectPtr == objPtr) { return(obj); } obj = (T)FormatterServices.GetUninitializedObject(typeof(T)); obj.SetPointer(objPtr); SimDictionary.RegisterObject(obj); return(obj); }
public static IntPtr FindObjectPtrById(uint id) { InternalUnsafeMethods.FindObjectById_Struct idStruct = new InternalUnsafeMethods.FindObjectById_Struct { id = id }; ISimObject obj = SimDictionary.Find <ISimObject>(id); if (obj != null) { return(obj.ObjectPtr); } return(InternalUnsafeMethods.FindObjectById(idStruct)); }
public static T FindObjectByName <T>(string name) where T : class, ISimObject { T dictObj = SimDictionary.Find <T>(name); if (dictObj != null) { return(dictObj); } T obj = (T)FormatterServices.GetUninitializedObject(typeof(T)); if (obj is IDataBlock) { IntPtr objPtr = FindDataBlockPtrByName(name); if (objPtr == IntPtr.Zero) { objPtr = FindObjectPtrByName(name); } if (objPtr == IntPtr.Zero) { return(default(T)); } obj.SetPointer(objPtr); } else { IntPtr objPtr = FindObjectPtrByName(name); if (objPtr == IntPtr.Zero) { return(default(T)); } obj.SetPointer(objPtr); } if (obj.ObjectPtr == IntPtr.Zero) { return(default(T)); } SimDictionary.RegisterObject(obj); return(obj); }