public void CustomAttributeElementTypeEncoder_Enum() { var b = new BlobBuilder(); var e = new CustomAttributeElementTypeEncoder(b); Assert.Same(b, e.Builder); e.Enum("abc"); AssertEx.Equal(new byte[] { 0x55, 0x03, 0x61, 0x62, 0x63 }, b.ToArray()); b.Clear(); e.Enum("\ud800"); // unpaired surrogate AssertEx.Equal(new byte[] { 0x55, 0x03, 0xED, 0xA0, 0x80 }, b.ToArray()); b.Clear(); Assert.Throws <ArgumentNullException>(() => e.Enum(null)); AssertExtensions.Throws <ArgumentException>("enumTypeName", () => e.Enum("")); }
public static void CustomElementType(this CustomAttributeElementTypeEncoder typeEncoder, IFieldSymbol field) { switch (field.Type.SpecialType) { case SpecialType.System_Boolean: typeEncoder.Boolean(); break; case SpecialType.System_Byte: typeEncoder.Byte(); break; case SpecialType.System_Int16: typeEncoder.Int16(); break; case SpecialType.System_Int32: typeEncoder.Int32(); break; case SpecialType.System_Int64: typeEncoder.Int64(); break; case SpecialType.System_UInt16: typeEncoder.UInt16(); break; case SpecialType.System_UInt32: typeEncoder.UInt32(); break; case SpecialType.System_UInt64: typeEncoder.UInt64(); break; case SpecialType.System_Single: typeEncoder.Single(); break; case SpecialType.System_Double: typeEncoder.Double(); break; case SpecialType.System_Char: typeEncoder.Char(); break; case SpecialType.System_String: typeEncoder.String(); break; case SpecialType.System_Enum: typeEncoder.Enum(field.Type.ToString()); break; case SpecialType.System_SByte: typeEncoder.SByte(); break; default: throw new NotImplementedException(); } }
public void CustomAttributeElementTypeEncoder_Enum() { var b = new BlobBuilder(); var e = new CustomAttributeElementTypeEncoder(b); Assert.Same(b, e.Builder); e.Enum("abc"); AssertEx.Equal(new byte[] { 0x55, 0x03, 0x61, 0x62, 0x63 }, b.ToArray()); b.Clear(); e.Enum("\ud800"); // unpaired surrogate AssertEx.Equal(new byte[] { 0x55, 0x03, 0xED, 0xA0, 0x80 }, b.ToArray()); b.Clear(); Assert.Throws<ArgumentNullException>(() => e.Enum(null)); Assert.Throws<ArgumentException>(() => e.Enum("")); }