Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Referring to an object by its name
Message
De
02/12/2004 08:00:51
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Divers
Thread ID:
00966331
Message ID:
00966349
Vues:
7
Stephane,
In your original message I missed it was a private field. Reflection shouldn't be able to reach it.
Also ChangeString in constructor sounds in fact you were after an overloaded constructor.

OK with this new info.
private void SetBinding()
{
  this.Databinding.Add( this.BindProperty, this.BindTable, this.BindTo );
}

//DataBinding class
public void Add(string bindProperty, string bindTable, string bindTo)
{
  this._bindProperty = bindProperty;
  this._bindTable = bindTable;
  this._bindTo = bindTo;
}
PS: Not talking about built-in DataBinding class just outlining code - check that one too.
Cetin

>Thanks Cetin,
>
>It does look like a set method but it's not, here's what i'm trying to do: all my controls have 3 custom properties for databinding:
>
>//Lets say we are in a textBox
>this.BindTo = "Name"; // the field name to bind to
>this.BindTable = "Table1"; // the table to bind to
>this.BindProperty = "Text"; // The property of this control to bind
>this.SetBinding()
>
>private void SetBinding()
>{
>  this.Databinding.Add( this.BindProperty, this.BindTable, this.BindTo );
>}
>
>
>the problem i have is to pass the object from "this.BindTable" to the DataBinding.Add method.
>
>
>>>In this code:
>>>
>>>
>>>class TestClass
>>>{
>>>  private string _myString = "hello";
>>>
>>>  public TestClass()
>>>  {
>>>      this.ChangeString( "_myString", "SomeNewValue" );
>>>  }
>>>  public void ChangeString( string fldname, string newValue )
>>>  {
>>>      // refer to the field fldname and change it's value to newValue
>>>      ??????
>>>  }
>>>}
>>>
>>>
>>>How can i refer to the myString field and change it's value from it's name ?
>>
>>Stephane,
>>You're somewhat describing a Property set method. Thinking you need for a special purpose cehck System.Reflection class. I believe what you need is FieldInfo:
>>
>>System.Reflection.FieldInfo[] fi = this.GetType().GetFields();
>>
>>Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform