Commit f34759e0 authored by Jon Skeet's avatar Jon Skeet

Add test for clearing fields with reflection.

parent 2d245ffe
......@@ -264,6 +264,16 @@ namespace Google.ProtocolBuffers
TestUtil.AssertAllFieldsSet(message);
}
[TestMethod]
public void ReflectionClear()
{
TestAllTypes.Builder builder = TestAllTypes.CreateBuilder();
reflectionTester.SetAllFieldsViaReflection(builder);
reflectionTester.ClearAllFieldsViaReflection(builder);
TestAllTypes message = builder.Build();
TestUtil.AssertClear(message);
}
[TestMethod]
public void ReflectionSettersRejectNull()
{
......
......@@ -384,6 +384,18 @@ namespace Google.ProtocolBuffers
message[f("default_cord")] = "425";
}
/// <summary>
/// Clears every field of the message, using the reflection interface.
/// </summary>
/// <param name="message"></param>
internal void ClearAllFieldsViaReflection(IBuilder message)
{
foreach (FieldDescriptor field in message.AllFields.Keys)
{
message.WeakClearField(field);
}
}
// -------------------------------------------------------------------
/// <summary>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment