I need to add properties in the GridDataSourceBase class at runtime, can anyone help me how to do this?
public class GridDataSourceBase : IGridDataSource
{
public long Handle { get; set; }
}
I need to add properties in the GridDataSourceBase class at runtime, can anyone help me how to do this?
public class GridDataSourceBase : IGridDataSource
{
public long Handle { get; set; }
}
One way is to use ExpandoObject
.
dynamic objeto = new ExpandoObject();
objeto.Propriedade = 1;
You will most likely have to copy the properties of the old object to this object. You can do this as follows:
public static class DynamicExtensions
{
public static dynamic ToDynamic(this object value)
{
IDictionary<string, object> expando = new ExpandoObject();
var props = TypeDescriptor.GetProperties(value.GetType());
foreach (PropertyDescriptor property in props)
expando.Add(property.Name, property.GetValue(value));
return expando as ExpandoObject;
}
}
var tuple = Tuple.Create(1, 1);
var newTuple = tuple.ToDynamic();
newTuple.Item3 = 1;