Beispiel #1
0
        /// <summary>
        /// Gets a single GUID value associated with the specified key.
        /// </summary>
        /// <param name="SectionName">Section name</param>
        /// <param name="Key">Key name</param>
        /// <param name="Value">Value associated with the specified key. If the key has more than one value, only the first one is returned</param>
        /// <returns>True if the key exists</returns>
        public bool GetGUID(string SectionName, string Key, out Guid Value)
        {
            Value = Guid.Empty;
            string TextValue;
            bool   Result = GetString(SectionName, Key, out TextValue);

            if (Result)
            {
                string HexString = "";
                if (TextValue.Contains("A=") && TextValue.Contains("B=") && TextValue.Contains("C=") && TextValue.Contains("D="))
                {
                    char[]   Separators      = new char[] { '(', ')', '=', ',', ' ', 'A', 'B', 'C', 'D' };
                    string[] ComponentValues = TextValue.Split(Separators, StringSplitOptions.RemoveEmptyEntries);
                    if (ComponentValues.Length == 4)
                    {
                        for (int ComponentIndex = 0; ComponentIndex < 4; ComponentIndex++)
                        {
                            int IntegerValue;
                            Result    &= Int32.TryParse(ComponentValues[ComponentIndex], out IntegerValue);
                            HexString += IntegerValue.ToString("X8");
                        }
                    }
                }
                else
                {
                    HexString = TextValue;
                }

                try
                {
                    Value  = Guid.ParseExact(HexString, "N");
                    Result = true;
                }
                catch (Exception)
                {
                    Result = false;
                }
            }
            return(Result);
        }
Beispiel #2
0
//JAVA TO C# CONVERTER TODO TASK: Most Java annotations will not have direct .NET equivalent attributes:
//ORIGINAL LINE: @Test void shouldHandleStringPredicatesWithOffset()
        internal virtual void ShouldHandleStringPredicatesWithOffset()
        {
            // Given
            sbyte[] bytes = "abcdefghijklmnoprstuvxyzABCDEFGHIJKLMNOPRSTUVXYZ".GetBytes(UTF_8);

            for (int offset = 0; offset <= bytes.Length; offset++)
            {
                for (int length = 0; length < bytes.Length - offset; length++)
                {
                    TextValue value = utf8Value(bytes, offset, length);

                    for (int otherOffset = 0; otherOffset <= bytes.Length; otherOffset++)
                    {
                        for (int otherLength = 0; otherLength < bytes.Length - otherOffset; otherLength++)
                        {
                            TextValue other = utf8Value(bytes, otherOffset, otherLength);
                            assertThat(value.StartsWith(other), equalTo(otherLength == 0 || otherOffset == offset && otherLength <= length));
                            assertThat(value.EndsWith(other), equalTo(otherLength == 0 || otherOffset >= offset && otherLength == length + offset - otherOffset));
                            assertThat(value.Contains(other), equalTo(otherLength == 0 || otherOffset >= offset && otherLength <= length + offset - otherOffset));
                        }
                    }
                }
            }
        }