Esempio n. 1
0
        private string ToFlagsString(TEnum enumValue)
        {
            ulong value = UnsafeDynamicCast <TEnum, ulong> .Cast(enumValue);

            var builder = flagsStringBuilder.Value.Clear();

            string result;

            if (enumToNameMap.TryGetValue(enumValue, out result))
            {
                return(result);
            }
            else
            {
                ulong mask = 0x1;

                for (int i = 0; i < 64; i++)
                {
                    if ((value & mask) == mask && enumToNameMap.TryGetValue(UnsafeDynamicCast <ulong, TEnum> .Cast(mask), out result))
                    {
                        builder.Append(result).Append(", ");
                    }

                    mask <<= 1;
                }
            }

            return(builder.ToString(0, builder.Length - 2));
        }
Esempio n. 2
0
        private bool TryParseFlags(ReadOnlyMemory <char> value, Dictionary <ReadOnlyMemory <char>, TEnum> dictionary, out TEnum result)
        {
            ulong enumValue = 0;

            int pos = 0;

            var span = value.Span;

            while (pos < value.Length)
            {
                int start = pos;

                while (pos < value.Length && span[pos] != ',')
                {
                    pos++;
                }

                if (!TryParseInternal(value.Slice(start, pos - start), dictionary, out TEnum temp))
                {
                    result = default;
                    return(false);
                }

                enumValue |= UnsafeDynamicCast <TEnum, ulong> .Cast(temp);

                pos++;
            }

            result = UnsafeDynamicCast <ulong, TEnum> .Cast(enumValue);

            return(true);
        }
Esempio n. 3
0
        public bool HasFlag(TEnum enumValue, TEnum flagValue)
        {
            ulong value = UnsafeDynamicCast <TEnum, ulong> .Cast(enumValue);

            ulong flag = UnsafeDynamicCast <TEnum, ulong> .Cast(flagValue);

            return((value & flag) == flag);
        }
Esempio n. 4
0
        private TEnum ParseFlags(ReadOnlyMemory <char> value, Dictionary <ReadOnlyMemory <char>, TEnum> dictionary)
        {
            ulong enumValue = 0;

            int pos = 0;

            while (pos < value.Length)
            {
                int start = pos;

                while (pos < value.Length && value.Span[pos] != ',')
                {
                    pos++;
                }

                ParseInternal(value.Slice(start, pos - start), dictionary, out TEnum result);

                enumValue |= UnsafeDynamicCast <TEnum, ulong> .Cast(result);

                pos++;
            }

            return(UnsafeDynamicCast <ulong, TEnum> .Cast(enumValue));
        }
Esempio n. 5
0
 public string GetName <TEnumUnderlyingType>(TEnumUnderlyingType enumValue)
     where TEnumUnderlyingType : unmanaged =>
 ToString(UnsafeDynamicCast <TEnumUnderlyingType, TEnum> .Cast(enumValue));
Esempio n. 6
0
 public TEnumUnderlyingType?GetValue <TEnumUnderlyingType>(TEnum?value)
     where TEnumUnderlyingType : unmanaged =>
 UnsafeDynamicCast <TEnum?, TEnumUnderlyingType?> .Cast(value);