Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Desktop Developer

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.

Your profile

    Search

    XML Feeds

    Google Ads

    « What so special about Optional/named parametersAn arrowhead anti-pattern »
    comments

    Today I needed to create a sequential GUid in .Net to test if my Compareto function worked as expected.

    The problem is that Guid.NewGuid produces a random Guid duh. which isn't sequential. Of course in my unittests I want to know what value I'm giving to the guid.

    .Net doesn't have a SequentialGuid function as far as I know So went for a little Google. And I found this site.

    Generate Sequential GUIDs for SQL Server 2005 in C#

    Which has an interesting concept. But I needed no such difficult things for my unittests.

    The following would prove my point just as well.

    1. ObjectThatHasGuid1 = New ObjectThatHasGuid()
    2. ObjectThatHasGuid1.GetType.GetField("_id",Reflection.BindingFlags.NonPublic or Reflection.BindingFlags.Instance).SetValue(ObjectThatHasGuid1,new Guid("00000000-0000-0000-0000-000000000001"))
    3. ObjectThatHasGuid2 = New ObjectThatHasGuid()
    4. ObjectThatHasGuid2.GetType.GetField("_id",Reflection.BindingFlags.NonPublic or Reflection.BindingFlags.Instance).SetValue(ObjectThatHasGuid2,new Guid("00000000-0000-0000-0000-000000000002"))

    Life can be so easy sometimes if you know how. I totaly forgot that GUID was an object and that you can instantiate it.

    About the Author

    User bio imageChris is awesome.
    Social SitingsTwitterHomePageLTD RSS Feed
    InstapaperVote on HN

    1 comment

    Comment from: SQLDenis [Member] Email
    SQLDenis SQL Server 2005 and up has the NEWSEQUENTIALID()

    NEWSEQUENTIALID() creates a GUID that is greater than any GUID previously generated by this function on a specified computer.
    06/10/09 @ 06:52

    Leave a comment


    Your email address will not be revealed on this site.

    To mislead the spambots.

    Your URL will be displayed.
    (Line breaks become <br />)
    (Name, email & website)
    (Allow users to contact you through a message form (your email will not be revealed.)