FromBytes() public static method

Converts a byte array to a Guid.
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
Example #1
0
 /// <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));
 }
Example #2
0
        /// <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
        }
Example #3
0
        /// <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));
        }