私は現在、GenericのC#の中で学んで研究していますが、作成されたメソッドを実際に使って苦労しています。一般的なメソッドにアクセスすることはできません
私が試してみました:私は(C#のフォームで)行うときに
public class myTestClass
{
class example
{
public static DataTable LINQtoDataTable<T>(IEnumerable<T> data)
{
DataTable dt = new DataTable();
PropertyInfo[] objectProps = null; // Reflection
if (data == null) return null;
foreach (T record in data)
{
if (objectProps == null) objectProps = ((Type)data.GetType()).GetProperties();
foreach (PropertyInfo pi in objectProps)
{
Type collumnType = pi.PropertyType;
if ((collumnType.IsGenericType) && (collumnType.GetGenericTypeDefinition() == typeof(Nullable<>))) collumnType = collumnType.GetGenericArguments()[0];
dt.Columns.Add(new DataColumn(pi.Name, collumnType));
}
}
return dt;
}
}
example ex { get; set; }
public myTestClass()
{
this.ex = new example();
}
}
をしかし:
// Namespace area
myTestClass test;
// Main Method
test = new myTestClass();
test.LINQtoDataTable()
が出てくるか、存在しません。誰も助けてくれますか?私はそれが静的LINQtoDataTable
metode becuse
'LINQtoDataTable'は私的ネストされたクラスの静的メソッドなので、' test.LINQtoDataTable'は動作しません。 – rbm
あなたは静的なクラスとしても必要です(データパラメータはこれに設定する必要があります)、拡張メソッドを少し調べることができます:) – Icepickle