मैं वैल्यू इंजेक्टर को समझने की कोशिश कर रहा था, इसलिए मैं इसे अपने घर के छोटे ओआरएम में उपयोग कर सकता हूं। चूंकि मुझे डेटारो और डेटाटेबल मैपिंग का समर्थन करना चाहिए, इसलिए मैं इस प्रकार के लिए मैपर लागू करने की कोशिश कर रहा हूं। और ईमानदारी से दस्तावेज पर्याप्त नहीं है और मैं इसे एक शॉट देना चाहता था। शायद ओमू या इस पुस्तकालय के कुछ अन्य उपयोगकर्ता जवाब देंगे।वैल्यू इंजेक्टर और डेटाटेबल
यहाँ मेरी DataRow इंजेक्टर
public class DataRowInjection: KnownSourceValueInjection<DataRow>
{
protected override void Inject(DataRow source, object target)
{
for (var i = 0; i < source.ItemArray.Count(); i++)
{
//TODO: Read from attributes or target type
var activeTarget = target.GetProps().GetByName(source.Table.Columns[i].ToString(), true);
if (activeTarget == null) continue;
var value = source.ItemArray[i];
if (value == DBNull.Value) continue;
activeTarget.SetValue(target, value);
}
}
}
इस बहुत अच्छी तरह से काम करता है। तो यहां सवाल यह है कि मैं इसे डेटाटेबल के लिए कैसे कार्यान्वित कर सकता हूं और Ienumarable या IList लौटा सकता हूं। मैं जिस कोड स्निपेट की अपेक्षा करता हूं वह ऐसा है।
public class DataTableInjector : ?????
{
protected override void Inject(DataTable source, IList<T> target) where T : class
{
// Do My Staff
foreach (var row in source.Rows)
{
target[i].InjectFrom<DataRowInjection>(row);
}
//return IList?
}
}
मैं इसे कैसे पूरा कर सकता हूं। आप
यहाँ ~~~~~~ पूरा कोड मैं Omu की मदद
public class DataTableInjection<T> : ValueInjection where T : new()
{
protected override void Inject(object source, object target)
{
var dt = source as DataTable;
var t = target as IList<T>;
foreach (DataRow dr in dt.Rows)
{
var t2 = new T();
t2.InjectFrom<DataRowInjection>(dr);
t.Add(t2);
}
}
}
भयानक :), बहुत आसान लग रहा है – Omu