Esempio n. 1
0
        public static IntPtr FindDataBlockPtrByName(string name)
        {
            ISimObject obj = SimDictionary.Find <ISimObject>(name);

            if (obj != null)
            {
                return(obj.ObjectPtr);
            }
            return(InternalUnsafeMethods.FindDataBlockByName(name));
        }
Esempio n. 2
0
        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);
        }
Esempio n. 3
0
        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));
        }
Esempio n. 4
0
        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);
        }