Anonim bir sınıfa ek özellikler eklemenin bir yolu var mı (veya ekstra özelliklere sahip yeni bir örnek oluştur)?Anonim bir sınıfa fazladan özellik ekleme
string cssClasses = "hide";
object viewData = new { @class = cssClasses };
if (suppliedId != null)
{
// add an extra id property to the viewData somehow...
// desired end result is { @id = suppliedId, @class = cssClasses }
}
// ... code will be passing the viewData as the additionalViewData parameter in asp.mvc's .EditorFor method
Evet, ya bu veya kullanım 'dynamic'' ExpandoObject' yerine :) –
@ PatrykĆwiek Evet, doğru. ExpandoObject tbh'yi çok beğendim, oldukça havalı. –
Niçin 'nesneyi' kodda tutmadın anlamıyorum? Söz konusu her iki isim de türden nesnelerdir. –