Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions src/benchmarks/micro/Serializers/DataGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ internal static T Generate<T>()
return (T)(object)CreateLargeStructWithProperties();
if (typeof(T) == typeof(int))
return (T)(object)42;
if (typeof(T) == typeof(DateTime?))
return (T)(object)DateTime.UtcNow;
if (typeof(T) == typeof(ClassWithValueTypes))
return (T)(object)CreateClassWithValueTypes();

throw new NotImplementedException();
}
Expand Down Expand Up @@ -178,7 +182,7 @@ private static DateTime[] CreateDateTimeArray(int count)

return arr;
}

private static Dictionary<int, string> CreateDictionaryOfIntString(int count)
{
Dictionary<int, string> dictOfIntString = new Dictionary<int, string>(count);
Expand Down Expand Up @@ -213,6 +217,17 @@ private static XmlElement CreateXmlElement()
xmlElement.InnerText = "Element innertext";
return xmlElement;
}

private static ClassWithValueTypes CreateClassWithValueTypes()
=> new ClassWithValueTypes
{
Value = 0,
NullableValueSet = 1,
NullableValueNull = null,
LargeStruct = CreateLargeStructWithProperties(),
NullableLargeStructSet = CreateLargeStructWithProperties(),
NullableLargeStructNull = null
};
}

// the view models come from a real world app called "AllReady"
Expand Down Expand Up @@ -286,7 +301,7 @@ public class CampaignSummaryViewModel
[Serializable]
[ProtoContract]
[MessagePackObject]
public class IndexViewModel
public class IndexViewModel
{
[ProtoMember(1)] [Key(0)] public List<ActiveOrUpcomingEvent> ActiveOrUpcomingEvents { get; set; }
[ProtoMember(2)] [Key(1)] public CampaignSummaryViewModel FeaturedCampaign { get; set; }
Expand Down Expand Up @@ -365,10 +380,10 @@ public class CollectionsOfPrimitives
{
[ProtoMember(1)] [Key(0)] public byte[] ByteArray { get; set; }
[ProtoMember(2)] [Key(1)] public DateTime[] DateTimeArray { get; set; }

[XmlIgnore] // xml serializer does not support anything that implements IDictionary..
[ProtoMember(3)] [Key(2)] public Dictionary<int, string> Dictionary { get; set; }

[ProtoMember(4)] [Key(3)] public List<int> ListOfInt { get; set; }
}

Expand Down Expand Up @@ -396,7 +411,7 @@ public struct SimpleStructWithProperties
}

public class SimpleListOfInt : List<int> { }

public class ClassImplementingIXmlSerialiable : IXmlSerializable
{
public string StringValue { get; set; }
Expand All @@ -419,4 +434,19 @@ public void WriteXml(XmlWriter writer)
writer.WriteAttributeString("BoolValue", BoolValue.ToString());
}
}

public class ClassWithValueTypes
{
public int Value { get; set; }

public int? NullableValueSet { get; set; }

public int? NullableValueNull { get; set; }

public LargeStructWithProperties LargeStruct { get; set; }

public LargeStructWithProperties? NullableLargeStructSet { get; set; }

public LargeStructWithProperties? NullableLargeStructNull { get; set; }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace System.Text.Json.Serialization.Tests
[GenericTypeArguments(typeof(SimpleStructWithProperties))]
[GenericTypeArguments(typeof(LargeStructWithProperties))]
[GenericTypeArguments(typeof(int))]
[GenericTypeArguments(typeof(DateTime?))]
[GenericTypeArguments(typeof(ClassWithValueTypes))]
public class WriteJson<T>
{
private T _value;
Expand Down