private void WirteEnumValue <T>(T value) where T : struct { AtValueBegin(); UInt64 integer = EnumCache <T> .ToUInt64(value); _streamWriter.Write('"'); _streamWriter.Write(JsonEncoder.Encode(value.ToString())); _streamWriter.Write('('); _streamWriter.Write(integer.ToString(CultureInfo.InvariantCulture)); _streamWriter.Write(')'); _streamWriter.Write('"'); AtValueEnd(); }
public void WriteFlags <T>(String tag, T value) where T : struct { WriteTag(tag); BeginArrayValue(); UInt64 flags = EnumCache <T> .ToUInt64(value); Boolean first = true; for (Int32 index = 0; index < EnumFlags <T> .Integers.Length; index++) { UInt64 flg = EnumFlags <T> .Integers[index]; if ((flags & flg) == flg) { flags &= ~flg; if (first) { first = false; } else { _streamWriter.Write(", "); } _streamWriter.Write('"'); _streamWriter.Write(JsonEncoder.Encode(EnumFlags <T> .Names[index])); _streamWriter.Write('('); _streamWriter.Write(flg.ToString(CultureInfo.InvariantCulture)); _streamWriter.Write(')'); _streamWriter.Write('"'); } } // Unexpected flags if (flags != 0) { if (!first) { _streamWriter.Write(", "); } _streamWriter.Write('('); _streamWriter.Write(flags.ToString(CultureInfo.InvariantCulture)); _streamWriter.Write(')'); } EndArrayValue(); _streamWriter.WriteLine(); }