Exemple #1
0
        public static T FindObjectById <T>(uint id) where T : SimObject
        {
            IntPtr objPtr = InternalUnsafeMethods.FindObjectById(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);
        }
Exemple #2
0
        public static T FindObjectByName <T>(string name) where T : SimObject
        {
            T dictObj = SimDictionary.Find <T>(name);

            if (dictObj != null)
            {
                return(dictObj);
            }
            T obj = (T)FormatterServices.GetUninitializedObject(typeof(T));

            if (obj is SimDataBlock)
            {
                IntPtr objPtr = FindDataBlockPtrByName(name);
                if (objPtr == IntPtr.Zero)
                {
                    objPtr = FindObjectPtrByName(name);
                }
                if (objPtr == IntPtr.Zero)
                {
                    return(null);
                }
                obj.SetPointer(objPtr);
            }
            else
            {
                IntPtr objPtr = FindObjectPtrByName(name);
                if (objPtr == IntPtr.Zero)
                {
                    return(null);
                }
                obj.SetPointer(objPtr);
            }
            if (obj.ObjectPtr == IntPtr.Zero)
            {
                return(null);
            }
            SimDictionary.RegisterObject(obj);
            return(obj);
        }