Tag: c ++

如何从app.config获取Windows服务名称

我有一个app.config 我的服务安装程序类 [RunInstaller(true)] public class MyServiceInstaller : System.Configuration.Install.Installer { public MyServiceInstaller() { var process = new ServiceProcessInstaller {Account = ServiceAccount.LocalSystem}; var serviceAdmin = new ServiceInstaller { StartType = ServiceStartMode.Manual, ServiceName = “HasService”, DisplayName = “HasService” }; Installers.Add(process); Installers.Add(serviceAdmin); } } 我想从app.config获取服务名称。 var serviceAdmin = new ServiceInstaller { StartType = ServiceStartMode.Manual, ServiceName = GetServiceNameAppConfig(“ServiceName”), DisplayName = […]

在C#中合并RTL Datagridview列标题

我想合并3个Datagridview列标题(第3个,第4个和第5个) 列)和Datagridview的RightToleft属性已启用。 我是用户 这段代码: private void PromotionButton_Click(object sender, EventArgs e) { dataGridView1.ColumnHeadersHeight = dataGridView1.ColumnHeadersHeight * 2; dataGridView1.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGridView1.CellPainting += new DataGridViewCellPaintingEventHandler(dataGridView1_CellPainting); dataGridView1.Paint += new PaintEventHandler(dataGridView1_Paint); dataGridView1.Scroll += new ScrollEventHandler(dataGridView1_Scroll); dataGridView1.ColumnWidthChanged += new DataGridViewColumnEventHandler(dataGridView1_ColumnWidthChanged); } private void dataGridView1_Paint(object sender, PaintEventArgs e) { for (int j = 2; j -1) { Rectangle r2 = e.CellBounds; […]

获取属性名称的扩展方法

我有一个扩展方法来获取属性名称 public static string Name(this Expression<Func> expression) { MemberExpression body = (MemberExpression)expression.Body; return body.Member.Name; } 我称之为 string Name = ((Expression<Func>)(() => this.PublishDateTime)).Name(); 这工作正常,并将PublishDateTime作为字符串返回给我。 但是我对调用语句有一个问题,它看起来太复杂了,我想要这样的东西。 this.PublishDateTime.Name() 有人可以修改我的扩展方法吗?

使用std :: string为PInvoke定制Marshaler

免责声明:C ++ / CLI Noob问题 我正在尝试在签名中具有std :: string的C ++ DLL上使用PInvoke。 目前我只是测试:我的目标是将字符串传递给本机DLL,然后返回它。 本机导出如下所示: #define NATIVE_CPP_API __declspec(dllexport) NATIVE_CPP_API void hello_std(std::string inp, char* buffer) { const char* data = inp.data(); strcpy(buffer, data); } 我正在尝试使用自定义封送器以正常方式对其进行PInvoke: [DllImport(“native_cpp.dll”, EntryPoint = “?hello_std@@YAPADV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@Z”, CallingConvention = CallingConvention.Cdecl)] private static extern void hello_std( [MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(clr_wrapper.string_marshaler))] String inp, StringBuilder buffer); static void Main(string[] args) […]

C解析器在C#或一般.Net

对于我的gradle论文,我需要实现某些静态C代码分析,我正在拼命寻找一个框架/库,它允许我解析C源代码,将其拆分为单个函数,因为每个函数都确定了哪些变量在函数体并自动为代码派生某些注释。 为了这个目的,是否有用C#或一般用.Net类编写的好框架?

关键字“用户”附近的语法不正确

错误是: System.Data.dll中发生了未处理的“System.Data.SqlClient.SqlException”类型exception 附加信息:关键字“用户”附近的语法不正确。 代码是: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace WindowsFormsApplication1 { public partial class Form1 : Form { SqlConnection conn; SqlDataAdapter GameDA; SqlDataAdapter DetailDA; DataSet DetailDS; SqlCommandBuilder cmdBuilder; SqlDataAdapter UserDA; SqlDataAdapter AdministratorDA; SqlDataAdapter OrderDA; DataSet OrderDS; SqlCommandBuilder cmdBuilder2; public Form1() { […]

如何仅绘制DataGridView的单元格背景而不是其内容?

我只需要绘制DataGridView单元格的背景而不是它的Content.But,而我正在绘画时它也会绘制其内容。请帮助我。 我的代码是这样的。 private void Daywisegrid_CellPainting(object sender, DataGridViewCellPaintingEventArgs e) { if (e.RowIndex == 0 ) { using (Brush gridBrush = new SolidBrush(this.Daywisegrid.GridColor)) { using (Brush backColorBrush = new SolidBrush(e.CellStyle.BackColor)) { using (Pen gridLinePen = new Pen(gridBrush)) { // Clear cell e.Graphics.FillRectangle(backColorBrush, e.CellBounds); //Bottom line drawing e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom-1 , e.CellBounds.Right, e.CellBounds.Bottom-1); e.Handled = true; } } […]

HTML Agility Pack解析大小写标签?

我使用HTML Agility Pack效果很好,我对此印象非常深刻 – 但是,我选择的内容是这样的 doc.DocumentNode.SelectSingleNode(“//body”).InnerHtml 如何处理以下情况,使用不同的文件? 我的代码上面只会得到小写版本吗?

在VBA中对C#COM库进行早期绑定

虽然这是一个很长的问题,但编码和测试部分应该很容易重现。 我在C#创建了两个单独的Class Libraries ,我认为我遇到了由我以前的项目和试验中的现有注册表项引起的名称冲突问题。 这是我的两个class级: using System; using System.Runtime.InteropServices; namespace Test { [InterfaceType(ComInterfaceType.InterfaceIsDual), Guid(“ED5D264B-1D80-4A5D-9C14-8297D90B7037”)] public interface ITest { // body } [ClassInterface(ClassInterfaceType.None)] [Guid(“8B261B92-8EC5-4CDC-A551-67DEB42137FF”)] [ProgId(“Test.TestClass”)] public class TestClass : ITest { // body } } 和 using System; using System.Runtime.InteropServices; using ADODB; namespace Test { [InterfaceType(ComInterfaceType.InterfaceIsDual), Guid(“ED5D264B-1D80-4A5D-9C14-8297D90B7037”)] public interface IConnection { // body } [ClassInterface(ClassInterfaceType.None)] [Guid(“8B261B92-8EC5-4CDC-A551-67DEB42137FF”)] […]

UPSERT进入具有动态表名的表

任何更好的UPSERT进入表的方法,提供: 数据以~1行/秒进行upsert 表名是DYNAMIC,使用传递给它的ObjectID参数生成 以下程序:“ORA-00942:表格或视图不存在” CREATE OR REPLACE PROCEDURE PROCEDURE “SPINSERTDATA” ( pObjectID IN RAW, pDateTime IN TIMESTAMP, pValue IN BINARY_DOUBLE, ) AS BEGIN Declare vQueryInsert VARCHAR2(1000); vQueryUpdate VARCHAR2(1000); vTableName VARCHAR2(30); Begin vTableName := FGETTABLENAME(POBJECTID => pObjectID); vQueryUpdate := ‘UPDATE ‘ || vTableName || ‘ SET “VALUE” = :1’; vQueryInsert := ‘INSERT INTO ‘ || vTableName […]