public ConsoleObjectBase As(Type t)
        {
            if (!typeof(ConsoleObjectBase).IsAssignableFrom(t))
            {
                return(null);
            }

            if (this is ISimObject sim)
            {
                return((ConsoleObjectBase)SimDictionary.CreateInstance(t, sim));
            }
            else if (this is UnknownSimObject unk)
            {
                return((ConsoleObjectBase)SimDictionary.CreateInstance(t, unk));
            }

            throw new NotImplementedException();
        }
Example #2
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);
        }
Example #3
0
 public T As <T>() where T : class, ISimObject
 {
     return((T)SimDictionary.CreateInstance(typeof(T), this));
 }
 protected virtual void Dispose(bool pDisposing)
 {
     SimDictionary.UnregisterObjectPtr(ObjectPtr);
 }
 public bool IsDead()
 {
     return(SimDictionary.IsDead(ObjectPtr));
 }