473,221 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,221 software developers and data experts.

What is good syntax for instanating virtual types?

Is this 'good' code to debug?

//Create separate Type library
namespace Common
{
public sealed class Statuses
{
internal Statuses(){}
public sealed class Good
{
public const string Ok = "Ok";
}
public sealed class Bad
{
public const string NotOk = "NotOk";
}
}
}
// end

// Create simple console app to use library
using Common;
namespace ConsoleApplication1
{
class Class1
{
[STAThread]
static void Main(string[] args)
{
string tmp = "Ok";
bool isOk = String.Compare(tmp, Statuses.Good.Ok) == 0;
Console.WriteLine(isOk.ToString());
}
}
}
Jun 27 '08 #1
4 1191
On Thu, 29 May 2008 16:25:00 -0700, jsh02_nova
<js*******@discussions.microsoft.comwrote:
Is this 'good' code to debug?
I don't even understand the question. Looking just at your subject, the
answer is "there's no such thing as a 'virtual type'". Looking at the
code, I'd have to say "no, that's not good code". For one, I don't see
the point of the nested classes "Ok" and "NotOk". They seem like a
pointless redundancy to me.

If you can be more clear about your question -- what is it that you think
a "virtual type" is, and what specific goal do you have in mind that
you're trying to address -- maybe a better answer would be forthcoming. :)

Pete
Jun 27 '08 #2
I do not know what you are targetting!!

However what ever the code you wrote is not good!! Try refactoring it
to an enum

namespace ConsoleApplication1
{
public enum Statuses
{
Ok, NotOk
}

class Class1
{
[STAThread]
static void Main(string[] args)
{
string tmp = "Ok";
bool isOk = String.Compare(tmp, Statuses.Ok.ToString())
== 0;
Console.WriteLine(isOk.ToString());
}
}
-Cnu

On May 30, 4:25*am, jsh02_nova <jsh02n...@discussions.microsoft.com>
wrote:
Is this 'good' code to debug?

//Create separate Type library
namespace Common
{
* * public sealed class Statuses
* * {
* * * * *internal Statuses(){}
* * * * *public sealed class Good
* * * * *{
* * * * * * * public const string Ok = "Ok";
* * * * *}
* * * * *public sealed class Bad
* * * * *{
* * * * * * * public const string NotOk = "NotOk";
* * * * *}
* * }}

// end

// Create simple console app to use library
using Common;
namespace ConsoleApplication1
{
* * *class Class1
* * *{
* * * * * [STAThread]
* * * * * static void Main(string[] args)
* * * * * {
* * * * * * * string tmp = "Ok";
* * * * * * * bool isOk = String.Compare(tmp, Statuses.Good.Ok) == 0;
* * * * * * * Console.WriteLine(isOk.ToString());
* * * * * }
* * *}

}- Hide quoted text -

- Show quoted text -
Jun 27 '08 #3
The exercise was try to refactor multiple 'hard coded' string comparisons
into nested abstract types with public readonly string fields, using .Net
v1.1. These 'abstract' types would be used throughout the solution. It was
discovered that the VS 2003 IDE couldn’t 'debug' these nested types, but it
could be seen that their instances were being created by the CLR. So, the
String.Compare method was working but the VS 2003 IDE wouldn’t hold these
nested ‘sealed’ types in scope so that the types could be 'watched' in the
debugger.
Jun 27 '08 #4
On Fri, 30 May 2008 15:58:00 -0700, jsh02_nova
<js*******@discussions.microsoft.comwrote:
The exercise was try to refactor multiple 'hard coded' string comparisons
into nested abstract types with public readonly string fields, using .Net
v1.1.
Why? Why is that the goal? The code you posted seems to achieve that,
but why do you want code that looks like that?
These 'abstract' types would be used throughout the solution.
There's nothing abstract about those types. In fact, by virtue of being
"sealed", it's the exact opposite.
It was
discovered that the VS 2003 IDE couldn’t 'debug' these nested types, but
it
could be seen that their instances were being created by the CLR. So, the
String.Compare method was working but the VS 2003 IDE wouldn’t hold these
nested ‘sealed’ types in scope so that the types could be 'watched' in
the
debugger.
Why would you want to "watch" a constant? Did you think it was going to
change? How does putting constants in a nested class address the issue?

I'm not even sure I've used the 2003 version of VS...I might have jumped
straight from VC6 to 2005. I'm not sure what limitations might exist in
the debugger that would present a problem here. But it seems to me that
if you're having trouble with the tools, the most appropriate solution is
to upgrade the tools, rather than try to rearrange your code in a
contrived way.

Pete
Jun 27 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

28
by: joe | last post by:
I have a simple .NET application with two or three listViews which are filled with icons and when the user click on the proper item, they display the related images. I use "image = null ; " for all...
12
by: Steve W. | last post by:
I just read the section (and did the exercise) in the C# Step by Step book that covers Explict Interface Implementation (where you specify in the method implementation the specific interface that...
4
by: Oleg Subachev | last post by:
What good obfuscators/protectors for .NET are on the market now ? -- Best regards, Oleg Subachev subachev@ural.ru
0
by: COHENMARVIN | last post by:
I have a web site where I put my asp.net application in a folder called /asp.net/hotelallocation. I want it to be protected by a password, so I put a web.config file in that folder. But now when...
12
by: Joe Fallon | last post by:
I would like to know the syntax to check that an Object is a String. If it was a number test I might use IsNumeric. But there is no function: IsString (is there?) -- Joe Fallon
0
by: Just Me | last post by:
Consider the following where I generate 2 identical ListViewItems, add one to the ListView and then check to see if the other one is Contained? I get the MM message but not the WW message. So...
4
by: moleskyca1 | last post by:
What operators cannot be virtual and why? I looked at FAQ and found nothing. I think there are operators that cannot be virtual, but I don't know why?
6
by: mcasaurabhsumit | last post by:
Hello Friend, can u send me about cursor? i find it most difficult. What is cursor? How many Types of cursor? how to create each one? what r the benefit of each cursor?
1
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
0
by: veera ravala | last post by:
ServiceNow is a powerful cloud-based platform that offers a wide range of services to help organizations manage their workflows, operations, and IT services more efficiently. At its core, ServiceNow...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: mar23 | last post by:
Here's the situation. I have a form called frmDiceInventory with subform called subfrmDice. The subform's control source is linked to a query called qryDiceInventory. I've been trying to pick up the...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: fareedcanada | last post by:
Hello I am trying to split number on their count. suppose i have 121314151617 (12cnt) then number should be split like 12,13,14,15,16,17 and if 11314151617 (11cnt) then should be split like...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
1
by: davi5007 | last post by:
Hi, Basically, I am trying to automate a field named TraceabilityNo into a web page from an access form. I've got the serial held in the variable strSearchString. How can I get this into the...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.