I Have a class that contains a string which is use to store multiple value (think in term of xml description) and an override of [] to put value in the string and getting it.
class Entity
{
private String _Data;
public String Data
{
get { return (String)_Data; }
set { _Data=value;}
}
public Object this[String propertyname]
{
get
{
return GetPropertyValue(propertyname);
}
set
{
SetPropertyValue(propertyname,Value);
}
}
private String GetPropertyValue(String propname)
{
if (Data == null) return "";
String fbalise = "<" + propname + ">";
int indexstart = Data.IndexOf(fbalise);
if (indexstart == -1)
//throw new Exception("Cannot Get Value because balise for " + propname + " does not exist");
return null;
indexstart += fbalise.Length;
String ebalise = "</" + propname + ">";
int caraclength = Data.IndexOf(ebalise, indexstart) - indexstart;
return Data.Substring(indexstart, caraclength);
}
private void SetPropertyValue(String propname, String valuetoinsert)
{
if (Data == null) Data = "";
String fbalise = "<" + propname + ">";
String ebalise = "</" + propname + ">";
int indexstart = Data.IndexOf(fbalise);
if (indexstart == -1)
{
indexstart = Data.Length;
Data = Data + fbalise + ebalise;
}
indexstart += fbalise.Length;
int caraclength = Data.IndexOf(ebalise, indexstart) - indexstart;
String lastvalue = Data.Substring(indexstart, caraclength);
if (lastvalue != valuetoinsert)
{
Data = Data.Remove(indexstart, caraclength);
Data = Data.Insert(indexstart, valuetoinsert);
}
}
}
Now I have a List<Entity>
that i want to bind to a gridview by setting the datasource of the gridview.
after the binding it s only show the Data as column with all my text. (it s normal, i m ok with that, it s the normal rule) But Is it possible to specified that my binding, instead of research property, use the [] to get data and bind it to appropriate column (for example if i have a column "Name", call entity["Name"] instead of entity.Name which is not existing.....