|
Virtually all the .NET framework uses get/set properties, even for lightweight structs (Point, Size, Rectangle, for example).
The only times the framework exposes fields are static readonly fields; aside from that the standard seems to be to expose fields as properties.
Judah Himango
|
|
|
|
|
Steven & Judah, thanks! I guess I'll change those fields into properties- I hate "breaking style". The class is sealed- it's basically for some help during a system data migration- but as trivial as it is, I don't want any poor coding habits popping up!
-Thomas
|
|
|
|
|
Steven Campbell wrote:
There is one (experimental) .NET language takes care of this more elegantly, called Boo. It uses attributes to let you mark a private field as having a getter and/or setter, which is then auto-generated at compile time (by the Boo compiler).
C++/CLI has something similar, called trivial properties. Basically, you say:
property int Something
and compiler creates a private variable and a property for you.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
|
|
|
|
|
Which in turn generate the appropriate get_x and set_x method calls.
- Nick Parker My Blog | My Articles
|
|
|
|
|
I want to be able to change the error icon shown in the datagrid cells on a per cell basis when i use the SetColumnError method.
For example, my application has errors and warnings. Errors prevent a user from saving any changes and warnings are only a visual indicator that the user needs to read.
I want to display the normal red error icon for errors, but want to display a different icon (a yellow error icon) on a warning.
How can I change this icon?
|
|
|
|
|
Hi.
I want to be able to configure and monitor what a service is doing on the fly, by means of a gui. I want the service to run as a normal service, but to allow an optional user interface.
Like the sygate firewall, for example.
How can I do this? should I use two different .exe? add a form into the service that is called when a user logs in?
Thanks
|
|
|
|
|
Services should not contain GUI components. You should write a separate application for configuring the service, this application may have to communicate directly with your service or may just alter some centrally accessible configuration options somewhere (like a datbase or file).
"If a man empties his purse into his head, no man can take it away from him, for an investment in knowledge pays the best interest." -- Joseph E. O'Donnell
Can't manage to P/Invoke that Win32 API in .NET? Why not do interop the wiki way!
|
|
|
|
|
Help! I've created several custom controls, but I notice that when I layout several on a screen and hit F5 to enter the debugger, sometimes the last control created will leap up to 0,0 on the design grid. Actually, the application that is being debugged shows everything fine, but on the IDE's design screen the control has lost all its properties and been jerked up to the top left corner. It kind of looks like the control was deleted and put back at 0,0 without my intervention.
I don't know how to debug this since it seems to happen behind-the-scene and doesn't hit any breakpoints in my app. It's all fine until I exit the debugger and run again, but if I watch the IDE I see the control jump immediately when I hit F5. If anyone has seen anything like this please give me some insight into what I'm looking for and how to track it down.
After it does it once, I can move the control back and it's repeatable, but if I add/delete controls from the screen it stops repeating.
thanks!
Deanna
|
|
|
|
|
Hi,
I ve got a string containing ", and i have to replace it by \" before to send it as argument of an external program. So i use successfully the method replace:
request.Replace("\"", "\\\"");
But when i try to do the opposite with the reply, it doesn't work at all!!
reply.Replace("\\\"", "\""); // this don't do anything
If sombody has got an idea....
thks
SkN 0o.
|
|
|
|
|
I tried this
string request = "\"Hello\" World";
Console.WriteLine(request);
request = request.Replace("\"", "\\\"");
Console.WriteLine(request);
string reply = "\\\"Hello World\\\"";
reply = reply.Replace("\\\"", "\"");
Console.WriteLine(reply);
And it worked fine. Of course, I hardcoded the strings. Are you sure the reply is coming back in the expected format?
Michael
CP Blog [^]
|
|
|
|
|
I'm sorry this question is so vague, but I'm not sure where to begin. I'm attempting to create a TrackBar from scratch. I'd like to implement rounded corners in both the borders of the TrackBar and the sliding user component of the control. Can anyone suggest where I can being researching how to create the rounded corners of the back ground ? I've started with a Panel control and created a rounded-corner rectangle bitmap as the Panel's background image. I think I'd have to use GDI to locate corners and set the color to Transparent or somthign like that, but again....I'm not sure. Any hints or idea on where I can start looking for the solution to my problem ?
|
|
|
|
|
|
OK, Great advice leppie, I've created the shape I need, but I'm having trouble figureing out how to "capture" the exterior region of the control shape (i.e. outside my rounded rectangle)
I want to set the color of these four regions (each corner) to Color.Transparent, but I don't know how to identify these regions...any ideas ?
|
|
|
|
|
I think I figured it out.
|
|
|
|
|
I have a control which inherits from textbox and when i set the
PropertyGrid.SelectedObject to my control the property grid shows all the public properties which are inherited, how can i hide these properties ?
like hiding all the behavior attributes.
(without overriding all of them and setting [Browsable(false)] to each one)
|
|
|
|
|
blankg wrote:
(without overriding all of them and setting [Browsable(false)] to each one)
I don't belive you can do this without applying the Browsable attribute.
- Nick Parker My Blog | My Articles
|
|
|
|
|
Hi I get an error when trying to serialize a derived class with XmlSerializer because it's base class implements an interface:
cannot serialize XXX because YYY is an Interface...
Any suggestions???
|
|
|
|
|
specify the implemetation type in the XmlElementAttribute, u should have an attribute for every class that will be deserialized.
top secret xacc-ide 0.0.1
|
|
|
|
|
I don't want to serialize the base class stuff,
only the current instances 'as is' -
is there a way I can let the serializer ignore the inheritance?
|
|
|
|
|
mgaerber wrote:
is there a way I can let the serializer ignore the inheritance?
You can ignore certian elements with attributes, but I suspect you havent done much reading on this, I suggest you do, unless u wanna write your own de/serializer. And no u can never instantiate an interface or an abstract class, so unless u wanna break .NET that will never succeed!
top secret xacc-ide 0.0.1
|
|
|
|
|
Alright,
the problem was in a class from which I inherited,
[XmlIgnore] did the trick...
Thanks for your hints!
|
|
|
|
|
And here I´m again...
I have problems to get a specified Array Length from an assembly file.
First here is a extract from the assembly file (source):
public class SEGMENT_FLATNESS
{
public int ID { get{ return 221; } }
// date as 8-digit integer in format yyyymmdd
public int DATE;
// time as 6-digit integer in format hhmmss
public int TIME;
// test
public float[] FLATNESS;
public SEGMENT_FLATNESS ()
{
FLATNESS = new float[35];
}
}
To get the array length I tried following:
first I have ceated an instance from the upper class, then I got the related Field and tried to get the Property 'Length' from it.
The second way was to invoke the Method GetLength from the array, but both didn´t work.
Here my last try:
using System;
using System.Reflection;
namespace DummyTest
{
///
/// Summary description for Class1.
///
class Class1
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
Assembly testAss = System.Reflection.Assembly.LoadFrom("KorrektesFile");
Type testType = testAss.GetType("SEGMENT_FLATNESS");
object testInvoke = Activator.CreateInstance(testType);
FieldInfo testInfo = testType.GetField("FLATNESS");
Type fieldType = testInfo.FieldType; // weiß nicht ob das nötig ist
PropertyInfo p = fieldType.GetProperty("Length");
MethodInfo[] testMethodInfo = p.GetAccessors(false); //liefert nur die public get Methode für die Länge!!!
testMethodInfo[0].Invoke(testInvoke, null); // **************
string tmpString = testInfo.Name; //dummyZeile wg. debug (kein vorzeitiges Ende)
}
}
}
What did I wrong? And how can I get the array length?
Please help me...
Norman-Timo
|
|
|
|
|
Norman-Timo wrote:
testMethodInfo[0].Invoke(testInvoke, null);
if u want a value, u should assign it!
top secret xacc-ide 0.0.1
|
|
|
|
|
Norman-Timo wrote:
FieldInfo testInfo = testType.GetField("FLATNESS");
Type fieldType = testInfo.FieldType; // weiß nicht ob das nötig ist
PropertyInfo p = fieldType.GetProperty("Length");
MethodInfo[] testMethodInfo = p.GetAccessors(false); //liefert nur die public get Methode für die Länge!!!
testMethodInfo[0].Invoke(testInvoke, null); // **************
try this rather:
FieldInfo testInfo = testType.GetField("FLATNESS");
Type fieldType = testInfo.FieldType;
PropertyInfo p = fieldType.GetProperty("Length");
int length = (int)p.Invoke(testInvoke, new object[0]);
top secret xacc-ide 0.0.1
|
|
|
|
|
Thanx for the very fast help, but there are compiler errors in your hint.
p.Invoke... (-> 'System.Reflection.PropertyInfo' does not contain a definition for 'Invoke')
Are there framework differences? I use framework 1.1!
But I tried somithing similar and I only got Exceptions like that:
"An unhandled exception of type 'System.Reflection.TargetException' occurred in mscorlib.dll
Additional information: Object does not match target type.
"
the Exception is trown with following lines:
FieldInfo testInfo = testType.GetField("FLATNESS");
Type fieldType = testInfo.FieldType;
PropertyInfo p = fieldType.GetProperty("Length");
int iii = (int) p.GetValue(testInvoke, null); // -> ********** Exception!
Please help me (I can´t [under]stand this thing!)
Norman-Timo
|
|
|
|