|
|
I don't understand. I'm beginner.
please give more tip to me, thank so much.
|
|
|
|
|
|
Hi All,
i am working on a project where we need to access some "property / member variable" at run time. i will explain in detail below:-
suppose there is a class called T which has some 4 member variables and 4 properties named A,B,C and D for them.
I will get a list from DB, which contains name of fields which i have to set property for in my code. till then name of field and thier numbers are unknown, because of dynamic nature of number of fields in my class.
suppose i get list which contains "B","D" only. now i need to set value for property B and D of object (type / class T)
Now what i need is something like this:-
string strfieldname = "B" // string which saves each field name from field list
T.B=20 // this is what i want to achieve, but htis is static but i can't write static code as field name is not concrete / decided at compile time.
here this line of code
T.B=20
shall be able to act as T.C, T.D, T.A based on field name string value saved in strfieldname.
is it any how possible? please help me as i am running into big trouble...
People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily
Akhilesh Singh
|
|
|
|
|
here2learn wrote: is it any how possible?
Yes, it is. It's called Reflection[^]
|
|
|
|
|
Hi Giorgi... thanks for your time for replying.
actually in core of my question, i wanted to know how to access a class's property if you know property name, i know we can do with reflection, but frankly speeking don't have any experience with reflection, so i don't know how to achieve it. i have long list of fields in my application, and the class i am referring to is actually web service's exposed class with dynamic fileds exposed.
Also security is not a risk , as it is just intranet application and i will take care of other risks in some way...
i am again explaining my question with another example, in case i was not bit clear first time...
A practical example:
suppose my class is System.Type and i want to set value to it's Delimiter property, like this i will need to set some proerties too, but i don't know it's delimiter or something else.
so i need to write this logic somehow:-
System.Type.NameOfField = "Some Value"; // here after ., NameOfField represents property name which i want to set i could be delimiter or other proerties...
could you please elaborate little bit on your suggestion of reflection as solution...
People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily
Akhilesh Singh
|
|
|
|
|
Well, if you know that it can be done by reflection why don't you start exploring it instead of voting down all replies?
As you need to work with properties of a class, it's not difficult to find that the class you need is called PropertyInfo
|
|
|
|
|
Thanks for suggestion, i will try based on your suggestion.
People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily
Akhilesh Singh
|
|
|
|
|
|
Not sure if I have fully understood, but what about a dictionary?
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Bob, i think i need to rely on reflection only, but how i don't know...
People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily
Akhilesh Singh
|
|
|
|
|
Like Giorgi has suggested, reflection is the way to do this.
I would be slightly careful with this though. Your basically allowing the data stored in the database to define what methods get called. What if someone nasty changed the database values to call a method that did something bad.
If you only have 4 different properties that you want to call dynamically, I would consider doing it with a switch statement. Just switch on the database value, and call the appropriate property. This way you are validating that the database value is something you expect.
I know your example was simplified, and your probably doing something more complex, so maybe a simple switch isn't appropriate. Just be aware that allowing methods to be dynamically called based on database values (Which could essentially be user input) you open up the risk of some kind of method name injection attack.
Simon
|
|
|
|
|
Hi Simon, thanks for good suggestions...
in my case i have long list of proerties which are going to be assigned value at run time, also security is not much concern as i have plans for that some way.
also i won't call methods dynamically as though methods are dynamic, i will be using only which are static ones.
i hope to get some more suggestion from you, to achieve it using reflection or some other way...
People often say that motivation doesn't last. Well, neither does bathing - that's why we recommend it daily
Akhilesh Singh
|
|
|
|
|
Has anyone figured out how to detect the movement of the mouse wheel when the mouse is over a listview control?
Darryl Borden
Principal IT Analyst
dborden@eprod.com
|
|
|
|
|
You can create your own class that derives from ListView, override WndProc and catch WM_MOUSEWHEEL to raise an event and/or handle it directly there.
[edit] WM constants[^]
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
You can directly and eventhandler Mouse_Wheel (sth like that) to the listview you use.
|
|
|
|
|
Seraph_summer is correct - for some reason MS have hidden it from the designer but it's available in the editor. I'll check the source later and see if I can figure out why!
listView1.MouseWheel += new MouseEventHandler(listView1_MouseWheel);
void listView1_MouseWheel(object sender, MouseEventArgs e)
{
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia)
|
|
|
|
|
Hello
How to get processor id of Server.
I want to get the processor id of network server.
A function that accepts the IP then return the processor ID of that Processor have the given IP.
Any idea???
Thanks
Syed Shahid Hussain
|
|
|
|
|
You either use the WMI with the Processor class in WMI and then you will right the methods to do so ... or use the already wrapped class for WMI managment System.Managment where the class to use is the Win32_Processor ...
Any way here is a sample example of retrieving Processor Information using System.Managment for a local machine ... read about the subject more and you will get how to get it using another machine (you map your IP to machine name then use machine name with System.Managment ... something like that ) http://friendstertalk.com/t50165-Use-WMI-to-get-processor-information-%5BC%23%5D.html[^]
Sincerely Samer Abu Rabie
Note: Please remember to rate this post to help others whom reading it.
|
|
|
|
|
The "processor ID" is not really a unique ID. It's a series of capability flags. Therefore, if you have two servers running the same CPU, they'll both return the same ID.
"Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997 ----- "...the staggering layers of obscenity in your statement make it a work of art on so many levels." - Jason Jystad, 10/26/2001
|
|
|
|
|
Hi.
I'm building an application which has to return a value from a database, conditioning on two things.
The database looks like:
|Workplace|
------------------------
ID | Description | Morning | Afternoon | Evening
Description: Description of the workplace
Morning: The hourly wage on this workplace
Afternoon: The hourly wage on this workplace
Evening: The hourly wage on this workplace
Example of a database:
1 | Warehouse | 1,3 | 3 | 3,7
2 | IT | 2,5 | 4 | 5
3 | Maintance | 2 | 2,5 | 7
Ok, we've cleared about the database... now lets got to the program.
In the app. the user must choose When did he work and when. That means, he chooses the ID of the workplace and when did he work.
The app. must then return the value of selected workplace and the wage on the selected time he worked. Thats the problem.
A friend of mine said, that in VB 6 and ADO (not .NET), it was quite simple. You could use the select string and then something with recordset.recordcount and then if recordset field value = ...
I googled and googled and in the end i didnt know what i was googleing The result - found nothing.
Again, im turning too the CodeProject community for help...
Thanks for taking your time to read and i hope you can help
Regards,
Matjaž
Força Barça!
|
|
|
|
|
Its a simple select statement returning (I assume) 1 row with all the columns, from which you select the rate dependant on the time selected by the user. All you need to do is google for "datareader", there are literally thousands of examples. The better alternative is to google for ado.net as again, there are thousands of articles and you will gain a better understanding of datareaders, datasets etc.
BTW,
max00slo wrote: then something with recordset.recordcount and then if recordset field value = ...
sounds like a long way round!
Hope this helps
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Thanks for your answer... eventhough i didnt need datareader with this
The solution to my problem looks like this:
<br />
OleDbConnection dbConn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "C:\\db.mdb");<br />
<br />
string sqlComm = "SELECT * FROM Workplace WHERE ID=2";
OleDbDataAdapter da = new OleDbDataAdapter(sqlComm,dbConn);
DataSet ds = new DataSet();<br />
da.Fill(ds);
<br />
string selected = ds.Tables[0].Rows[0]["DelovnoMesto_PopTarifa"].ToString();
Thanks again
Regards,
Matjaž
|
|
|
|
|
Thats one way, but for performance a datareader is better than filling a dataset - particularly when you are only expecting 1 record.
Also, stored procedures or parameterised queries are preferable (for security and performace reasons - google for sql injection) and it is also bad practice to do select * as you are generally returning more data than you actually require - not significant in this case, but if it was a table with many columns and millions of rows... However, I expect you were just showing sample code and you are aware of this.
Anyway, at least you have got there
Bob
Ashfield Consultants Ltd
|
|
|
|
|
Hi EveryOne, I have to format string being entered in the TextBox Control, i.e, in the (Lat/Long)format 00 00.000, dynamically as the text is being entered into the textBox,
Please help me out with this issue...
Thanks in Advance...
|
|
|
|