1.Reflection 與 dynamic 都是在 runtime 時可操作 object 相關 methods / properties。
2.Reflection 可在 runtime 時檢閱 object 的 meta-data,如 methods / properties,也可以在 runtime 時 invoke 物件的 methods / properties。
3.dynamic 是在 .NET 4.0 時才有的語法。宣告 dynamic 的物件,該物件會在 runtime 時才確定執行物件的 methods / properties。換句話說,在 compiler 階段該物件的 methods / properties 若不存在,是不會發生錯誤,要等到 runtime 執行時,才會有錯誤訊息。
4.dynamic 的內部也是使用 Reflection。
5.使用 Reflection 可以呼叫 public 與 private 的 methods / properties,但是 dynamic 只能呼叫 public 的 methods / properties。
6.dynamic 是 instance,所以無法呼叫 static 的 methods,若要在 runtime 時呼叫 static 的 methods,只能透過 Reflection 才行。
沒有留言:
張貼留言