alexandru ghiondea c compiler sdet
Download
Skip this Video
Download Presentation
C# 4.0

Loading in 2 Seconds...

play fullscreen
1 / 18

C 4.0 - PowerPoint PPT Presentation


  • 121 Views
  • Uploaded on

Alexandru Ghiondea C# Compiler SDET. C# 4.0. The Evolution of C#. C# 4.0. Dynamic Programming. C# 3.0. Language Integrated Query. C# 2.0. Generics. C# 1.0. Managed Code. C# 4.0 Language Innovations. Dynamically Typed Objects Optional and Named Parameters

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about 'C 4.0' - yovela


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
alexandru ghiondea c compiler sdet
Alexandru Ghiondea

C# Compiler SDET

C# 4.0

the evolution of c
The Evolution of C#

C# 4.0

Dynamic Programming

C# 3.0

Language Integrated Query

C# 2.0

Generics

C# 1.0

Managed Code

slide3

C# 4.0 Language Innovations

  • Dynamically Typed Objects
  • Optional and Named Parameters
  • Improved COM Interoperability
net dynamic programming
.NET Dynamic Programming

IronPython

IronRuby

C#

VB.NET

Others…

Dynamic Language Runtime

Expression Trees

Dynamic Dispatch

Call Site Caching

ObjectBinder

JavaScriptBinder

PythonBinder

RubyBinder

COMBinder

dynamically typed objects
Dynamically Typed Objects

Calculator calc = GetCalculator();

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

.NET object

object calc = GetCalculator();

TypecalcType = calc.GetType();

object res = calcType.InvokeMember("Add",

BindingFlags.InvokeMethod, null,

newobject[] { 10, 20 });

int sum = Convert.ToInt32(res);

Dynamic Language object

ScriptObject calc = GetCalculator();

object res = calc.Invoke("Add", 10, 20);

int sum = Convert.ToInt32(res);

Statically typed to be dynamic

dynamic calc = GetCalculator();

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

Dynamic conversion

Dynamic method invocation

slide6

Under the cover

  • dynamic is a new type only in the compiler
  • The return type of a dynamic operation is dynamic
  • There is an assignment conversion from dynamic to any type
  • We support all types of operations on dynamic
idynamicobject
IDynamicObject

publicabstractclassDynamicObject : IDynamicObject

{

publicvirtualobjectGetMember(GetMemberBinder info);

publicvirtualobjectSetMember(SetMemberBinder info, object value);

publicvirtualobjectDeleteMember(DeleteMemberBinder info);

publicvirtualobjectUnaryOperation(UnaryOperationBinder info);

publicvirtualobjectBinaryOperation(BinaryOperationBinder info, objectarg);

publicvirtualobject Convert(ConvertBinder info);

publicvirtualobject Invoke(InvokeBinder info, object[] args);

publicvirtualobjectInvokeMember(InvokeMemberBinder info, object[] args);

publicvirtualobjectCreateInstance(CreateInstanceBinder info, object[] args);

publicvirtualobjectGetIndex(GetIndexBinder info, object[] indices);

publicvirtualobjectSetIndex(SetIndexBinder info, object[] indices, object value);

publicvirtualobjectDeleteIndex(DeleteIndexBinder info, object[] indices);

publicMetaObjectIDynamicObject.GetMetaObject();

}

slide10

Improved COM Interoperability

  • Automatic object  dynamic mapping
  • Optional and named parameters
  • Optional “ref” modifier
  • Interop type embedding (“No PIA”)
slide11

object -> dynamic mapping

We need to cast

((Excel.Range)xl.Cells[1,1]).Value2 = “ID”;

xl.Cells[1,1].Value2 = “ID”;

You can continue to “dot”

slide12

Optional and named parameters

xlWorkbook.Worksheets.Add(Type.Missing,

xlWorkbook.ActiveSheet, Type.Missing, Type.Missing);

Arguments evaluated in order written

xlWorkbook.Worksheets.Add(After:xlWorkbook.ActiveSheet);

Named arguments can appear in any order

slide13

Optional and named parameters

Optional parameters

publicStreamReaderOpenTextFile(

string path,

Encodingencoding,

booldetectEncoding,

intbufferSize);

publicStreamReaderOpenTextFile(

string path,

Encodingencoding = null,

booldetectEncoding = true,

intbufferSize = 1024);

Non-optional must be specified

OpenTextFile("foo.txt”);

OpenTextFile("foo.txt", Encoding.UTF8, bufferSize: 4096);

Named argument

slide14

Optional “ref” modifier

objectfileName = "Test.docx";

object missing = System.Reflection.Missing.Value;

doc.SaveAs(reffileName,

ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing,

ref missing, ref missing, ref missing);

doc.SaveAs("Test.docx");

slide15

Under the cover

  • The default value for a parameter is encoded with a DefaultParameterValue attribute
  • No change in overload resolution
  • The “omit ref” only works for COM objects
  • No-PIA encapsulates the used interfaces into the assembly
slide17

Additional Resources

  • C# 4.0 Samples and Whitepaper
    • http://code.msdn.microsoft.com/csharpfuture
  • Visual C# Developer Center
    • http://csharp.net
  • C# team member’s blogs
    • http://blogs.msdn.com/ericlippert/
    • http://blogs.msdn.com/cburrows/
    • http://blogs.msdn.com/samng/
    • http://blogs.msdn.com/sreekarc/
    • http://blogs.msdn.com/mattwar/
    • http://blogs.msdn.com/ed_maurer/
    • http://blogs.msdn.com/davsterl/
    • http://blogs.msdn.com/alexghi
ad