aboutsummaryrefslogtreecommitdiffhomepage
path: root/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
diff options
context:
space:
mode:
Diffstat (limited to 'csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs')
-rw-r--r--csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs20
1 files changed, 20 insertions, 0 deletions
diff --git a/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs b/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
index d0dc3e8b..ec222dc1 100644
--- a/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
+++ b/csharp/src/Google.Protobuf/Reflection/ReflectionUtil.cs
@@ -31,6 +31,7 @@
#endregion
using System;
+using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
@@ -102,5 +103,24 @@ namespace Google.Protobuf.Reflection
Expression call = Expression.Call(castTarget, method);
return Expression.Lambda<Action<object>>(call, targetParameter).Compile();
}
+
+ /// <summary>
+ /// Returns the next type from an iterator of types, unless the iterator is a null reference,
+ /// in which case null is returned.
+ /// </summary>
+ internal static Type GetNextType(IEnumerator<Type> generatedTypeIterator)
+ {
+ if (generatedTypeIterator == null)
+ {
+ return null;
+ }
+ if (!generatedTypeIterator.MoveNext())
+ {
+ // This parameter name corresponds to any public method supplying the generated types to start with.
+ throw new ArgumentException("More generated types left over after consuming all expected ones", "generatedTypes");
+ }
+ return generatedTypeIterator.Current;
+ }
+
}
} \ No newline at end of file