• Code
  • Tags
  • Users
  • Titles
  • Log in
  • Feedback
  • FAQ
Share Code
Welcome to ForkCan.com

ForkCan is all about sharing code in a social way.

Discuss, debate or argue with other devs about their or your own code.

Give other devs feedback or make a Fork (Make a better version of a shared code).

Rate the code, if you use the code mark it as used so others can see if the shared code is used by someone.

Help each other to be better devs and to be more productive.


Features not working yet:

Flag a post


QR Code

Tiny Url

http://4kcan.com/s/MzA4

GUID Sequential generator

Can be used when you want to generat unique ID in your domain model.

0
468 0 0 0 0 0

public Guid NewSequentialID()
{
   var destinationArray = Guid.NewGuid().ToByteArray();

   var time = new DateTime(0x76c, 1, 1);
   var now = DateTime.Now;

   var span = new TimeSpan(now.Ticks - time.Ticks);
   var timeOfDay = now.TimeOfDay;

   var bytes = BitConverter.GetBytes(span.Days);
   var array = BitConverter.GetBytes((long) (timeOfDay.TotalMilliseconds / 3.333333));

   Array.Reverse(bytes);
   Array.Reverse(array);

   Array.Copy(bytes, bytes.Length - 2, destinationArray, destinationArray.Length - 6, 2);
   Array.Copy(array, array.Length - 4, destinationArray, destinationArray.Length - 4, 4);

   return new Guid(destinationArray);
}

Note: Code is from Doug posted on StackOverflow: Sequential guid in linq to sql


Share: twitter | facebook   Action: used | fork | flag

c#

Mark 'c#' tag as 'like'

Mark 'c#' tag as 'ignore'

generated-id

Mark 'generated-id' tag as 'like'

Mark 'generated-id' tag as 'ignore'

guid

Mark 'guid' tag as 'like'

Mark 'guid' tag as 'ignore'

sequential-id

Mark 'sequential-id' tag as 'like'

Mark 'sequential-id' tag as 'ignore'


 @fredrikn "I'm the master"
3.11k
October 07, 2010 11:32 AM

Fork

 GUID Sequential generator -  @fredrikn Thursday 07, 2010 11:32 AM


0 Feedback


You must log in before you can give any feedback


0 Discussion(s)

Newest Oldest

You must log in before you can post a comment

Squeed
Made by: Fredrik Normén 2010