public void EmptyTest() { var c = new ConstantStringArray() { StringsWith5Chars = new[] { "", "", "" } }; var res = Utils.SerializeDeserialize(c); Utils.AssertAreEqual(res.StringsWith5Chars, new[] { new string(' ', 5), new string(' ', 5), new string(' ', 5) }); }
public void DefaultTest() { var c = new ConstantStringArray(); var res = Utils.SerializeDeserialize(c); Assert.AreEqual(res.StringsWith5Chars, c.StringsWith5Chars); }
private MetadataRecord HandleCustomAttributeConstantArray( Cts.ArrayType type, ImmutableArray <Ecma.CustomAttributeTypedArgument <Cts.TypeDesc> > value) { Cts.TypeDesc elementType = type.ElementType; switch (elementType.UnderlyingType.Category) { case Cts.TypeFlags.Boolean: return(new ConstantBooleanArray { Value = GetCustomAttributeConstantArrayElements <bool>(value) }); case Cts.TypeFlags.Byte: return(new ConstantByteArray { Value = GetCustomAttributeConstantArrayElements <byte>(value) }); case Cts.TypeFlags.Char: return(new ConstantCharArray { Value = GetCustomAttributeConstantArrayElements <char>(value) }); case Cts.TypeFlags.Double: return(new ConstantDoubleArray { Value = GetCustomAttributeConstantArrayElements <double>(value) }); case Cts.TypeFlags.Int16: return(new ConstantInt16Array { Value = GetCustomAttributeConstantArrayElements <short>(value) }); case Cts.TypeFlags.Int32: return(new ConstantInt32Array { Value = GetCustomAttributeConstantArrayElements <int>(value) }); case Cts.TypeFlags.Int64: return(new ConstantInt64Array { Value = GetCustomAttributeConstantArrayElements <long>(value) }); case Cts.TypeFlags.SByte: return(new ConstantSByteArray { Value = GetCustomAttributeConstantArrayElements <sbyte>(value) }); case Cts.TypeFlags.Single: return(new ConstantSingleArray { Value = GetCustomAttributeConstantArrayElements <float>(value) }); case Cts.TypeFlags.UInt16: return(new ConstantUInt16Array { Value = GetCustomAttributeConstantArrayElements <ushort>(value) }); case Cts.TypeFlags.UInt32: return(new ConstantUInt32Array { Value = GetCustomAttributeConstantArrayElements <uint>(value) }); case Cts.TypeFlags.UInt64: return(new ConstantUInt64Array { Value = GetCustomAttributeConstantArrayElements <ulong>(value) }); } if (elementType.IsString) { var record = new ConstantStringArray(); record.Value.Capacity = value.Length; foreach (var element in value) { MetadataRecord elementRecord = element.Value == null ? (MetadataRecord) new ConstantReferenceValue() : HandleString((string)element.Value); record.Value.Add(elementRecord); } return(record); } var result = new ConstantHandleArray(); result.Value.Capacity = value.Length; for (int i = 0; i < value.Length; i++) { MetadataRecord elementRecord = HandleCustomAttributeConstantValue(value[i].Type, value[i].Value); if (value[i].Type.IsEnum) { elementRecord = new ConstantBoxedEnumValue { Value = elementRecord, Type = HandleType(value[i].Type) }; } result.Value.Add(elementRecord); } return(result); }
public void SameLengthsTest() { var c = new ConstantStringArray() { StringsWith5Chars = new[] { "01234", "01234", "01234" } }; var res = Utils.SerializeDeserialize(c); Assert.AreEqual(res.StringsWith5Chars, c.StringsWith5Chars); }
public void MixedTest() { var c = new ConstantStringArray() { StringsWith5Chars = new[] { "", "01234", null, "012345678", "012" } }; var res = Utils.SerializeDeserialize(c); Utils.AssertAreEqual(res.StringsWith5Chars, new[] { new string(' ', 5), "01234", new string(' ', 5), "01234", "012 " }); }
public void CStringArr3_Test() { var c = new ConstantStringArray() { StringsWith5Chars = new[] { "abcde", "ABCDE", "01234", "01 ", "01234" } }; Utils.TestRoundTrip(c, "CStringArr3"); }
public void CStringArr1_Test() { var c = new ConstantStringArray(); Utils.TestRoundTrip(c, "CStringArr1"); }