Microsoft.Protocols.TestSuites.Common.Common.IsGUID C# (CSharp) Method

IsGUID() public static method

Check whether the byte array is GUID or not
public static IsGUID ( byte bytes ) : bool
bytes byte The byte array to be checked
return bool
        public static bool IsGUID(byte[] bytes)
        {
            bool isGUID = false;

            // Check GUID length with 16.
            if (bytes != null && bytes.Length == 16)
            {
                Guid guid = new Guid(bytes);

                // GUID format check regExpression.
                string regexPatten = @"^(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\"
                    + @"-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}$";
                System.Text.RegularExpressions.Regex regex = new System.Text.RegularExpressions.Regex(regexPatten);
                string guidStr = guid.ToString();
                isGUID = regex.IsMatch(guidStr);
            }

            return isGUID;
        }
Common