473,671 Members | 2,363 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2773
Guy <Gu*@discussion s.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.WriteLi ne (id.Guid);
id = ID.CreateID();
Console.WriteLi ne (id.Guid);
}
}

--
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
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*@discussion s.microsoft.com > wrote in message
news:E8******** *************** ***********@mic rosoft.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
2726
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 else is so well done that the way you create forms seems to be too cumbersome, in particular making it so that a pull down menu selects a value that you assign it. In any case, does anyone know of any php based (or other readily accepted web...
1
2909
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 2000. The access file is in access 2000 format. I have a form that will hold the relevent parameters for the query/report that reports the statistics for all job records that match a certain criteria. These are: - A Customer Name.
7
1719
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 something similar in code would be great. I've looked at the System.Guid class but can't figure how to have it generate a fresh GUID.
12
3153
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 restarting the application. What I did was to create an AppDomain that loaded the plugins and everything was great, until I tried to pass something else that strings between the domains...
3
2570
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 hope you can help. (I have posted to alt.comp.mail.qmail, but that doesn't have much participation). Goal: I want the create an account in qmail (which is written in php). What I want to do is gather all the information from the user from a...
2
3255
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 CreateGUID() As String Dim objGUID As Object objGUID = New Guid
4
4255
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 __declspec(uuid("37944845-f74f-3999-b972-d42355a78bcd")) _AlarmSetting : IDispatch {};
1
8282
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. This part is done but next requirement is that after closing ActiveX I have to redirect parent page to location X or Y depending on how the
4
5892
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: copy the GUID to a new rows field 1 parse out the first value of the csv field and copy to a new rows field 2 Continue to write new rows with the GUID and the next value in the csv field until all values have been written to new rows in a new...
0
8471
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8388
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,...
0
8907
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8663
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6218
isladogs
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...
0
5687
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();...
0
4215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
2
2046
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1799
bsmnconsultancy
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...

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.