硬编码值到用户输入
问题描述:
我想弄清楚如何改变一个硬编码输入(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;
}
答
你总是可以尝试重载方法:
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
等
+0
感谢您的反馈人。尝试了一些建议,但发现服务需要绕过,因为它对我来说不可接触。没有意识到当Lock过期时它会根据Service中的值自动创建一个新的。 – Jbbanuelos
这与JavaScript有什么关系? – itsme86
'ContactInterval'是一个'System.TimeSpan'吗?如果是这样,您可以将'.TryParse()'或'.TryParseExact()'用户输入转换为所需的'TimeSpan'。 – Filburt
与用户的交流如何? – pm100