473,395 Members | 1,379 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,395 software developers and data experts.

Creating a new Value Type for hiding creation of Guid's

Guy
I want to create a new value type for hiding the creation of Guid's that can
be used in my business classes. I suppose I have to achieve this by creating
a struct (ID)
The problem is I'm completely stuck as how to develop my struct. Anyone can
help?
Thanks.

e.g.

class Person
{
ID PersonID; // ID is the struct
string FirstName;
string LastName;
Person()
{
this.ID = ID.new(); // Calling the static method of the struct ID, with
the purpose of getting a Guid
...
}
...
}

struct ID
{
...
public static ??? new()
{
???
}
}
Dec 23 '05 #1
2 2765
Guy <Gu*@discussions.microsoft.com> wrote:
I want to create a new value type for hiding the creation of Guid's that can
be used in my business classes. I suppose I have to achieve this by creating
a struct (ID)
The problem is I'm completely stuck as how to develop my struct. Anyone can
help?


Well, you can't create a method called "new" in C# (you could use @new,
but it's really not a good idea).

Instead, you should create a factory method which calls a constructor
and does whatever is required. For instance:

using System;

struct ID
{
Guid guid;

public Guid Guid
{
get { return guid; }
}

public static ID CreateID()
{
ID id = new ID();
id.guid = Guid.NewGuid();
return id;
}
}

public class Test
{
static void Main()
{
ID id = ID.CreateID();
Console.WriteLine (id.Guid);
id = ID.CreateID();
Console.WriteLine (id.Guid);
}
}

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Dec 23 '05 #2
Hi,

Why not using directly a Guid?
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Guy" <Gu*@discussions.microsoft.com> wrote in message
news:E8**********************************@microsof t.com...
I want to create a new value type for hiding the creation of Guid's that
can
be used in my business classes. I suppose I have to achieve this by
creating
a struct (ID)
The problem is I'm completely stuck as how to develop my struct. Anyone
can
help?
Thanks.

e.g.

class Person
{
ID PersonID; // ID is the struct
string FirstName;
string LastName;
Person()
{
this.ID = ID.new(); // Calling the static method of the struct ID, with
the purpose of getting a Guid
...
}
...
}

struct ID
{
...
public static ??? new()
{
???
}
}

Dec 27 '05 #3

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

Similar topics

6
by: gonzalo briceno | last post by:
I have been using phplib for a while and I really like the framework except for form creation. Maybe it is me but I in my opinion there isn't a good way to create forms or should I say, everything...
1
by: longtim | last post by:
I have been having endless difficulty creating reports/queries that set any relevent parameters from controls in forms. I am creating an application under access 2003 but will target access...
7
by: Steve | last post by:
I need to generate a unique number/string of some description and thought a guid would be ideal. Any ideas on how to generate a guid? I'm not using SQL server so SELECT NEWID() is out but...
12
by: Mats Lycken | last post by:
Hi, I'm creating a CMS that I would like to be plug-in based with different plugins handling different kinds of content. What I really want is to be able to load/unload plugins on the fly without...
3
by: sheldonlg | last post by:
I don't think my last attempt posted so here it is again. This is a bit off-topic, but it does relate to php. This is the most active related group that I can find, so even if it is off-topic I...
2
by: doug | last post by:
G'day all, I'm a newbie to .net (7 years or so as a vb/asp programmer) and I'm trying to create a GUID using the GUID type in vb.net Here's the code I'm using to create it : Public Function...
4
by: tom | last post by:
I called regasm.exe /tlb CameraManagement.dll and I got CameraManagement.tlb When I look inside with OleView.exe or create C++ header I see something like that: struct...
1
by: kret | last post by:
Hi, this is my first post so first of all I would like to say hello :) Now getting to my problem. In my job I have to create an ActiveX control in .NET 1.1 that can be lunched from IE....
4
by: kageyone | last post by:
I have an access database with a table with two fields. They are 1. a GUID field and 2. a comma delimited set of values. I want to take this table and for each row I want to do the following: ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.