In my class I have private variables and properties like this.
private string _itemCOde=string.Empty;
private string _itemName=string.Empty;
public string ItemCode
{
get { return _itemCode; }
set { _itemCode = value == null ? value : value.Trim();}
}
public string ItemName
{
get { return _itemName; }
set { _itemName = value == null ? value : value.Trim();}
}
According to this properties I create Item objects after selecting the data from the sql table.
Now, if database table altered and add a new column called cost, then I have to add another property to the class. Without adding new properties to the class is there any way do declare properties according to the table fields dynamically.
You can add a property to a class dynamically. But that's the catch: you have to add it to the class. A property is actually a simple implementation of a thing called a descriptor. It's an object that provides custom handling for a given attribute, on a given class.
Adding attributes to a Python class is very straight forward, you just use the '. ' operator after an instance of the class with whatever arbitrary name you want the attribute to be called, followed by its value.
Theoretically, it can be defined as the ratio of stress to strain resulting from an oscillatory load applied under tensile, shear, or compression mode.
You could use an ExpandoObject
:
Represents an object whose members can be dynamically added and removed at run time.
dynamic expando = new ExpandoObject();
expando.Cost= 42.0;
expando.ItemName = "Shoes";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With