小编NIl*_*nke的帖子

避免在Type.GetType()中给出命名空间名称

Type.GetType("TheClass");
Run Code Online (Sandbox Code Playgroud)

null如果namespace不存在则返回如下:

Type.GetType("SomeNamespace.TheClass"); // returns a Type object 
Run Code Online (Sandbox Code Playgroud)

有没有办法避免给出这个namespace名字?

c# reflection types c#-4.0

23
推荐指数
3
解决办法
1万
查看次数

检查Xml节点是否具有属性

如何检查节点是否具有特定属性.

我做的是:

string referenceFileName = xmlFileName;
XmlTextReader textReader = new XmlTextReader(referenceFileName);

while (textReader.Read())
{
  XmlNodeType nType = textReader.NodeType;

  // if node type is an element
  if (nType == XmlNodeType.Element)
  {
    if (textReader.Name.Equals("Control"))
    {
      if (textReader.AttributeCount >= 1)
      {
        String val = string.Empty;
        val = textReader.GetAttribute("Visible");
        if (!(val == null || val.Equals(string.Empty)))
        {

        }
      }
    }
  }
Run Code Online (Sandbox Code Playgroud)

是否有任何功能来检查给定属性是否存在?

c# xml

10
推荐指数
2
解决办法
3万
查看次数

如何在 C# 中进行性能测试

如何在 C# 中测试性能?

我现在所知道的就是使用:

Stopwatch sw = new Stopwatch();

sw.Start();
{
     //code to test
}
sw.Stop();
Run Code Online (Sandbox Code Playgroud)

还有其他方法可以做到这一点还是上述方法错误?

c# testing c#-4.0

8
推荐指数
1
解决办法
2万
查看次数

如何使用imageList控件

我有一些图像,我手动添加到imageList Cotrol.现在我需要从imageList中删除thart图像,具体取决于键索引并设置为面板背景.

我该怎么办

.net c# imagelist winforms

8
推荐指数
1
解决办法
7万
查看次数

如何保护dll函数不被我的应用程序使用?

我想限制其他应用程序使用我编写的dll函数.

例如.如果我有data.dll包含两个函数.

public void InsertInToDatabse();
public void ClearDatabase();
Run Code Online (Sandbox Code Playgroud)

现在如果我的应用程序调用了InsertInToDatabse()并正在做其他工作,直到这个时候,如果其他一些应用程序通过引用database.dll调用ClearDatabase(),那么数据库就会被废弃.那么如何限制对这些函数的调用呢第三方申请?

c# security design-patterns c#-4.0

8
推荐指数
1
解决办法
6171
查看次数

在将Html转换为Pdf时显示Unicode字符

我正在使用itextsharp dll将HTML转换为PDF.

HTML有一些Unicode字符,如α,β...当我尝试将HTML转换为PDF时,Unicode字符不会显示在PDF中.

我的功能:

Document doc = new Document(PageSize.LETTER);

using (FileStream fs = new FileStream(Path.Combine("Test.pdf"), FileMode.Create, FileAccess.Write, FileShare.Read))
{
    PdfWriter.GetInstance(doc, fs);

    doc.Open();
    doc.NewPage();

    string arialuniTff = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts),
                                      "ARIALUNI.TTF");

    BaseFont bf = BaseFont.CreateFont(arialuniTff, BaseFont.IDENTITY_H, BaseFont.EMBEDDED);

    Font fontNormal = new Font(bf, 12, Font.NORMAL);

    List<IElement> list = HTMLWorker.ParseToList(new StringReader(stringBuilder.ToString()),
                                                 new StyleSheet());
    Paragraph p = new Paragraph {Font = fontNormal};

    foreach (var element in list)
    {
        p.Add(element);
        doc.Add(p);
    }

    doc.Close();
}
Run Code Online (Sandbox Code Playgroud)

c# unicode itext

8
推荐指数
2
解决办法
2万
查看次数

parentForm Reference如何为null?

我有一个应用程序,我在表单上添加了一个usercontrol.当我签this.parentForm入userControl构造函数时,它给出了一个空引用

我的userControl代码就像

public UserControl1()
        {
            InitializeComponent();
            if (this.ParentForm != null)//ParentReference is null
            {
                MessageBox.Show("Hi");//Does Not get Called
            }
        }
Run Code Online (Sandbox Code Playgroud)

c# user-controls c#-4.0

5
推荐指数
1
解决办法
5151
查看次数

如何在保存到磁盘之前压缩文件?

我想在物理上保存在磁盘上之前压缩文件.

我尝试使用压缩和解压缩方法(MSDN示例代码),但所有方法都需要一个已经物理存储在磁盘上的文件.

c# c#-4.0

5
推荐指数
1
解决办法
2784
查看次数

与Access数据库的连接池

我有一个应用程序经常从Access数据库中读取数据,有没有办法使用连接池?

我的Open Databse方法: -

private bool OpenDatabaseConnection(string databaseName)
{
    try
    {
        string connectionString = "Provider = Microsoft.Jet.OLEDB.4.0; " +
            "Data Source = " + databaseName + ";";
        settingsDbConn = new OleDbConnection(connectionString);
        settingsDbConn.Open();
    }
    catch (Exception)
    {
        return false;
    }

    return true;
}
Run Code Online (Sandbox Code Playgroud)

c# ms-access connection-pooling c#-4.0

5
推荐指数
1
解决办法
2837
查看次数

如何访问excel文件的当前行索引?

public bool StoreInExecel(String name,String csFIleName)
{
    int cellno = ;//Initialize to current row no
    Microsoft.Office.Interop.Excel.Application excelApp = new Microsoft.Office.Interop.Excel.Application();
    Microsoft.Office.Interop.Excel.Workbook workbook = (Microsoft.Office.Interop.Excel.Workbook)excelApp.Workbooks.Add(Missing.Value);
    Worksheet worksheet;

    // Opening excel file
    workbook = excelApp.Workbooks.Open(fileName, 0, false, 5, "", "", true, XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);

    // Get first Worksheet
    worksheet = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets.get_Item(1);

    // Setting cell values

    ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[cellno,"B"]).Value2 = "5";
    ((Microsoft.Office.Interop.Excel.Range)worksheet.Cells[cellno,"B"]).Value2 = "7";

    workbook.Save();
    workbook.Close(0, 0, 0);
    //excelApp.Quit();   
    return true;
}
Run Code Online (Sandbox Code Playgroud)

我想将“cellno”初始化为 excel 文件的当前行索引,以免数据被覆盖。是否有任何特定的函数来获取填充的行数?

c# c#-4.0

3
推荐指数
1
解决办法
6494
查看次数