Sai*_*han 11 c# extension-methods .net-2.0
我需要什么命名空间才能使我的扩展工作
这是我的扩展方法
using System;
using System.Collections.Generic;
using System.Web;
using System.Data;
namespace MyUtilities
{
public static class DataReaderExtensions
{
public static DataTable ToDataTable(IDataReader reader)
{
DataTable table = new DataTable();
table.Load(reader);
return table;
}
}
}
当我尝试像这样使用它
Session["Master"] = cust.GetCustomerOrderSummary((string)Session["CustomerNumber"]).ToDataTable();
它不起作用.这是.net 2.0
Mar*_*ell 25
标签说.NET 2.0; 如果您正在使用C#3.0(即VS 2008)并针对.NET 2.0,则可以通过声明ExtensionAttribute - 或(更简单)引用LINQBridge来实现.
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Class |
AttributeTargets.Method)]
public sealed class ExtensionAttribute : Attribute { }
}
Run Code Online (Sandbox Code Playgroud)
有了这个,扩展方法将适用于带有C#3.0的.NET 2.0.
| 归档时间: |
|
| 查看次数: |
9096 次 |
| 最近记录: |