SlideShare uma empresa Scribd logo
1 de 8
Baixar para ler offline
C# 4.0
           dynamic
                or:
How I Learned to Stop Worrying and
           Love dynamic
“C# is still a statically typed language everywhere that
you are not using dynamic” – John Skeet

"Oh, well it's statically-typed as a dynamic type.“ – Scott
Hanselman blog

“C# is evolving nicely by introducing dynamic typing
through a static type called dynamic” – Nikhil Kothari
Office Interop
object oDocCustomProps = doc.CustomDocumentProperties;
Type typeDocCustomProps = oDocCustomProps.GetType();
typeDocCustomProps.InvokeMember(
               "Item",
               BindingFlags.Default |
               BindingFlags.SetProperty,
               null, oDocCustomProps,
               new object[] {propertyName, propertyValue});



                                     VS

aDoc.CustomDocumentProperties["CustomProperty1"] = "Alt.NET";
Calling Iron* from C#
ScriptEngine engine = Ruby.CreateEngine();
ScriptScope scope = engine.CreateScope();
engine.ExecuteFile("tax.rb", scope);

var CalculateTax =
         scope.GetVariable<Func<TaxableItem[], decimal>>("calculate_tax");

var items = new TaxableItem[] {
                new TaxableItem("Cola", 2.5),
                new TaxableItem("Donut",1.5)
            };

var tax = CalculateTax(items);

Console.WriteLine("Tax: {0}", tax);

Console.ReadLine();
Calling Iron* from C#
class Item                         def calculate_tax(items)
     def initialize(name, price)        total = 0.0
          @name = name
          @price = price                 items.each do |item|
     end                                      total += item.price * 0.1
                                          end
      def name
          @name                          return total
      end                          end

      def price
            @price
      end
end
C# 4.0 dynamic

Mais conteúdo relacionado

Mais procurados

Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
Princess Sam
 
Introduction to Underscore.js
Introduction to Underscore.jsIntroduction to Underscore.js
Introduction to Underscore.js
David Jacobs
 

Mais procurados (20)

Functional Programming with JavaScript
Functional Programming with JavaScriptFunctional Programming with JavaScript
Functional Programming with JavaScript
 
Set Default Values to Fields in Odoo 15
Set Default Values to Fields in Odoo 15Set Default Values to Fields in Odoo 15
Set Default Values to Fields in Odoo 15
 
LSL Scripting
LSL ScriptingLSL Scripting
LSL Scripting
 
Js interpreter interpreted
Js interpreter interpretedJs interpreter interpreted
Js interpreter interpreted
 
Underscore.js
Underscore.jsUnderscore.js
Underscore.js
 
Operator Overloading
Operator OverloadingOperator Overloading
Operator Overloading
 
operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++operator overloading & type conversion in cpp over view || c++
operator overloading & type conversion in cpp over view || c++
 
Javascript
JavascriptJavascript
Javascript
 
Lec 26.27-operator overloading
Lec 26.27-operator overloadingLec 26.27-operator overloading
Lec 26.27-operator overloading
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
The JavaScript Programming Language
The JavaScript Programming LanguageThe JavaScript Programming Language
The JavaScript Programming Language
 
Knockout extender
Knockout extenderKnockout extender
Knockout extender
 
Perl Tools for Productivity
Perl Tools for ProductivityPerl Tools for Productivity
Perl Tools for Productivity
 
Migration Objective-C to Swift
Migration Objective-C to SwiftMigration Objective-C to Swift
Migration Objective-C to Swift
 
Bca 2nd sem u-4 operator overloading
Bca 2nd sem u-4 operator overloadingBca 2nd sem u-4 operator overloading
Bca 2nd sem u-4 operator overloading
 
Flamingo Core Concepts
Flamingo Core ConceptsFlamingo Core Concepts
Flamingo Core Concepts
 
Operator overloading and type conversion in cpp
Operator overloading and type conversion in cppOperator overloading and type conversion in cpp
Operator overloading and type conversion in cpp
 
Operator overloading
Operator overloadingOperator overloading
Operator overloading
 
Operator overloading and type conversions
Operator overloading and type conversionsOperator overloading and type conversions
Operator overloading and type conversions
 
Introduction to Underscore.js
Introduction to Underscore.jsIntroduction to Underscore.js
Introduction to Underscore.js
 

Semelhante a C# 4.0 dynamic

11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
Phúc Đỗ
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
Piyush Katariya
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
Surinder Kaur
 

Semelhante a C# 4.0 dynamic (20)

Dlr
DlrDlr
Dlr
 
descriptive programming
descriptive programmingdescriptive programming
descriptive programming
 
JavaScript - Chapter 12 - Document Object Model
  JavaScript - Chapter 12 - Document Object Model  JavaScript - Chapter 12 - Document Object Model
JavaScript - Chapter 12 - Document Object Model
 
Realm database
Realm databaseRealm database
Realm database
 
11. session 11 functions and objects
11. session 11   functions and objects11. session 11   functions and objects
11. session 11 functions and objects
 
Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.Object Trampoline: Why having not the object you want is what you need.
Object Trampoline: Why having not the object you want is what you need.
 
JavaScript (without DOM)
JavaScript (without DOM)JavaScript (without DOM)
JavaScript (without DOM)
 
Week3
Week3Week3
Week3
 
Javascript
JavascriptJavascript
Javascript
 
Part 7
Part 7Part 7
Part 7
 
DOM and Events
DOM and EventsDOM and Events
DOM and Events
 
Coding using jscript test complete
Coding using jscript test completeCoding using jscript test complete
Coding using jscript test complete
 
ppt- u 2.pptx
ppt- u 2.pptxppt- u 2.pptx
ppt- u 2.pptx
 
java API for XML DOM
java API for XML DOMjava API for XML DOM
java API for XML DOM
 
KSP intro
KSP introKSP intro
KSP intro
 
What\'s New in C# 4.0
What\'s New in C# 4.0What\'s New in C# 4.0
What\'s New in C# 4.0
 
Java script
Java scriptJava script
Java script
 
Objective c
Objective cObjective c
Objective c
 
Day 1
Day 1Day 1
Day 1
 
iOS Session-2
iOS Session-2iOS Session-2
iOS Session-2
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
Apidays Singapore 2024 - Scalable LLM APIs for AI and Generative AI Applicati...
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot ModelNavi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Navi Mumbai Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 

C# 4.0 dynamic

  • 1. C# 4.0 dynamic or: How I Learned to Stop Worrying and Love dynamic
  • 2.
  • 3. “C# is still a statically typed language everywhere that you are not using dynamic” – John Skeet "Oh, well it's statically-typed as a dynamic type.“ – Scott Hanselman blog “C# is evolving nicely by introducing dynamic typing through a static type called dynamic” – Nikhil Kothari
  • 4.
  • 5. Office Interop object oDocCustomProps = doc.CustomDocumentProperties; Type typeDocCustomProps = oDocCustomProps.GetType(); typeDocCustomProps.InvokeMember( "Item", BindingFlags.Default | BindingFlags.SetProperty, null, oDocCustomProps, new object[] {propertyName, propertyValue}); VS aDoc.CustomDocumentProperties["CustomProperty1"] = "Alt.NET";
  • 6. Calling Iron* from C# ScriptEngine engine = Ruby.CreateEngine(); ScriptScope scope = engine.CreateScope(); engine.ExecuteFile("tax.rb", scope); var CalculateTax = scope.GetVariable<Func<TaxableItem[], decimal>>("calculate_tax"); var items = new TaxableItem[] { new TaxableItem("Cola", 2.5), new TaxableItem("Donut",1.5) }; var tax = CalculateTax(items); Console.WriteLine("Tax: {0}", tax); Console.ReadLine();
  • 7. Calling Iron* from C# class Item def calculate_tax(items) def initialize(name, price) total = 0.0 @name = name @price = price items.each do |item| end total += item.price * 0.1 end def name @name return total end end def price @price end end