473,396 Members | 1,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Dynamically set property

Hi there,

I'm trying to create a function to dynamically set a property from a class.
The idea is to get a general function that works for every class. Although
this function works for classes i created myself, and for standard classes,
this function does not seem to work for classes from webreferences (wsdl).

I wonder why...

This is my code:

public void setProperty(object oTargetObject, string strPropname, object
oProperty)

{

System.Type myType = oTargetObject.GetType();

System.Reflection.PropertyInfo[] properties = myType.GetProperties();

foreach(System.Reflection.PropertyInfo pi in properties)

{

if (pi.CanWrite && pi.Name == strPropname)

{

pi.SetValue(oTargetObject, oProperty, null);

}

}

}
Feb 2 '06 #1
1 1345
Hmm wrong newsgroup... Sorry

Im reposting this message in languages.csharp

"Mark" <vl********@hotmail.com> wrote in message
news:uu*************@TK2MSFTNGP09.phx.gbl...
Hi there,

I'm trying to create a function to dynamically set a property from a
class. The idea is to get a general function that works for every class.
Although this function works for classes i created myself, and for
standard classes, this function does not seem to work for classes from
webreferences (wsdl).

I wonder why...

This is my code:

public void setProperty(object oTargetObject, string strPropname, object
oProperty)

{

System.Type myType = oTargetObject.GetType();

System.Reflection.PropertyInfo[] properties = myType.GetProperties();

foreach(System.Reflection.PropertyInfo pi in properties)

{

if (pi.CanWrite && pi.Name == strPropname)

{

pi.SetValue(oTargetObject, oProperty, null);

}

}

}

Feb 2 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Eric | last post by:
How can I dynamically assign an event to an element? I have tried : (myelement is a text input) document.getElementById('myelement').onKeyUp = "myfnc(param1,param2,param3)"; ...
4
by: Ahmet | last post by:
Hi all; I have one application in which I read form names from database to be opened. I open form with the code below, and call its show method for form to be shown but before this, I must set...
2
by: Duncan Welch | last post by:
Hi, I've got a fairly simple date control, that I'm creating dynamically in my page. The reason for creating it dynamically is that I want the ID to vary, depending on it's situation. The...
0
by: Diane Yocom | last post by:
I'm very new to ASP.Net and probably jumped in a little over my head, but... I'm trying to create a user control that will control navigation through my site. It's sortof like Amazon.com, where...
3
by: Guadala Harry | last post by:
I have this scenario: ASPX Page dynamically loads userControl1 - which in turn dynamically loads userControl2. UserControl2 contains a TextBox Web Server control. When a user clicks a button in...
7
by: Samuel | last post by:
Hi, I am building a page that makes use of user control as a templating technique. The following is that I have in mind and it is actually working: Root/ -- login.aspx -- login.aspx.vb --...
6
by: | last post by:
I have made some user controls with custom properties. I can set those properties on instances of my user controls, and I have programmed my user control to do useful visual things in response to...
12
by: vbnewbie | last post by:
I am having problems accessing properties of dynamically generated objects in VB2005. Can someone please help? In a nutshell: My app creates an equal number of checkboxes and labels that share the...
3
by: MarkusJ_NZ | last post by:
Hi, I am trying to dynamically populate an objects properties using reflection. Specifically, I have an object called the theObj and it has a number of properties. property is a PropertyInfo...
8
by: BillE | last post by:
When I create a control dynamically and it grows according to the content, the control Height property still returns the original default control height instead of the height after expanding. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.