Greetings,
I am working on a project and cannot choose the best way to achieve this :
I got a method which returns an error code like this : DISK_FULL or
PERMISSION_DENI ED.
Those are constants defined in a class named "Constants" :
public static byte DISK_FULL = 1;
public static byte PERMISSION_DENI ED = 2;
Now I have a resource file with keys like this :
DISK_FULL Sorry, your disk is full, should make some room.
PERMISSION_DENI ED Sorry, bla bla.
But since they are constants, the keys are not retrieved (I try to
retrieve "1" for instance), of course.
I thought to design my resource file like this :
1 Sorry, your disk is full, should make some room.
2 bla bla
My dilema is that my file is not very human-readable that way :(
I then thought but I could make things like this :
public static string DISK_FULL = "DISK_FULL" ;
public static string PERMISSION_DENI ED = "PERMISSION_DEN IED";
And a resource file with keys like this :
DISK_FULL Sorry, your disk is full, should make some room.
PERMISSION_DENI ED Sorry, bla bla.
But I find it useless to use strings here : bytes are shorter so faster
managed (yes this does not change everything, I know ;) )
My question : what do you do ??
phew, he finally asked the question ;)
I come from the java world so maybe I am missing here :)
Thank you for your patience 4 2563
gabriel <sp**@yahoo.f r> wrote: I am working on a project and cannot choose the best way to achieve this :
I got a method which returns an error code like this : DISK_FULL or PERMISSION_DENI ED.
Those are constants defined in a class named "Constants" :
public static byte DISK_FULL = 1; public static byte PERMISSION_DENI ED = 2;
Firstly, the .NET naming conventions would suggest DiskFull and
PermissionDenie d. I've converted to using these conventions in my Java
code too, and they do make things much more readable.
Now I have a resource file with keys like this :
DISK_FULL Sorry, your disk is full, should make some room. PERMISSION_DENI ED Sorry, bla bla.
But since they are constants, the keys are not retrieved (I try to retrieve "1" for instance), of course.
I thought to design my resource file like this :
1 Sorry, your disk is full, should make some room. 2 bla bla
My dilema is that my file is not very human-readable that way :(
The easy way of dealing with this is to use an enum. You can easily get
the name of an enum element, you get the speed of ints (or whatever -
although frankly as you'd only be passing a reference round, I think
your performance concern is misplaced), and you keep the human
readability of the file.
--
Jon Skeet - <sk***@pobox.co m> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
If you can move to Visual Studio 2005, then you will find that the IDE
provides strong support for resources such as these.
It provides a graphical table where you enter your constant/string pairs...
DiskFull Your disk is full
PermissionsErro r There was a permissions error
It generates a class from this which provides a static "get" property for
each resource. The class is in the Properties namespace.
An example of using it...
MessageBox.Show (Properties.Res ources.DiskFull );
.....displays the string "Your disk is full"
VS 2003 provides similar features, but they are somewhat hidden behind
localization. I haven't used them myself, but I think that with a little bit
of investigation will find what you need. Start in the Solution Explorer,
right-click the project, and select "Add Component" then "Add Assembly
Resource File", and take it from there.
You can also use a HashTable
enum ErrorCodes
{
DiskFull,
PermissionsErro r
}
Hashtable errorTable = new Hashtable();
// Initialize the hash table
errorTable.Add( ErrorCodes.Disk Full, "Your disk is full");
errorTable.Add( ErrorCodes.Perm issionsError, "Permission s error");
// Use an item from the hash table
MessageBox.Show (errorTable[DiskFull].ToString());
Regards,
Javaman
Hi,
As Jon mentioned, I use enums.
You might want to check out a simple method I use for this purpose: http://rakeshrajan.com/blog/archive/2005/10/11/43.aspx
--
HTH,
Rakesh Rajan
MVP, MCSD http://www.rakeshrajan.com/
"gabriel" wrote: Greetings,
I am working on a project and cannot choose the best way to achieve this :
I got a method which returns an error code like this : DISK_FULL or PERMISSION_DENI ED.
Those are constants defined in a class named "Constants" :
public static byte DISK_FULL = 1; public static byte PERMISSION_DENI ED = 2;
Now I have a resource file with keys like this :
DISK_FULL Sorry, your disk is full, should make some room. PERMISSION_DENI ED Sorry, bla bla.
But since they are constants, the keys are not retrieved (I try to retrieve "1" for instance), of course.
I thought to design my resource file like this :
1 Sorry, your disk is full, should make some room. 2 bla bla
My dilema is that my file is not very human-readable that way :(
I then thought but I could make things like this :
public static string DISK_FULL = "DISK_FULL" ; public static string PERMISSION_DENI ED = "PERMISSION_DEN IED";
And a resource file with keys like this :
DISK_FULL Sorry, your disk is full, should make some room. PERMISSION_DENI ED Sorry, bla bla.
But I find it useless to use strings here : bytes are shorter so faster managed (yes this does not change everything, I know ;) )
My question : what do you do ??
phew, he finally asked the question ;)
I come from the java world so maybe I am missing here :)
Thank you for your patience
> The easy way of dealing with this is to use an enum. You can easily get the name of an enum element, you get the speed of ints (or whatever - although frankly as you'd only be passing a reference round, I think your performance concern is misplaced), and you keep the human readability of the file.
Thank you, I'll dig that !
humbly yours :) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: אלחנן |
last post by:
hi..
i don't know if this is the right group for this..
i have a small application which involves a windows service, and web
services which bascally retrieves files, process them and zips them away
(it's a little more complext then that..) i would like to consult ppl about
creating the right classes for it..
|
by: MLH |
last post by:
I make API calls to the sndPlaySound function,
something like this...
XX% = sndPlaySound(msound, MyParm)
Several predefined system constants (or API
intrinsic constants) have been recommended
for use as the 2nd parm...
SND_ASYNC
|
by: Saso Zagoranski |
last post by:
hi,
this is not actually a C# problem but since this is the only newsgroup I
follow I decided
to post my question here (please tell me where to post this next time if you
think this post shouldn't be here).
I have two design questions:
1. what is the correct (or best) way to include database queries into the
code if you plan on
|
by: Kevin |
last post by:
Has anyone ever encountered this problem? (I searched on google for
past posts but didn't find anything)
I have a class implementing the IHttpModule Interface. It's mainly
used for seting up layout information & provide some security/logging
functions. Typically it inspects a HttpRequest, set some variables
into session, and returns.
for exactness, the HttpModule is hooked up to these events
|
by: Alf P. Steinbach |
last post by:
<what to design a C++ solution for>
A Windows API /resource/ is data embedded in the executable, accessed
via API functions. A resource is completely identified by the quadruple
(id, type, language, file), where (1) id is what, for want of a better
name, I'll call a /kludgeon/, (2) type is also a kludgeon, (3) language
is a small integer identifying a concrete national language or one of a
set of pseudo-languages such as the Windows...
| |
by: Jason |
last post by:
Greetings ,
I'm studying for a MS exam and I'm a little confused about assemblies. Not
what they are but just a specific comment that I'm reading and it doesn't
make sense to me. It reads
"Assembly resource files are preferred for use with localized data that is
not tied directly to the user interface such as message box text"
My question is why wouldn't satellite assemblies be the preferred method
|
by: www.gerardvignes.com |
last post by:
I do most JavaScript programming with objects and methods. I use tiny
boot and shutdown scripts as hooks for the browser load and unload
events.
My JavaScripts interact with scripts running on the web server. I need
to declare shared values (as constants) to assist communication between
client and server. I declare these constants using global variables:
var CONSTANT_NAME = 'whatever';
|
by: Stephen Torri |
last post by:
I am trying to produce a singleton class that I can use throughout my
library to write tracing information to a file. My intent was to design
such that someone using the library in its debug mode would be able to
see what was happening without having to use a debugger to step through
each instruction. What they would do is run their program and view the
tracing file output. If there was something wrong then they would use the
debugger of...
|
by: matt |
last post by:
Hello group,
I'm trying to become familiar with the information hiding design rules, and I
have a lot (3) of questions for all you experts. AFAIK, a generic module has 2
files:
================
module.h
================
#ifndef __MODULE_HDR_INCLUDED__
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |