Fixed handling of enum items with signed types and negative values.

Fixes https://github.com/mono/Embeddinator-4000/issues/15.
This commit is contained in:
Joao Matos 2017-03-01 15:13:39 +00:00
Родитель a824a1d969
Коммит 5c0939d137
1 изменённых файлов: 9 добавлений и 2 удалений

Просмотреть файл

@ -136,20 +136,27 @@ namespace MonoEmbeddinator4000.Generators
if (Options.GeneratorKind == GeneratorKind.CPlusPlus)
@enum.Modifiers = Enumeration.EnumModifiers.Scoped;
var builtinType = @enum.Type as BuiltinType;
foreach (var item in type.DeclaredFields)
{
if (!item.IsLiteral)
continue;
var @value = Convert.ToUInt64(item.GetRawConstantValue());
var enumItem = new Enumeration.Item
{
Namespace = @enum,
Name = item.Name,
Value = @value,
ExplicitValue = true
};
var rawValue = item.GetRawConstantValue();
if (builtinType.IsUnsigned)
enumItem.Value = Convert.ToUInt64(rawValue);
else
enumItem.Value = (ulong) Convert.ToInt64(rawValue);
@enum.AddItem(enumItem);
}