danielcrenna/tweetsharp — Issue #13: Streaming broken, TwitterStreamArtifact is always null
Author: srijken
Created: 2011-12-29 08:42:15+00:00
State: open

On all events, TwitterStreamArtifact is null. I'm able to work around the problem with the code below:

Type _serializerType = Type.GetType("TweetSharp.Serialization.JsonSerializer, TweetSharp");
private object _serializer;
object Serializer
{
get
{
if (_serializer != null)
return _serializer;

_serializer = Activator.CreateInstance(_serializerType, true);
return _serializer;
}
}

private FieldInfo _responseField;
private FieldInfo ResponseField
{
get { return _responseField ?? (_responseField = typeof (TwitterResponse).GetField("_response", BindingFlags.Instance | BindingFlags.NonPublic)); }
}

private MethodInfo _deserializeMethod;
private MethodInfo DeserializeMethod
{
get
{
if(_deserializeMethod != null)
return _deserializeMethod;

var method = _serializerType.GetMethod("Deserialize", new[] { typeof(Hammock.RestResponseBase) });

_deserializeMethod =
method.MakeGenericMethod(typeof(TwitterStreamArtifact));

return _deserializeMethod;
}
}

private void OnStream(TwitterStreamArtifact streamEvent, TwitterResponse response)
{
if (streamEvent == null)
{
var responseobj = ResponseField.GetValue(response);
streamEvent = (TwitterStreamArtifact)DeserializeMethod.Invoke(Serializer, new object[] { responseobj });
}