leejw51 / protobuf-net

Automatically exported from code.google.com/p/protobuf-net
0 stars 0 forks source link

Limit of MethodInfo.GetParameters on NetCF #87

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
On Compact Framework Serializer.NonGeneric will throw
NotSupportedException, message is "GetParameters for Open Generic methods
is not supported". As says this is a limitation of NetCF. I made some
changes like below and seems work.

if (method.Name == "SerializeWithLengthPrefix" && method.IsGenericMethod)
{
    MethodInfo genericMethod = method.MakeGenericMethod(instance.GetType());
    if((p = genericMethod.GetParameters()).Length == 4
        && p[0].ParameterType == typeof(Stream)
        && p[2].ParameterType == typeof(PrefixStyle)
        && p[3].ParameterType == typeof(int))
        genericMethod.Invoke( ...

Original issue reported on code.google.com by ulysess444@gmail.com on 30 Dec 2009 at 11:18

GoogleCodeExporter commented 9 years ago
Thanks for the report and fix; I'll try to integrate this in a build soon.

Original comment by marc.gravell on 30 Dec 2009 at 11:36

GoogleCodeExporter commented 9 years ago
sorry, the code I showed has a mistake, there's two statement after 
MakeGenericMethod
for "SerializeWithLengthPrefix" and "Serialize" - a invoke and a return - must 
place
together in { }, "Deserialize" and "DeepClone" only have one line contain both 
return
and invoke.

Original comment by ulysess444@gmail.com on 31 Dec 2009 at 7:06

GoogleCodeExporter commented 9 years ago
Hello Marc.

I would like to use protobuf-net in a Compact Framework project (v3.5).   Is a
release planned to incorporate this change?

Thanks,
Matt

Original comment by matthew....@gmail.com on 23 Jan 2010 at 6:04

GoogleCodeExporter commented 9 years ago
Yes; I'm currently trying to unpick some intertwined good/bad changes - hope to 
release 
a stable version (with this patch) in the next few days (today, tomorrow, 
something 
like that).

Original comment by marc.gravell on 25 Jan 2010 at 9:53

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 28 Jan 2010 at 7:25

GoogleCodeExporter commented 9 years ago
I think that is fixed in r282; any feedback?

Original comment by marc.gravell on 28 Jan 2010 at 7:57

GoogleCodeExporter commented 9 years ago
There are 4 methods have this problem, "SerializeWithLengthPrefix", "Serialize",
"Deserialize" and "DeepClone", see comment2 posted by me. "Serialize" is 
similar to
"SerializeWithLengthPrefix", other two has some differences.

if (method.Name == "Deserialize" && method.IsGenericMethod)
{
    MethodInfo genericMethod = method.MakeGenericMethod(type);
    if ((p = genericMethod.GetParameters()).Length == 1
        && p[0].ParameterType == typeof(Stream))
        return genericMethod.Invoke(null, new object[] { source });
}

Original comment by ulysess444@gmail.com on 29 Jan 2010 at 3:55

GoogleCodeExporter commented 9 years ago
OK; will update and re-publish

Original comment by marc.gravell on 29 Jan 2010 at 7:44

GoogleCodeExporter commented 9 years ago

Original comment by marc.gravell on 22 Apr 2010 at 9:22