|
|
I have a class with 10 properties. Within one of the class methods, I'd like to iterate through the 10 properties rather than referencing each one manually. So instead of this:
this.property1=
this.property2=
this.property3=
I'd like to do something like this:
foreach( property p in this.properties )
{
p.value =
...
}
Is there a way to do this?
Using reflection, I can get the properties and iterate through them, but it's a blank object. I want to be able to do that with an existing object where the properties contain valid data values.
Thanks in advance.
|
|
|
|
|
what do you mean its a blank object
get the Type()
then get the propertyInfo for each one
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
One idea - since you are accessing from inside the class, have the property values in an ArrayList:
private enum MyProperties {Prop1, Prop2, Prop3, ...};
private ArrayList m_PropVals = new ArrayList ();
public object property1
{
get
{ return m_PropVals[MyProperties.Prop1]; }
}
...
private void foo()
{
foreach (object p in m_PropVals)
{
p = bar;
}
}
Otherwise, its System.Reflection for you:
private void foo()
{
foreach (PropertyInfo propInfo in this.GetType ().GetProperties ())
{
propInfo.SetValue (this, bar, null);
}
}
α.γεεκ Fortune passes everywhere. Duke Leto Atreides
|
|
|
|
|
The second way was what I was looking for. Thanks!
The first way is also an interesting idea, but won't work for what I'm trying to do.
|
|
|
|
|
Hi there, I think the subject simply describes the point of my problem (I want to get the decimal ASCII codes of these characters like "k" or "S" and so on...) Thanx...
|
|
|
|
|
|
Thanx This is what I need...
|
|
|
|
|
How to communicate a aspx page with a thread ( one thread per session )?
I try to build a thread that be able to communicate with a aspx (C#).
Basically, this thread launches a special procedure which can take several minutes. Also, the aspx page refreshes automatically every 5s(meta http-equiv=refresh content="1,qsdf.aspx”) and it shows the status like a progress bar. Currently, I can launch and execute a separate thread in my Web Sessio n. But I could not communicate by event and collection class.
For example. In my main aspx,I create a new instance of my Collection(ArrayList) (private list { set{ Session[“List”] } get{return (LIST)Seesion[“ref”] }}). In my constructor thread, I take this List(ref) to pass like parameter. But apparently my collection has not been modified by my thread when I try to read that in my aspx page.
Could you help me?
Where can I find some documentation about that?
Thank in advance …..
Bye bye
Ps=the thread is saved in the session variable
-=zoltx=-
|
|
|
|
|
Hi All,
I m new to C#, and i want to know how could i detect the double click Event on a Row in DataGrid Control.
Any Response will be appreciated.
Thanx in advance
cheers
|
|
|
|
|
hi !
that's a realy great link for datagrid stuff:
http://www.syncfusion.com/FAQ/WinForms/FAQ_c44c.asp
andi
--
still not having a meaningful aphorism to use as a signature
|
|
|
|
|
In a winform, before saving, I call the function this.Validate() to make sure all controls contents are good (verifications are made in the Validating event of each control).
In some cases, the call to the validate() function returns false. How can I know which control causes the validation to fail ?
Thanks for help,
Nico
|
|
|
|
|
I wonder how fast is .NET and especially some of its components.
As everyone can read pinvoke is slow. Does it make sense to uses it in real applications (applications you want to sell and to be sure that there aren't any problems for you and your customers) for cases where there is no real need to to it like creating fancy custom GUI?
How fast is GDI+? Does it depend on CPU power or it just requires powerful 2D (or 3D) accelerator?
For me SharpDevelop is an example for a very slow application. I wonder if all .NET applications with complex GUI will be as slow as SharpDevelop. (I think that WebMatrix is also completely written for .NET and it is totally fast!!! Does this mean that SharpDevelop is not written well enough?)
Should one be careful when using GDI+ for creating new custom windows forms controls or for stuff like CAD drawing, bitmap and vector manipulation programs? Eventually if these programs are executed on latest CPUs and graphics accelerators they will run fast but what about old and slow systems like: P90 or even P400 with old slow TNT or worse graphic cards?
What is your oppinion? Could you, please, enlighten me? I'm talking here about commercial use and not about free time development ;_)
Thank you!
|
|
|
|
|
I certainly hope I formulated my questions clear enough for you to understand and that they make sense.
|
|
|
|
|
|
Excellent article, BTW, Nish! Didn't get a chance to say it before.
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Cristoff wrote:
I wonder how fast is .NET and especially some of its components.
Fast enough.
Hey, wait! Put down that axe and let me explain it.
Cristoff wrote:
As everyone can read pinvoke is slow.
Slower it the word, not slow. It is slower than a native call, but it's quite fast for most applications. I wouldn't make a PInvoke call on a tight loop, tought.
Cristoff wrote:
How fast is GDI+? Does it depend on CPU power or it just requires powerful 2D (or 3D) accelerator?
GDI+ is not hardware accelerated. It depends solely on the main CPU.
Cristoff wrote:
For me SharpDevelop is an example for a very slow application.
Me too. But they are focusing on several other things than performance. So, give them a break. On machines > 800Mhz, and well crafted .NET code, most of the time, users don't see a huge performance hit.
Cristoff wrote:
Should one be careful when using GDI+ for creating new custom windows forms controls or for stuff like CAD drawing, bitmap and vector manipulation programs?
For things like that hardware acceleration is a must. I would go for Managed DirectX, and would not use GDI+ as the performance hit would be too high.
Cristoff wrote:
What is your oppinion?
Performance analysis is extremely dependant of your problem domain. Some (20) years ago, people raised the same kind of question about compilers x pure asm. IMHO, the most wise answer at that time was: "if you are worrying if something will be 2x slower when compiled, then you can't afford a compiler, go and code in ASM". For the kind of work I do, the hit was neglectable, but YMMV.
Cristoff wrote:
about old and slow systems like: P90 or even P400 with old slow TNT or worse graphic cards?
You mentioned using graphics intensive applications on P90 and P400 machines. If these are custommers you can't afford to lose, and/or they can't afford a new machine, you should stick with C++.
You can do it on anything you choose - from .bat to .net - A customer
|
|
|
|
|
Thank you everyone...
To Nish: I find your articles very well written, keep on!
To Daniel:
Some (20) years ago, people raised the same kind of question about compilers x pure asm.
That's out of question. I know that .NET languages could be fast enough, even faster but some componets like GDI+, SharpDevelop and some samples make me wonder if .NET is suitable for slower computers.
One thing out Microsoft I don't like is that they seem to belive that their OSes have to comsume all computer resources, they do not leave any to the user applications.
A few years ago when I tryied QNX I was totally surprised how little RAM did it need and how fast it was, same goes for BeOS. These systems seem to have been designed to do their job without interfering with the user's job.
|
|
|
|
|
Cristoff wrote:
A few years ago when I tryied QNX I was totally surprised how little RAM did it need and how fast it was, same goes for BeOS. These systems seem to have been designed to do their job without interfering with the user's job.
I know the feeling. I have a system running RH Linux 7.1 which is an AMD K6 400Mhz with 128MB RAM. The machine is mainly a development server, and it's running:
1. CVS server
2. SSH server
3. Apache server
4. MySQL Server (for bugzilla)
5. Bugzilla
6. CVSWEB
7. SMTP server
8. Several other small typical *nix utilities and daemons, like cron, etc.
9. Several scheduled jobs for backups, automatic updates, system statistics (sar), etc.
All of this and the machine is using 75MB RAM. I could even reduce it further, probably to something on the 40~50MB range, but as I'm lazy, I didn't bother. The uptime of the machine:
[root@linux /root]# uptime
10:41am up 287 days, 21:46, 4 users, load average: 0.15, 0.03, 0.01
Notice that before of this we had a power failure and our >200 days uptime was ruined. So, the real uptime is in the 500 days range, without a single reboot.
I am yet to see a Windows machine doing this. The next Windows version, Longhorn, will need a minimum 3D-capable video card with almost double the memory I need to run this whole server.
You can do it on anything you choose - from .bat to .net - A customer
|
|
|
|
|
Hi, I have a datagrid boud to a dataset. I am saving the changes by usign the DataAdapter.update(DataSet) method. This woks fine except when the user is position on the last row of the datagrid (the addnew row) with every field DBnull. In this case I am gettin a NonNull alowed exception. I think what I have got to do is cancel the edit on the last row ,when the primary key is Null, and then position the datagrid to the last valid row. If anyone can help I´d be very thankfull.
Thanks,
Pedro
Pedro
|
|
|
|
|
I don't allow records with nulls in required (primary etc.) fields. User must fill them or delete the records.
Hi,
AW
|
|
|
|
|
Thaks, it was alot simpler than what I was trying to do.
|
|
|
|
|
Hi ...
Since I couldn't find a converter from .rc to cs forms i wanted to write one by myself.
Now the problem that arises is, that though the alignment is right (so the buttons and radio boxes are at the right places) the scale is smaller.
I try to explain:
all controls are closer to each other and smaller, so you can't read them.
It's about the factor 1.5 -> 2 .. don't know exactely.
Does any one of you know where this might come from and how i can fix it ?
Thanks
P.S.: I used the values directly from the rc file and write them directly to the cs form file.
and sorry for my bad english
|
|
|
|
|
Somnatic wrote:
I used the values directly from the rc file and write them directly to the cs form file.
I think that is part of the problem. If I remember correctly, the values in the rc file are in DLU's; not pixels like .NET uses. You'll have to find some formula to convert from DLUs to pixels given the current font size.
DLUs are used so that the dialog will scale properly if the user has large fonts but the developer doesn't or vice versa. In .NET, there is a property on the form which does the proper scaling so pixels can be specified in the control source.
James
At Jethro Tull's August 28, 2003 concert Ian Anderson mentioned that the group would be performing several songs in a row and that they were all title tracks. The songs were "Songs from the Wood", "Too Old to Rock and Roll; Too Young to Die"; and from the Heavy Horses album, "Stairway to Heaven"
|
|
|
|
|
Hi there,
I was wondering how to really unregister the Tcp Server Channel.
I create the Server channel like this:
hts = new TcpServerChannel(8000);
ChannelServices.RegisterChannel(hts);
RemotingConfiguration.RegisterWellKnownServiceType(typeof (BankDetailsClassLibrary), "RemoteClass", WellKnownObjectMode.Singleton);
then I try to disconnect the Sever channel using
ChannelServices.UnregisterChannel(hts);
But when I disconnect the server, the client still works. I can even write to the database. What could that be?
Thanks a lot
Chris
|
|
|
|