I would like to know if it is possible to modify the members of a structure or class from a derived class (add or remove members dynamically)
public class Base
{
public struct MyStruct
{
public Type originalVar;
}
MyStruct myStruct;
}
public class Derivada : Base
{
public ModificaEnum()
{
//algo asi sería genial
MyStruct.Add(Type, nuevaVar);
MyStruct.Remove(Type, originalVar);
}
}
And what if you use classes that are made for that like the
Dictionary
? These allow you to add/update/remove any property (indexer in this case) without having to generate code at runtime:There is also the type
dynamic
using the classExpandoObject
in c#:Generating properties at runtime is very expensive so you should avoid it. Remember that C# is a typed language and adding runtime type checking functionality to it can cost you.