2011-01-12 121 views
2

考慮以下.NET 3.5中(使用bin \ Net35 \ Facebook的* .DLL組件):使用.NET 3.5 API訪問Facebook C#SDK結果對象?

using Facebook; 

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

...在沒有C#4.0 dynamic關鍵字這僅提供了通用的object成員。
如何最好地訪問此結果對象的Facebook屬性?

在Facebook C#SDK中是否有助手或實用方法或更強大的類型,還是應該使用標準的.NET反射技術?

+0

類似的問題 - http://stackoverflow.com/questions/4674669/facebook-c-sdk-net-3-5-dynamic-objects – 2011-01-14 20:47:59

回答

5

code sample顯示3.5的使用,而無需在C#dynamic關鍵字:

// 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"]; 
+0

爲別人誰只是複製了,不知道爲什麼它不't編譯,正確的拼寫是'IDictionary':o) – Marc 2013-06-20 16:41:45

-1

您還可以創建圍繞IDictionary的一個門面對象,解釋here

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; 
這裏