Skip to content

Instantly share code, notes, and snippets.

@tenfortyeight
Created November 14, 2013 07:32
Show Gist options
  • Save tenfortyeight/7462857 to your computer and use it in GitHub Desktop.
Save tenfortyeight/7462857 to your computer and use it in GitHub Desktop.
How come that the first version doesn't work, but the other do? I am missing something in all the dynamics...
//Version 1 - Don't work
public IEnumerable<string> GetAll()
{
var dataHistory = tbl.All(); //Massive, returns a dynamic object
var history = Deserialize(dataHistory);
return history;
}
private IEnumerable<string> Deserialize(dynamic dataHistory)
{
foreach (dynamic dataMessage in dataHistory) //This will blow up: Massive.DynamicModel.Query(string, params object[])' is a 'method' but is used like a 'type'
{
using (var stream = new MemoryStream(dataMessage.Payload))
{
//do stuff
yield return;
}
}
}
//Version 2: this works just fine. Same thing but not passing in the dynamic object as a parameter
public IEnumerable<string> GetAll()
{
dynamic tbl = new MessageHistory();
var dataHistory = tbl.All();
var history = new List<string>();
foreach (dynamic dataMessage in dataHistory)
{
using (var stream = new MemoryStream(dataMessage.Payload))
{
//do stuff
history.Add(message);
}
}
return history;
}
@victorarias
Copy link

Ops, I mean accepting a IEnumerable< dynamic > in the Deserialize method, not just IEnumerable :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment