我有这个对象:
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);
}
我想要的是再次实际调用相同的方法,以“重启”方法。我做得对吗?这就是我实际上所谓的“递归调用”相同的方法吗?