Checking for empty guid
-
Thats how one of our developers with 18 years experience checks if guid is empty
public List GetCommentIdsByUserQueryID_Paging(Guid userQueryID, out int total, int skipCount = 0, int itemsPerPage = 20)
{
.........
if (userQueryID.ToString().Length==0) return null;
..........Should have been:
if (userQueryID.ToString() == "00000000-0000-0000-0000-000000000000") return null;
He should've known that :D Alternatively he could've looped and count the 0's. Just don't use
Guid.Empty
. I heard it's bugged :~It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
Should have been:
if (userQueryID.ToString() == "00000000-0000-0000-0000-000000000000") return null;
He should've known that :D Alternatively he could've looped and count the 0's. Just don't use
Guid.Empty
. I heard it's bugged :~It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}What if it has lower-case zeroes? :-D
You'll never get very far if all you do is follow instructions.
-
Should have been:
if (userQueryID.ToString() == "00000000-0000-0000-0000-000000000000") return null;
He should've known that :D Alternatively he could've looped and count the 0's. Just don't use
Guid.Empty
. I heard it's bugged :~It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}Sander Rossel wrote:
I heard it's bugged
You heard right - it's not even slightly unique.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
-
Thats how one of our developers with 18 years experience checks if guid is empty
public List GetCommentIdsByUserQueryID_Paging(Guid userQueryID, out int total, int skipCount = 0, int itemsPerPage = 20)
{
.........
if (userQueryID.ToString().Length==0) return null;
.......... -
Sander Rossel wrote:
I heard it's bugged
You heard right - it's not even slightly unique.
Those who fail to learn history are doomed to repeat it. --- George Santayana (December 16, 1863 – September 26, 1952) Those who fail to clear history are doomed to explain it. --- OriginalGriff (February 24, 1959 – ∞)
Isn't a non-unique GUID pretty unique :D
It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
What if it has lower-case zeroes? :-D
You'll never get very far if all you do is follow instructions.
You mean they aren't the letter O?
It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
} -
Thats how one of our developers with 18 years experience checks if guid is empty
public List GetCommentIdsByUserQueryID_Paging(Guid userQueryID, out int total, int skipCount = 0, int itemsPerPage = 20)
{
.........
if (userQueryID.ToString().Length==0) return null;
..........Don't fix that! Other places using that function meanwhile rely on its "feature" that it returns a *special* list for Guid.Empty()!
-
Exactly. Ought to be
Guid invalid = Guid.Empty();
if (userQueryID.ToString().ToUpper() != invalid.ToString().ToUpper());return null;Oops;! Happened to add another feature...
-
Thats how one of our developers with 18 years experience checks if guid is empty
public List GetCommentIdsByUserQueryID_Paging(Guid userQueryID, out int total, int skipCount = 0, int itemsPerPage = 20)
{
.........
if (userQueryID.ToString().Length==0) return null;
..........IIRC guid's are value not reference types so they can't be empty. Doesn't it have
hasValue()
method or some such? -
IIRC guid's are value not reference types so they can't be empty. Doesn't it have
hasValue()
method or some such?They can't be null, but they can be empty, which is the guid equivalent of zero. http://msdn.microsoft.com/en-us/library/system.guid.empty.aspx[^] There's no
HasValue
property or method; you just need to test whether it's equal toGuid.Empty
.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
They can't be null, but they can be empty, which is the guid equivalent of zero. http://msdn.microsoft.com/en-us/library/system.guid.empty.aspx[^] There's no
HasValue
property or method; you just need to test whether it's equal toGuid.Empty
.
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Richard Deeming wrote:
you just need to test whether it's equal to Guid.Empty
Except for that you probably don't actually need to. Edit: I'm also suspicious as to whether or not they're actually using
System.Guid
. The snippet doesn't specify, so it's possible that they rolled their own Guid class and then all bets are off.You'll never get very far if all you do is follow instructions.
-
Richard Deeming wrote:
you just need to test whether it's equal to Guid.Empty
Except for that you probably don't actually need to. Edit: I'm also suspicious as to whether or not they're actually using
System.Guid
. The snippet doesn't specify, so it's possible that they rolled their own Guid class and then all bets are off.You'll never get very far if all you do is follow instructions.
Well, you do if you want to know whether or not it's empty. ;P
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
-
Well, you do if you want to know whether or not it's empty. ;P
"These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer
Except you probably don't actually need to.
You'll never get very far if all you do is follow instructions.
-
Exactly. Ought to be
Guid invalid = Guid.Empty();
if (userQueryID.ToString().ToUpper() != invalid.ToString().ToUpper());return null;Oops;! Happened to add another feature...
Is the errant semi-colon on purpose? :suss:
You'll never get very far if all you do is follow instructions.
-
Isn't a non-unique GUID pretty unique :D
It's an OO world.
public class SanderRossel : Lazy<Person>
{
public void DoWork()
{
throw new NotSupportedException();
}
}Pretty much the same argument as that for "there are no uninteresting numbers". :thumbsup: "If there are uninteresting numbers, there must be a first uninteresting number, and that number would therefore be pretty interesting."
You'll never get very far if all you do is follow instructions.
-
Don't fix that! Other places using that function meanwhile rely on its "feature" that it returns a *special* list for Guid.Empty()!
Bernhard Hiller wrote:
it returns a *special* list for Guid.Empty()!
It's _expecte_d to, but does it?
You'll never get very far if all you do is follow instructions.