如何在switchcase语句中获取当前用户名
本文关键字:用户 获取 switchcase 语句 | 更新日期: 2023-09-27 18:19:51
我想从case语句中删除硬代码值。现在我正在为不同的用户提供一些硬代码值,比如
ScheduledUtility.ClsISession.OpenSession();
switch (Convert.ToString(System.Security.Principal.WindowsIdentity.GetCurrent().Name))
{
case @"suniln":
AP.ClsBatchInvoice objBatchInvoice = new AP.ClsBatchInvoice(ScheduledUtility.ClsISession.mySession);
objBatchInvoice.ReportId = new Guid("6D783F3C-206C-6576-7273-696F6E3D2231");
objBatchInvoice.PDFFileName = "BatchInvoice";
objBatchInvoice.VBatchInvoice();
break;
case @"vijayk":
VendorInvoice_svc objvendor = new VendorInvoice_svc(objsession.mySession);
objvendor.GetVenderReports();
AP.Aging_svc objaging = new AP.Aging_svc(ScheduledUtility.ClsISession.mySession);
objaging.viewerRptAging_Load();
break;
如何编写事例值并从environment.username
中获取?
"case"只接受常数值,因此不可能放入变量等动态内容。
p.S.-你最好改变你的方法,将用户与预定义的角色相关联,将他们放在常量中,如Enum,并在切换情况下基于预定义的角色制定决策树。