You are on page 1of 43

>

>

>
>
>
>
>
>
>

>
>
>
> Common C
> static
>

> Dynamic D
> dynamic
>
>

>

>
>

>

>

>
Calculator calc = GetCalculator();
int sum = calc.Add(10, 20);

object calc = GetCalculator();


Type calcType = calc.GetType();
object res = calcType.InvokeMember("Add",
BindingFlags.InvokeMethod, null,
new object[] { 10, 20 });
ScriptObject calc = GetCalculator();
int sum = Convert.ToInt32(res);
object res = calc.Invoke("Add", 10, 20);
int sum = Convert.ToInt32(res);

þ   typed dynamic calc = GetCalculator();


to be dynamic int sum = calc.Add(10, 20);

Dynamic Dynamic method


conversion invocation
‘ 
>

>

>
string[] strings = GetStrings();

string last = strings[strings.Length ŷ 1];


object strings = GetDynamicObject();

string last = strings[strings.Length ŷ 1];


object strings = GetDynamicObject();

string last = strings[strings~.Length ŷ 1];


object strings = GetDynamicObject();

string last = strings~[strings~.Length ŷ 1];


object strings = GetDynamicObject();

string last = strings~[strings~.Length ~ŷ 1];


object strings = GetDynamicObject();

string last = (string)strings~[strings~.Length ~ŷ 1];


object strings = GetDynamicObject();

string last = ~(string)strings~[strings~.Length ~ŷ 1];


object strings = GetDynamicObject();

string last = ~(string)strings~[strings~.Length ~ŷ 1];

>

>
object strings = GetDynamicObject();

string last = ~(string)strings~[strings~.Length ~ŷ 1];

>

>

G
object strings = GetDynamicObject();
string last;
dynamic { last = strings[strings.Length ŷ 1]; }
object strings = GetDynamicObject();
string last;
dynamic { last = strings[strings.Length ŷ 1]; }

>
>
>
object strings = GetDynamicObject();
string last;
dynamic { last = strings[strings.Length ŷ 1]; }

>
>
>

G
object strings = GetDynamicObject();

string last = strings[dynamic(strings).Length ŷ 1];


object strings = GetDynamicObject();

string last = strings[dynamic(strings).Length ŷ 1];

>

>
object strings = GetDynamicObject();

string last = strings[dynamic(strings).Length ŷ 1];

>

>

G
dynamic strings = GetDynamicObject();

string last = strings[strings.Length ŷ 1];


dynamic strings = GetDynamicObject();

string last = strings[strings.Length ŷ 1];

>

>
dynamic strings = GetDynamicObject();

string last = strings[strings.Length ŷ 1];

>

>

G
>

>

>
>
dynamic Foo foo = GetDynamicFoo();
>
>

>
dynamic foo = GetDynamicFoo();

>
>
>
dynamic Foo foo = GetDynamicFoo();
>
> G
>
dynamic foo = GetDynamicFoo();

>
>
G
>
dynamic result = Math.Abs((double)d);

>

>
dynamic result = Math.Abs(d);
>
>
dynamic result = Math.Abs((double)d);

> G
>
dynamic result = Math.Abs(d);
>
G
>
> Math.Abs(d)
> d(ũHelloŪ)
> d.Length
> 4 + d
> d[ũHelloŪ]
>
> (double)d
> new Foo(d)
M(GetFoo(), d);

ëind with ëind with



 type   type
M(GetFoo(), d);

ëind with ëind with



 type   type

>

>
>
dynamic
 se my r ntime type for bindingµ
>

Type calcType = calc.GetType();


object res = calcType.InvokeMember("Add",
BindingFlags.InvokeMethod, null,
new object[] { 10, 20 });
int sum = Convert.ToInt32(res);

int sum = calc.Add(10, 20);


r& 
 6$
 
 / !  å Hall F Ä  
  
&-
 

.
6$"
 / !  #å Hall F j‘  

.&-
 
.. 0 ),)) 

 / !  #å
å ë r  
‘
6  
      
  !  "#å
å etree Hall D Ä 
r$ +
,-

+ .
.
 * !  å  Ä  
   6$%&'()
( 
 * "#!  å etree Hall D r 
    %&'()
( 
 * "#!  å etree Hall C r   

>

>

channel9.msdn.com/learn
ë ilt by Developers for Developers¬.
0 29 Microsoft Corporation. ll rights reserved. Microsoft, Windows, Windows Vista and other prod ct names are or may be registered trademarks and/or trademarks in the U.S. and/or other co ntries.
The information herein is for informational p rposes only and represents the c rrent view of Microsoft Corporation as of the date of this presentation. ëeca se Microsoft m st respond to changing market
conditions, it sho ld not be interpreted to be a commitment on the part of Microsoft, and Microsoft cannot g arantee the acc racy of any information provided after the date of this presentation. MICROSOFT
MS NO WRRNTIS,  RSS, IM
ID OR STTUTORY, S TO TH INFORMTION IN THIS RSNTTION.