Skip to content

Commit 96a7baf

Browse files
committed
prep for flatten
1 parent c7cb8c0 commit 96a7baf

1 file changed

Lines changed: 23 additions & 2 deletions

File tree

src/ServiceStack.GrpcClient/GrpcServiceClient.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,29 @@ private static string GetTypeName(Type type)
715715
}
716716

717717
//also forces static initializer
718-
public static MetaType GetMetaType() => metaType
719-
??= typeof(T).IsValueType ? null : GrpcConfig.TypeModel.Add(typeof(T), applyDefaultBehaviour:true);
718+
public static MetaType GetMetaType() => metaType
719+
??= typeof(T).IsValueType ? null : CreateMetaType();
720+
721+
private static MetaType CreateMetaType()
722+
{
723+
// check to see if this is a request DTO; if it is, we'll do things manually;
724+
// do this by checking for the IReturn[Void|<T>] : IReturn API
725+
bool isRequest = typeof(IReturn).IsAssignableFrom(typeof(T))
726+
&& typeof(T).GetInterfaces().Any(
727+
x => x == typeof(IReturnVoid)
728+
|| x.IsGenericType && x.GetGenericTypeDefinition() == typeof(IReturn<>));
729+
730+
if (!isRequest)
731+
{
732+
// regular type; let the serializer worry about the details
733+
return GrpcConfig.TypeModel.Add(typeof(T), applyDefaultBehaviour: true);
734+
}
735+
// query type; flatten
736+
var mt = GrpcConfig.TypeModel.Add(typeof(T), applyDefaultBehaviour: false);
737+
738+
return mt;
739+
740+
}
720741

721742
public GrpcMarshaller() : base(Serialize, Deserialize) {}
722743

0 commit comments

Comments
 (0)