2

Consider the following in .NET 3.5 (using the Bin\Net35\Facebook*.dll assemblies):

using Facebook;

var app = new FacebookApp();
var result = app.Get("me");
// want to access result properties with no dynamic

... in the absence of the C# 4.0 dynamic keyword this provides only generic object members.
How best should I access the facebook properties of this result object?

Are there helper or utility methods or stronger types in the facebook C# SDK, or should I use standard .NET reflection techniques?

1

3 Answers 3

5

This code sample shows 3.5 usage, without needing the C# dynamic keyword:

// Using IDictionary<string, object> (.Net 3.5)
var client = new FacebookClient();
var me = (IDictionary<string,object>)client.Get("me");
string firstName = (string)me["first_name"];
string lastName = (string)me["last_name"];
string email = (string)me["email"];
Sign up to request clarification or add additional context in comments.

1 Comment

For anyone else who just copied that and wondered why it doesn't compile, the correct spelling is 'IDictionary' :o)
0
var accesstoken = Session["AccessToken"].ToString();
var client = new FacebookClient(accesstoken);
dynamic result = client.Get("me", new { fields = "name,id,email" });
Details details = new Details();
details.Id = result.id;
details.Name = result.name;
details.Email = result.email;

Comments

-1

You can also create a facade object around the IDictionary, as explained here.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.