public static FromBytes ( byte bytes, GuidRepresentation representation ) : System.Guid | ||
bytes | byte | The byte array. |
representation | GuidRepresentation | The representation of the Guid in the byte array. |
return | System.Guid |
/// <summary> /// Converts this BsonBinaryData to a Guid. /// </summary> /// <param name="guidRepresentation">The representation for Guids.</param> /// <returns>A Guid.</returns> public Guid ToGuid(GuidRepresentation guidRepresentation) { if (_subType != BsonBinarySubType.UuidStandard && _subType != BsonBinarySubType.UuidLegacy) { var message = string.Format("SubType must be UuidStandard or UuidLegacy, not {0}.", _subType); throw new InvalidOperationException(message); } if (guidRepresentation == GuidRepresentation.Unspecified) { throw new ArgumentException("GuidRepresentation cannot be Unspecified."); } return(GuidConverter.FromBytes(_bytes, guidRepresentation)); }
/// <summary> /// Converts this BsonBinaryData to a Guid. /// </summary> /// <returns>A Guid.</returns> public Guid ToGuid() { #pragma warning disable 618 if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V2) { return(ToGuid(_guidRepresentation)); } else { if (_subType != BsonBinarySubType.UuidStandard) { throw new InvalidOperationException("ToGuid without a Guid representation can only be called when sub type is UuidStandard."); } return(GuidConverter.FromBytes(_bytes, GuidRepresentation.Standard)); } #pragma warning restore 618 }
/// <summary> /// Converts this BsonBinaryData to a Guid. /// </summary> /// <param name="guidRepresentation">The representation for Guids.</param> /// <returns>A Guid.</returns> public Guid ToGuid(GuidRepresentation guidRepresentation) { if (_subType != BsonBinarySubType.UuidStandard && _subType != BsonBinarySubType.UuidLegacy) { var message = string.Format("SubType must be UuidStandard or UuidLegacy, not {0}.", _subType); throw new InvalidOperationException(message); } if (guidRepresentation == GuidRepresentation.Unspecified) { throw new ArgumentException("GuidRepresentation cannot be Unspecified."); } #pragma warning disable 618 if (BsonDefaults.GuidRepresentationMode == GuidRepresentationMode.V3) { var expectedSubType = GuidConverter.GetSubType(guidRepresentation); if (_subType != expectedSubType) { throw new InvalidOperationException($"ToGuid with Guid representation {guidRepresentation} can only be called when sub type is {expectedSubType}."); } } #pragma warning restore 618 return(GuidConverter.FromBytes(_bytes, guidRepresentation)); }