Indirection Question

  • Thread starter Thread starter cmitroka
  • Start date Start date
C

cmitroka

I'm writing a C# class and need to do something known to me in Cache (another
language) as indirection. Not sure if the functionality exists in C#, but
could really use some help here. Basically, pretend a method takes in two
string variables: field (and we'll say the value is Name) and fieldvalue (and
we'll say the value is Chris). This is within a public class having a field
of Name. I need that variable to now be set to Chris. Any ideas how I can
accompilsh this without a switch or if/else?
 
I'm writing a C# class and need to do something known to me in Cache (another
language) as indirection. Not sure if the functionality exists in C#, but
could really use some help here. Basically, pretend a method takes in two
string variables: field (and we'll say the value is Name) and fieldvalue (and
we'll say the value is Chris). This is within a public class having a field
of Name. I need that variable to now be set to Chris. Any ideas how I can
accompilsh this without a switch or if/else?

Hi,

Take a look at Reflection,
method(string propName, strnig Value){
this.GetType().InvokeMember(propName,
System.Reflection.BindingFlags.SetProperty, null, new object[]
{ propValue });
}
 
Back
Top