473,386 Members | 1,785 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,386 software developers and data experts.

Want to use Reflextion if it possible in my case

Hello!!

I have the method CollectData that I want to use Reflection on.
I use foreach looping through a collection of DSRow. This DSRow does not
have a property but I can add one if it would solve my problem.
After each lap in the foreach loop I instansiate a Composition object.
In the switch case part I have these statements
case "EAF" :
case "C_min" :
case "C_aim" :
case "C_max" :
case "P" :
case "C" :
case "V" :

meaning that if I come here I have any of these in variable colName "EAF",
"C_min", "C_aim", "C_max", "P,"C" or "V"

In the comp class I also have properties with exact these names "EAF",
"C_min", "C_aim", "C_max", "P,"C" or "V"

What I want if it's possible it to use reflection to update the comp object
by using the properties "EAF", "C_min", "C_aim", "C_max", "P,"C" or "V"
The value to set in these properties is (double)gridRow[j];

I have written something here but I know this is wrong but you out there
might know how I should write instead.
comp.GetType().GetProperty(Value).SetValue(comp,
(double)comp.GetType().GetProperty(colName).GetVal ue(comp, null), null);

public bool CollectData(ref IDialogPostData post)
{
...
foreach( DSRow gridRow in (ArrayList)m_flgLimit.Rows.DataSource )
{
MeltPracDataComposition.Composition comp = new
MeltPracDataComposition.Composition();

for (int j = 0; j < m_flgLimit.Columns.Items.Count; j++)
{
string colName = m_flgLimit.Columns.Items[j].Caption;

switch( colName )
{
case "EAF" :
case "C_min" :
case "C_aim" :
case "C_max" :
case "P" :
case "C" :
case "V" :
//

comp.GetType().GetProperty(Value).SetValue(comp,
(double)comp.GetType().GetProperty(colName).GetVal ue(comp, null), null);
}// end switch
}//end for
...
}//end foreach
...
}

//Tony
Aug 29 '06 #1
1 1495
tony wrote:
Hello!!

I have the method CollectData that I want to use Reflection on.
I use foreach looping through a collection of DSRow. This DSRow does not
have a property but I can add one if it would solve my problem.
After each lap in the foreach loop I instansiate a Composition object.
In the switch case part I have these statements
case "EAF" :
case "C_min" :
case "C_aim" :
case "C_max" :
case "P" :
case "C" :
case "V" :

meaning that if I come here I have any of these in variable colName "EAF",
"C_min", "C_aim", "C_max", "P,"C" or "V"

In the comp class I also have properties with exact these names "EAF",
"C_min", "C_aim", "C_max", "P,"C" or "V"

What I want if it's possible it to use reflection to update the comp object
by using the properties "EAF", "C_min", "C_aim", "C_max", "P,"C" or "V"
The value to set in these properties is (double)gridRow[j];

I have written something here but I know this is wrong but you out there
might know how I should write instead.
comp.GetType().GetProperty(Value).SetValue(comp,
(double)comp.GetType().GetProperty(colName).GetVal ue(comp, null), null);

public bool CollectData(ref IDialogPostData post)
{
...
foreach( DSRow gridRow in (ArrayList)m_flgLimit.Rows.DataSource )
{
MeltPracDataComposition.Composition comp = new
MeltPracDataComposition.Composition();

for (int j = 0; j < m_flgLimit.Columns.Items.Count; j++)
{
string colName = m_flgLimit.Columns.Items[j].Caption;

switch( colName )
{
case "EAF" :
case "C_min" :
case "C_aim" :
case "C_max" :
case "P" :
case "C" :
case "V" :
//

comp.GetType().GetProperty(Value).SetValue(comp,
(double)comp.GetType().GetProperty(colName).GetVal ue(comp, null), null);
}// end switch
}//end for
...
}//end foreach
...
}

//Tony

Hi Tony,

from reading your code this should work:

// get the prop info for the property that matches the
// column
PropertyInfo pi = comp.GetType().GetProperty(colName);

// set the value on the Composition object
double val = (double)gridRow[j];
pi.SetValue(comp, val, null)

HTH,
Andy
--
You can email me directly by removing the NOSPAm below
xm**********@gmxNOSPAm.netNOSPAm
Aug 29 '06 #2

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

Similar topics

5
by: Flipje | last post by:
In my view, there is a major drawback to using attributes: the getter and the setter have identical protection levels. But I usually want the getter to be public and the setter to be protected or...
10
by: cppdev | last post by:
Hi All! I want to clear the string contents from sensitive information such as passwords, and etc. It's always a case that password will appear as string at some point or another. And i feel...
182
by: Jim Hubbard | last post by:
http://www.eweek.com/article2/0,1759,1774642,00.asp
110
by: alf | last post by:
Hi, is it possible that due to OS crash or mysql itself crash or some e.g. SCSI failure to lose all the data stored in the table (let's say million of 1KB rows). In other words what is the worst...
6
by: Cecil Westerhof | last post by:
This is a piece of code from a xslt-file: <xsl:template match="SMS"> <xsl:for-each select='.'> <tr> <td class = "inputDescription"><xsl:value-of select='.' />:</td> <td><textarea class =...
22
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is...
3
by: Markus Dehmann | last post by:
I think this is a question about automatic type conversion, but I didn't find the answer after googling for these words ... I have a class called Value (source see below) which can hold an int...
4
by: =?Utf-8?B?cmF1bGF2aQ==?= | last post by:
c# vs2008 HI: I have to replace a string with somevalue, I use the case any Ideas how to better implement this (avoid regex if possible). (was thinking of a dictionary?) thanks case "a" myvar...
56
by: Adem | last post by:
C/C++ language proposal: Change the 'case expression' from "integral constant-expression" to "integral expression" The C++ Standard (ISO/IEC 14882, Second edition, 2003-10-15) says under...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.