actually, I can make a relation between a table field and a variable by doing this inside my OE:
public class MyOE
{
[Column("AGE_FIELD")]
public int ageField { get; set; }
}
My OE class just need to use this other class:
[AttributeUsage(AttributeTargets.Property, Inherited = true, AllowMultiple = true)]
public class ColumnAtt : Attribute
{
private string name;
public string Name
{
get { return name; }
}
public ColumnAtt (string name)
{
this.name = name;
}
}
Well, using the code above, Im doing a generic method that I will need to get the “Column” value. How I could do that?
Here is my method:
public void CompareTwoObjectsAndSaveChanges<TObjectType>(TObjectType objectA, TObjectType objectB )
{
if(objectA.GetType() == objectB.GetType())
{
foreach (var prop in objectA.GetType().GetProperties())
{
if(prop.GetValue(objectA, null) != prop.GetValue(objectB, null))
{
string colvalue = "";//Here I need to get the Column value of the attribute.
string nameOfPropertyThatChanges = prop.Name;
string objectAValue = prop.GetValue(objectA, null).ToString();
string objectBValue = prop.GetValue(objectB, null).ToString();
}
}
}
}
You need to use reflection to get the attributes applied to your object. If you know the attribute is always going to be
ColumnAtt, then you can do something like this to get the value:This makes use of the
GetCustomAttributes(...)method.