我正在试图弄清楚如何更改硬编码输入(ContactInterval)以允许用户选择投入多少时间。目前设置为20分钟。
以下是锁的创建方式: ContactInterval在Echo.Common.Services.LockManagerServices
中进行了硬编码public Echo.Common.Business.LockingManager.LockItem GetLock(Echo.Common.Business.LockingManager.LockItem.LockType lockType, int entityId, int userId, string userName, string phoneNumber)
{
Echo.Common.Business.LockingManager.LockItem theLock = new Echo.Common.Business.LockingManager.LockItem();
try
{
Echo.Common.Services.LockManagerServices lockManagerServices = new Echo.Common.Services.LockManagerServices();
Echo.Common.Services.LockItem returnedLock = lockManagerServices.GetLock((Echo.Common.Services.LockType)lockType, entityId, userId, userName, phoneNumber);
theLock.UserId = returnedLock.UserId;
theLock.UserName = returnedLock.UserName;
theLock.PhoneNumber = returnedLock.PhoneNumber;
theLock.ExpireSecs = returnedLock.ExpireSecs;
theLock.ContactInterval = returnedLock.ContactInterval;
int respondsID = (int)returnedLock.ResponseId;
theLock.ResponseId = (LockItem.LockResponse)respondsID;
}
catch
{
theLock.ResponseId = LockItem.LockResponse.ERROR;
}
return theLock;
}
答案 0 :(得分:0)
您总是可以尝试重载该方法:
public Echo.Common.Business.LockingManager.LockItem GetLock(Echo.Common.Business.LockingManager.LockItem.LockType lockType, int entityId, int userId, string userName, string phoneNumber, ContactInterval contactInterval = null)
{
Echo.Common.Business.LockingManager.LockItem theLock = new Echo.Common.Business.LockingManager.LockItem();
try
{
Echo.Common.Services.LockManagerServices lockManagerServices = new Echo.Common.Services.LockManagerServices();
Echo.Common.Services.LockItem returnedLock = lockManagerServices.GetLock((Echo.Common.Services.LockType)lockType, entityId, userId, userName, phoneNumber);
theLock.UserId = returnedLock.UserId;
theLock.UserName = returnedLock.UserName;
theLock.PhoneNumber = returnedLock.PhoneNumber;
theLock.ExpireSecs = returnedLock.ExpireSecs;
// check if contactInterval is null, if not, use it, otherwise use default from returnedLock
theLock.ContactInterval = (contactInterval != null) ? contactInterval : returnedLock.ContactInterval;
int respondsID = (int)returnedLock.ResponseId;
theLock.ResponseId = (LockItem.LockResponse)respondsID;
}
catch
{
theLock.ResponseId = LockItem.LockResponse.ERROR;
}
return theLock;
}
这当然假设ContactInterval是它自己的类型。否则,你只需传递它的类型,即:int
,double
,datetime
等。