我有这个对象:
public class ObjectDisplay
{
public int mMasterObjectID { get; set; }
public ObjectInfo mMasterObject { get; set; }
public int mChildObjectID { get; set; }
public ObjectInfo mChildObject { get; set; }
public ObjectDisplay()
{
mMasterObject = new ObjectInfo();
mChildObject = new ObjectInfo();
}
}
并且是一个类,在不正常Object Display
的情况下将主对象(始终存在的主要对象)和子对象分组。ObjectInfo.ObjectType
我有这种方法可以为我获取这些项目:
public Object GetObjectDisplayByID(int _objectID)
{
Object objectToReturn = new Object();
if (objectToReturn.mMasterObject == null)
{
return null;
}
if (objectToReturn.mMasterObject.ObjectType != "Normal")
{
if (objectToReturn.mMasterObject == null && objectToReturn.mChildObject == null)
{
mObjectDAL.LinkObjects();
return GetObjectDisplayByID(objectToReturn.mMasterObject.mObjectID);
}
if (objectToReturn.mMasterObject.mMasterObjectID != null)
{
// If we are here then the primary object is in fact a child object.
// We need to swap the objects and fetch the primary object which will become the child object.
ObjectInfo child = objectToReturn.mMasterObject;
objectToReturn.mMasterObject = mObjectDAL.GetObjectByID((int)child.mMasterObjectID);
objectToReturn.mMasterObjectID = objectToReturn.mMasterObject.mObjectID;
objectToReturn.mChildObject = child;
objectToReturn.mChildObjectID = child.mObjectID;
}
else
{
if (objectToReturn.mMasterObject.mChildObjectID == null)
{
// The links are not made yet and we would need to redo them.
mObjectDAL.LinkObjects();
return mObjectDAL.GetObjectDisplayByID(objectToReturn.mMasterObject.mObjectID);
}
objectToReturn.mChildObject = mObjectDAL.GetObjectByID((int)objectToReturn.mMasterObject.mChildObjectID);
objectToReturn.mChildObjectID = objectToReturn.mChildObject.mObjectID;
}
}
return objectToReturn;
}
我的主要问题是,通过这些行,我已经做到了,如果还没有 ID,则意味着尚未建立链接。我调用一个内部方法来做链接:
if (objectToReturn.mMasterObject.mChildObjectID == null)
{
// The links are not made yet and we would need to redo them.
mObjectDAL.LinkObjects();
return mObjectDAL.GetObjectDisplayByID(objectToReturn.mMasterObject.mObjectID);
}
我想要的是再次实际调用相同的方法,以“重新启动”该方法。我做对了吗?那是我实际上所说的“递归调用”相同的方法吗?