Dave Burke : Freelance .NET Web Developer specializing in Online Communities

Reflection SetValue with Frankie Avalon and Walter Pigeon references

This post demonstrates how to use Reflection to set a property value...using two different approaches.  1) using a GET-SET Frankie Avalon mombo-combo approach, and 2) using a Walter Pigeon GET property value only and setting the reflection value via a method.  It seems reasonable that if more than one value for the SetValue statement is desired that a separate SET method is required. 

Or isn't it??????

// Usercontrol.  A category type of an uploaded document sets file processing logic in the parent page

private bool _blnUploadFile
public bool blnUploadFile
{
 get 
 {
  Type type = this.Parent.Page.GetType();
  object o = type.GetProperty("blnUploadFile").GetValue(this.Parent.Page, null);
  bool _blnUploadFile = bool.Parse(o.ToString());
  return _blnUploadFile;
 }
 set
 {
  Type parentType = this.Parent.Page.GetType();
  type.GetProperty("blnUploadFile", typeof(bool)).SetValue(this.Parent.Page, _blnUploadFile, null);
 }
}

// Using the above approach, in the local control it is required to set two variables....

if (ddSpecialDoc.SelectedItem.Value.ToString() == “its_not_stupid_its_special“)
{
_blnUploadFile = true;
blnUploadFile = true;
}


A preferred method is to employ a get {} property function in the local control and pass the boolean value to a method, as in

public bool blnUploadFile
{
 get 
 {
  Type type = this.Parent.Page.GetType();
  object o = type.GetProperty("blnUploadFile").GetValue(this.Parent.Page, null);
  bool _blnUploadFile = bool.Parse(o.ToString());
  return _blnUploadFile;
 }
}

private void SetUploadFile(bool blnFu)
{
 Type type = this.Parent.Page.GetType();
 type.GetProperty("blnUploadFile", typeof(bool)).SetValue(this.Parent.Page.GetType(); blnFu, null);
}

Reference postscript: I love old SciFi flicks and The Voyage to the Bottom of the Sea is in my rotation.  For several days after each viewing, both Frankie and Walter remain as points of reference for some reason.  And Barbara Eden for obvious reasons.

Comments (0) | Post RSS RSS comment feed

Posted on 5/8/2004 10:26:00 PM by Dave Burke
Categories:
Tags:

Related posts


Powered by BlogEngine.NET 2.0.0.36
Theme by Dave Burke