すべてのコミュニケーションメソッドを配置するためにインターフェイスクラスを作成した後、他のクラスから継承するインターフェイスクラスを作成しましたが、このクラスの属性をチェックする方法インターフェイスのtypeOfに現在のクラスの型を渡す
public KeyValuePair<string, string> CheckForNonNullArguments()
{
System.Reflection.PropertyInfo[] properties = typeof(BaseBLL).GetProperties();
foreach (System.Reflection.PropertyInfo property in properties)
if (property.GetValue(this, null) != null && (!property.GetValue(this, null).Equals("NULL") && !property.GetValue(this, null).ToString().Equals("0")) && !String.IsNullOrEmpty(property.GetValue(this, null).ToString()))
return new KeyValuePair<string, string>(property.Name.ToString(), property.GetValue(this, null).ToString());
return new KeyValuePair<string, string>("", "");
//if (property.GetValue(this, null) != null) GetName(() => property); ;
}
「BaseBLL」は、インタフェースクラスの名前で、私はそれを私が継承するたびに変更する必要があり、そうする方法はありますか?私はActivatorを試しましたが、それは仕事をしませんでしたか、それを使用する方法を知らなかったのです。
ありがとうございます。呼び出され
public KeyValuePair<string, string> CheckForNonNullArguments(Type @class)
{
System.Reflection.PropertyInfo[] properties = @class.GetProperties();
foreach (System.Reflection.PropertyInfo property in properties)
{
object val = property.GetValue(this, null); // Caching result for better perfs.
string str = val?.ToString();
if (val != null && (!str.Equals("NULL") && !str.Equals("0")) && !String.IsNullOrEmpty(str)
return new KeyValuePair<string, string>(property.Name.ToString(), str);
}
return new KeyValuePair<string, string>(string.Empty, string.Empty);
//if (property.GetValue(this, null) != null) GetName(() => property); ;
}
:
があなたの方法に 'type'がを渡して、それを呼び出すとき:
呼び出されます'CheckForNonNullArguments(typeof(BaseBLL))'は、ジョブを実行します –
ありがとうございます(まだ投票できません^^ ") – Angela