|
Hi
I have a big solution which contains many projects.
I created a class
public class MySettingClass:ApplicationSettingsBase
which contains a few settings.
I would like to have an access to these variables from almost all projects.
How to do that in the most efficient way?
When I want to use any setting variable I create an object
public MySettingClass mySettings = new MySettingClass();
how to make it visible in all projects in solution? I do not want to pass any parameters (there would be too many changes).
Do I have to create an object in each project? No sense.
Thanks for help
Ela
|
|
|
|
|
You could create a specific project for dealing with settings and then reference it from all the projects that need it. You can then access the classes from anywhere in your solution (just remember to include the namespace).
|
|
|
|
|
I thought so...
Thanks for confirmation.
I wondered if there is another way but I suppose not.
Ela
|
|
|
|
|
e_LA wrote: Thanks for confirmation.
I wondered if there is another way but I suppose not.
I just confirmed what I tend to do, and that has fit every situation that I've needed so far. There may be other ways - What kind of thing were you looking for?
|
|
|
|
|
If I knew I wouldn't ask.
I thought there is an easier way to do with global settings in Framework 2.0.
Ela
|
|
|
|
|
I understand I have to create an object of settings class in each project?
Ela
|
|
|
|
|
You can create one object only. (The class exists in a single project and it can use the singleton pattern so that only one instance of the object exists across the whole application)
|
|
|
|
|
I think do not undrestand everything. I have many projects in solution and in almost all of them I need see global varialbes.
Do I have to add a references to my "global" class with settings and create an object.
There is something wrong.
Ela
|
|
|
|
|
e_LA wrote: Do I have to add a references to my "global" class with settings and create an object.
Every time you use your settings class you will need to include the namespace and reference the project that the in which the settings class resides. i.e. In the project that you wish to use the settings class you "Add Reference..." to the project that contains the settings class.
|
|
|
|
|
Colin,
Could you provide me with any example for such a specific project?
I have one class e.g.
public class MyAppSettings : ApplicationSettingsBase
{
[UserScopedSetting()]
[DefaultSettingValueAttribute("true")]
[global::System.Configuration.ApplicationScopedSettingAttribute()]
public bool someProperty
{
get { return (bool)this["someProperty"]; }
set { this["someProperty"] = value; }
}
Then I have to create a project dealing with the setting. I suppose it should contain class with static properties??
Could you give me an example?
Thanks
Ela
|
|
|
|
|
e_LA wrote: Then I have to create a project dealing with the setting. I suppose it should contain class with static properties??
You can use a static class. Although I prefer to use the Singleton pattern because I can mock the class for unit testing.
public static MySettingsClass
{
public bool static SomeProperty
{
get
{
return this.someProperty
}
}
} My settings classes never have setters. They are readonly.
|
|
|
|
|
...but where to create the object of settings class?
|
|
|
|
|
e_LA wrote: but where to create the object of settings class?
If you are using the singleton pattern then the class itself creates the object.
For example:
public Settings
{
private static Settings onlyInstance;
private Settings(){};
public static Instance
{
get
{
return this.onlyInstance;
}
}
}
|
|
|
|
|
Colin,
When I was waiting for the answer I managed to do that in such a way you explained and it works! I can make a few changes after reading you responses.
Many thanks for the explanation!
...very strange this singleton pattern
I had problems with saving settings but I created public method in singleton and called settings save method.
Redards
Ela
|
|
|
|
|
Hi all.
How I can get control's id "(Name)" property of a control of other process (vb6 app) via windows api?
Please, help me.
Thx in advance.
Best Regards,
Marco Alves.
|
|
|
|
|
hi all,
i have a simple windows application with 2 forms.
i show the 2nd form with showdialog option.
but when i click on the main form, the second form flicks both in task bar and its head part.
the thing i want to learn is: is it possible to completely restrict clicking on the form behind when i open a new form with showdialog option ?
(do not want the main form to react with mouse clicks. no flicks on the front form)
thanks in advance, bye.
MFA
|
|
|
|
|
Hello,
No, with ShowDialog you have too .Exit the Form.
I don't think that there is a solution for the flickering.
All the best,
Martin
-- modified at 9:16 Monday 4th September, 2006
What you can try is, not showing the 2nd Form (ShowDialog Form) in Taskbar.
All the best,
Martin
|
|
|
|
|
I'm relatively new to C#, and just started with interop. I've a C DLL with this function:
int SomeFunction (
const int id,
const char * name,
int num = 0,
CLASS1 *const ptr1 = NULL,
CLASS2 *const ptr2 = NULL
)
I wrote a C# file for this C library and defined this function as:
[DllImport(DLLNAME)]
public static extern int SomeFunction(
int id,
string name,
SIPX_CONTACT_ID num,
IntPtr ptr1,
IntPtr ptr2
);
Now I've got only the values of only first three parameters. So, I want to pass the last two parameters as null . But I got "Cannot convert null to System.IntPtr because it is a value type" error.
To solve this problem I rewrote C# file as:
[DllImport(DLLNAME)]
public static extern int SomeFunction(
int id,
string name,
SIPX_CONTACT_ID num,
ref CLASS1 ptr1,
ref CLASS2 ptr2
);
Is this correct? It's not giving me the desired results. SomeFunction is returning me
wrong values.
I also tried an alternative approach. In the C# file, I declared an overloaded
function as:
[DllImport(DLLNAME)]
public static extern int SomeFunction(
int id,
string name
);
Then I called the function with only first two arguments. But that gives me an System.AccessViolationException : "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
What's wrong with this code?
Ut
|
|
|
|
|
Okay,
you could try to pass "0" instead of "null", since "null" is a built-in "feature" (dont know if its a datatype or "just" a value).
Since cpp null is nothing else than the value 0, you could try to pass this value instead.
*edit* please let me know if it works - i'm not that expirienced in programming cpp nor in programming c# ;D
|
|
|
|
|
It does work! Thanks a lot! You don't know how much time I wasted on this! Thanks a lot, again!
Utkarshraj Atmaram
|
|
|
|
|
I found out another way to do this using Type.Missing . We can write: string foo = (string)Type.Missing etc. and then pass foo as parameter.
Utkarshraj Atmaram
|
|
|
|
|
I want Save The Picture I drew in PictureBox,usually I can use PictureBox.Image
property to save, But the picture is I drew, the Image proper is null, What can i do in this case.
|
|
|
|
|
You must draw it into Image object, and then set this object into Image property, or draw them into picturebox on Paint event.
Geniality is in simplicity.
|
|
|
|
|
how will you differentiate interface and abstract class.
|
|
|
|
|
An interface can't contain any behaviour (it doesn't have any method bodies).
An abstract class can have some behaviour allready defined and can allready store properties into fields, etc..
Choosing wich one to use realy depend on your situation.
|
|
|
|