First, you have posted the interface and not class code. Please
update the question with the class code.
Second, the "field" you are trying to read is a actually an indexer. You can read about indexers here:
MSDN[
^]. From the link:
Quote:
Indexers allow instances of a class or struct to be indexed just like arrays. Indexers resemble properties except that their accessors take parameters.
Looking at the code you have posted, here is what I can assume might be done in the class:
static class Program
{
static void Main(string[] args)
{
BugClass classObj = new BugClass();
classObj.Id = 1;
classObj.Name = "First";
int firstId = classObj["Id"];
string firstName = classObj["Name"];
Console.Read();
}
}
public interface IBug
{
dynamic this[string FieldName] { get; set; }
int Id { get; set; }
string Name { get; set; }
}
class BugClass:IBug
{
public dynamic this[string FieldName]
{
get
{
return this.GetType().GetProperty(FieldName).GetValue(this);
}
set
{
this.GetType().GetProperty(FieldName).SetValue(this, value);
}
}
public int Id
{
get;
set;
}
public string Name
{
get;
set;
}
}
Here,
dynamic this
itself does not really hold anything. It merely is an alternate way to play around with class properties. As long as you are reading all the values from the properties, your code should be fine.