属性方法?

也许我忽略了一些明显的东西,但我在代码中看到过你可能有像“HairColor”这样的属性,然后是像“HairColor.Update()”这样的方法。 这可能吗? Person person = new Person(int personID); person.HairColor = “Blonde”; person.HairColor.Update(); 我有特定的属性,我希望能够根据具体情况进行扩展。 我想我可以有一个名为“HairColorUpdate”的方法,但似乎应该可以使用HairColor.Update()。 我不想使用“set”,因为我并不总是希望以这种方式更新DB。 我这样做的原因是因为我可能只想调用数据库来更新一列而不是调用我的save方法,该方法更新每一列有望提高效率。

如何在asp.net中回帖后将焦点设置在文本框上

我在更新面板中有一个文本框。 当用户键入内容时,我从数据库中获取相关数据并将其填入另一个文本框中。 我的问题是,在autopostback之后,重点放在任何文本框上都会丢失。 我如何使用javascript或代码管理这个,因为我在我使用的代码中使用了两者 System.Web.UI.ScriptManager.GetCurrent(this).SetFocus(this.txtReference); 和JavaScript我发现还有一个 var postbackElement; Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(beginRequest); Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoaded); function beginRequest(sender, args) { postbackElement = args.get_postBackElement(); } function pageLoaded(sender, args) { var updatedPanels = args.get_panelsUpdated(); if (typeof (postbackElement) === “undefined”) { alert(‘if Loop’); return; } else if (postbackElement.id.toLowerCase().indexOf(‘button1’) > -1) { alert(‘else’); for (i = 0; i < updatedPanels.length; i++) { document.getElementById('’).focus(); } } […]

使用IP地址打印到网络打印机

我想发送文件名和打印机的IP地址来指定要打印的打印机。 我收到一条错误消息“访问打印机的设置’xxx.xxx.xxx.xxx’无效。” 当我到printdoc.Print()。 如何根据IP地址设置要打印的打印机? printdoc = new PrintDocument(); printdoc.PrinterSettings.PrinterName = IPAddress.Trim; printdoc.DocumentName = FileName; printdoc.Print(); 如何解决这个问题?它的ac#vs2010独立Windows应用程序

从c#读取android上的logcat

我正在研究制作ac#程序,它将读取来自android设备的logcat输出并将其读入c#程序。 最初它应该在手机连接时执行此操作,并且它不应该要求安装手机上的特定应用程序以便c#程序能够检索logcat输出。 此外,手机不应要求root访问权限。 这是可能的,我在谷歌上找不到任何可能的东西,但我想在这里要求有人提供一些有用的信息。 感谢您的任何帮助,您可以提供

将ScaleTransform应用于图形GDI +

我把这个简单的代码放在一起画一条线。 现在我想将ScaleTransform应用到它10倍; 但是下面的代码不起作用。 var bitmap = new Bitmap(pictureBox1.Size.Width, pictureBox1.Size.Height); var g = Graphics.FromImage(bitmap); pictureBox1.Image = bitmap; var pn = new Pen(Color.Wheat, -1); g.DrawLine(pn, 0, 0, 10, 10); pn.Dispose(); // I’m trying to scaletransform here! g.ScaleTransform(10, 10); 更新: 更新更改的正确方法是什么? 我没有得到任何结果:( g.ScaleTransform(1, 1); pictureBox1.Invalidate();

在Web API中使用ExceptionFilterAttribute

我试图在创建的Web API中实现error handling,需要以JSON格式返回exception详细信息。 我创建了BALExceptionFilterAttribute之类的 public class BALExceptionFilterAttribute : ExceptionFilterAttribute { public override void OnException(HttpActionExecutedContext actionExecutedContext) { base.OnException(actionExecutedContext); actionExecutedContext.Response = actionExecutedContext.Request.CreateResponse(HttpStatusCode.BadRequest, new { error = actionExecutedContext.Exception.Message }); } } 并在Gloal.asax.cs中注册了它们 GlobalConfiguration.Configuration.Filters.Add(new BALExceptionFilterAttribute()); 在我的控制器中,我想抛出exception [HttpGet] [BALExceptionFilter] public HttpResponseMessage Getdetails(string ROOM, DateTime DOB_GT) { if (string.IsNullOrEmpty(ROOM) { return Request.CreateResponse(new { error = “Input paramete cannot be Empty or […]

IEnumerable 的generics方法的重载?

我想要一个generics方法的两个重载: public ReturnType DoStuff(T thing) {…} public ReturnType DoStuff(IEnumerable things) {…} 麻烦当然是IEnumerable本身就是一个匹配第一个签名的类型,所以当我尝试将一个集合传递给这个方法时,它会调用第一个重载。 显然,我可以用不同的方法命名方法以消除歧义。 但是看到方法基本上做同样的事情,我想把它们作为重载。 是否有某种方法在第一个签名中定义T ,以便它不接受IEnumerable作为参数?

为什么在单击ToolStrip按钮两次时抛出NullReferenceException – openFileDialog.showDialog()?

我创建了一个干净的WindowsFormsApplication解决方案,在主窗体上添加了一个ToolStrip ,并在其上放置了一个按钮。 我还添加了一个OpenFileDialog ,因此ToolStripButton的Click事件如下所示: private void toolStripButton1_Click(object sender, EventArgs e) { openFileDialog1.ShowDialog(); } 我没有改变任何其他属性或事件。 有趣的是,当我双击ToolStripButton (第二次单击必须非常快,在对话框打开之前),然后取消两个对话框(或选择一个文件,它并不重要),然后单击客户端主窗体的区域, NullReferenceException崩溃应用程序(post末尾附加的错误详细信息)。 请注意, Click事件是在DoubleClick未执行时实施的 。 更奇怪的是,当OpenFileDialog被任何用户实现的表单替换时, ToolStripButton 阻止被点击两次 。 我在Windows 7 Professional (来自MSDNAA)上使用VS2008和.NET3.5进行最新更新。 我没有在VS中更改很多选项(只有fontsize,工作区文件夹和行编号)。 有谁知道如何解决这个问题? 它在我的机器上是100%可复制的,是否也在其他机器上? 我能想到的一个解决方案是在调用OpenFileDialog.ShowDialog()然后再启用按钮之前禁用该按钮(但这并不好)。 还有其他想法吗? 现在承诺的错误细节: System.NullReferenceException未处理 Message =“对象引用未设置为对象的实例。” 来源= “System.Windows.Forms的” 堆栈跟踪: 在System.Windows.Forms.NativeWindow.WindowClass.Callback(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam) 在System.Windows.Forms.UnsafeNativeMethods.PeekMessage(MSG&msg,HandleRef hwnd,Int32 msgMin,Int32 msgMax,Int32 remove) 在System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID,Int32 reason,Int32 pvLoopData) 在System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 […]

如何删除Access Db的临时ldb文件

我有一个ASP.NET项目。 我正在连接到数据库,然后关闭并处理连接对象。 但是当任何人进入我的网站时,MS Access会创建一个临时的dbname.ldb。 当我想从我的服务器下载我的原始mdb文件时,它将不允许我访问mdb文件。 如果服务器中有ldb文件,我什么也做不了。 它锁定mdb文件,我无法移动它。 所以有什么问题? 我打开连接并关闭它。 那么为什么这个ldb文件在连接关闭后不会自行删除。

使用itextSharp 5.3.3对数字签名和validationPdf文档

我正在尝试使用iTextSharp 5.3.3对服务器(c#)上的pdf文档进行数字签名和validation。 我使用DigiSign(在线工具)生成.Pfx文件,然后使用Windows生成证书(.cer)文件 /// /// Signs a PDF document using iTextSharp library /// /// The path of the source pdf document which is to be signed /// The path at which the signed pdf document should be generated /// A Stream containing the private/public key in .pfx format which would be used to sign the […]