SlideShare a Scribd company logo
Expressions и все-все-все
http://sane.habrahabr.ru
http://der-waldgeist.blogspot.com
http://twitter.com/AlexSane
http://www.google.com/profiles/shurickFomin




                                    http://crew.taucraft.com/
Expression
…остальные              trees
 плюшки



             Expression
               Visitor
2+3*4

2+(3*4)
private static void Main()
{
  Func<int, int, int> f = (x, y) => x + y;
  Console.WriteLine(f);
}
System.Func`3[System.Int32,System.Int32,System.Int32]



[CompilerGenerated]
private static int <Main>b__0(int x, int y)
{
    return x+y;
}

private static void Main()
{
    var f = new Func<int, int, int>(Program.<Main>b__0));
    Console.WriteLine(f);
 }
static void Main()
{
    Expression<Func<int, int, int>> f = (x, y) => x + y;
    Console.WriteLine(f);
}

(x, y) => (x + y)



ParameterExpression CS0 = Expression.Parameter(typeof (int), "x");
ParameterExpression CS1 = Expression.Parameter(typeof (int), "y");
Expression<Func<int, int, int>> f =
         Expression.Lambda<Func<int, int, int>>(
                  Expression.Add(CS0, CS1),
                  new ParameterExpression[] {CS0, CS1}
         );
Expression<Func<DateTime, int>> f =
d => (int) Math.Abs((DateTime.Now - d).TotalSeconds);
d => (int) Math.Abs((DateTime.Now - d).TotalSeconds);

ParameterExpression CS0 = Expression.Parameter(typeof (DateTime), "d");
Expression<Func<DateTime, int>> f =
  Expression.Lambda<Func<DateTime, int>>(
    Expression.Convert(
       Expression.Call(
           null,
           (MethodInfo) methodof (Math.Abs),
           new Expression[]
           {
             Expression.Property(
                 Expression.Subtract(
                    Expression.Property(null, (MethodInfo) methodof (DateTime.get_Now)),
                    CS0,
                    (MethodInfo) methodof (DateTime.op_Subtraction)
                 ),
                 (MethodInfo) methodof (TimeSpan.get_TotalSeconds)
             )
           }
       ), typeof (int)
    ), new ParameterExpression[] {CS0} );
Expression
   tree
d => (int) Math.Abs((DateTime.Now - d).TotalSeconds);
.NET 3.0                      .NET 4.0

•   Operators                 •   Blocks
•   Method calls              •   Loops
•   Property getters          •   Try/Catch/Finally
•   Collection initializers   •   Goto/Labels
•   Object initializers       •   Variables
•   Convert/Cast              •   Assignments
•   Constants                 •   If/Then/Else

          (x,y)=>x+y              (x,y) => { return x+y; }*
ExpressionVisitor
protected virtual Expression VisitBinary(BinaryExpression b)
{
   Expression left = this.Visit(b.Left);
   Expression right = this.Visit(b.Right);
   return b;
}
protected virtual Expression VisitBinary(BinaryExpression b)
{
   Expression left = this.Visit(b.Left);
   Expression right = this.Visit(b.Right);
   if (left != b.Left || right != b.Right)
   {
         return Expression.MakeBinary(
                  b.NodeType, left, right, b.Method
         );
   }
    return b;
}
IQueryable<Tree> forest = // ...
var queryable = from tree in forest
                where tree.HasHollow
                select tree.ColectSomeHoney();

var queryable = forest.Where(tree => tree.HasHollow)
                .Select(tree => tree.ColectSomeHoney());

var queryable = Queryable.Select(
  Queryable.Where(forest, tree => tree.HasHollow),
     tree => tree.ColectSomeHoney() );

var queryable = Enumerable.Select(
  Enumerable.Where(forest.AsEnumerable (), tree => tree.HasHollow),
     tree => tree.ColectSomeHoney() );
internal override Expression VisitMethodCall(MethodCallExpression m)
{
    Expression instance = base.VisitMethodCall(m);
    if (m.Method.DeclaringType == typeof(Queryable))
    {
          MethodInfo info = FindEnumerableMethod(m.Method);
          return Expression.Call(instance, info, source);
    }
    return m;
}
internal override Expression VisitMethodCall(MethodCallExpression m)
{
    Expression instance = base.VisitMethodCall(m);

    if (m.Method.DeclaringType == typeof(Queryable))
    {
          MethodInfo info = FindEnumerableMethod(m.Method);
          return Expression.Call(instance, info, source);
    }
    return m;
}
Compiled expressions
string PasswordPhrase(bool isBear)
{
   return string.Format("{0} очень любит {1}",
      isBear ? "Мишка" : "Ослик",
      isBear ? "мёд" : "йод");
}
ILGenerator generator = //...
var label1 = generator.DefineLabel();
var label2 = generator.DefineLabel();
var label3 = generator.DefineLabel();
var label4 = generator.DefineLabel();
generator.Emit(OpCodes.Ldstr, "{0} очень любит {1}");
generator.Emit(OpCodes.Ldarg_1);
generator.Emit(OpCodes.Brtrue_S, label1);
generator.Emit(OpCodes.Ldstr, "Мишка");
generator.Emit(OpCodes.Br_S, label2);
generator.MarkLabel(label1);
generator.Emit(OpCodes.Ldstr, ”Ослик");
generator.MarkLabel(label2);
generator.Emit(OpCodes.Ldarg_1);
generator.Emit(OpCodes.Brtrue_S, label3);
generator.MarkLabel(label3);
generator.Emit(OpCodes.Ldstr, ”мёд");
generator.Emit(OpCodes.Br_S, label4);
generator.Emit(OpCodes.Ldstr, "йод");
generator.MarkLabel(label4);
generator.EmitCall(OpCodes.Call, typeof(String).GetMethod("Format"), new[] { typeof(string), typeof(ob
     ject), typeof(object) });
generator.Emit(OpCodes.Ret);
Func<bool, string> Emit()
{
  var isBear = Expression.Parameter(typeof (bool), "isBear");
  var lambda = Expression.Lambda<Func<bool, string>>(
   Expression.Call(
     Method(() => string.Format("", null, null)),
       Expression.Constant("{0} очень любит {1}"),
       Expression.Condition(isBear, Expression.Constant("Мишка"),
                              Expression.Constant("Ослик")),
         Expression.Condition(isBear, Expression.Constant("мёд"), Expression.C
onstant("йод") )
      )
   );
  Func<bool, string> func = lambda.Compile();
  return func;
}
Reflection in compile time
public class Tree
{
    public Honey ColectSomeHoney()
    {
           //...
           return new Honey();
    }
}
private static void Main()
{
    MethodInfo method =
      typeof(Tree).GetMethod( "ColectSomeHoney",
         BindingFlags.Public | BindingFlags.Instance
      );
}
Reflection in compile time
public class Tree
{
   public Honey CollectSomeHoney()
   {
         //...
         return new Honey();
   }
}
private static void Main()
{
    MethodInfo method =
     typeof(Tree).GetMethod( "ColectSomeHoney",
        BindingFlags.Public | BindingFlags.Instance
     );
}
Reflection in compile time
public class Tree
{
    public Honey CollectSomeHoney()
    {
          //...
          return new Honey();
    }
}
private static void Main()
{
    MethodInfo method =
     typeof(Tree).GetMethod( "ColectSomeHoney",
        BindingFlags.Public | BindingFlags.Instance
     );
}
Reflection in compile time
private static void Main()
{
  var method = GetMethod<Tree>(x => x.ColectSomeHoney());
}
public static MethodInfo GetMethod<T>(Expression<Action<T>> e)
{
  return ((MethodCallExpression) e.Body)
     .Method;
}
Reflection in compile time
private static void Main()
{
  var method = GetMethod<Tree>(x => x.CollectSomeHoney());
}
public static MethodInfo GetMethod<T>(Expression<Action<T>> e)
{
  return ((MethodCallExpression) e.Body)
     .Method;
}
IQueryable
interface IQueryable<T> : IEnumerable<T> , IQueryable
{
    Type ElementType { get; }
    Expression Expression { get; }
    IQueryProvider Provider { get; }
}

interface IQueryProvider
{
    IQueryable CreateQuery(Expression e) ;
    IQueryable<T> CreateQuery<T> (Expression e);
    object Execute (Expression expression);
    object Execute (Expression expression);
}
IQueryable
Expressions в C# — impress yourself!




                      http://habrahabr.ru/blogs/net/83169/
LINQ: Building an IQueryable provider
                series




        http://blogs.msdn.com/b/mattwar/archive/2008/11/18/linq-links.aspx
Винни-Пух и Все-Все-все




                  ISBN: 978-5-17-064151-2
Ciklum net sat12112011-alexander fomin-expressions and all, all, all

More Related Content

What's hot

TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
tdc-globalcode
 
Closure, Higher-order function in Swift
Closure, Higher-order function in SwiftClosure, Higher-order function in Swift
Closure, Higher-order function in Swift
SeongGyu Jo
 
Collection v3
Collection v3Collection v3
Collection v3
Sunil OS
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
Skills Matter
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
진성 오
 
PDBC
PDBCPDBC
PDBC
Sunil OS
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
Sunil OS
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
UC San Diego
 
Implementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickImplementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with Slick
Hermann Hueck
 
Using Scala Slick at FortyTwo
Using Scala Slick at FortyTwoUsing Scala Slick at FortyTwo
Using Scala Slick at FortyTwo
Eishay Smith
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
Paulo Morgado
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
Paulo Morgado
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
O T
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
greenwop
 
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italyFrom java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
Fabio Collini
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
Gil Cohen
 
C# 7
C# 7C# 7
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
gekiaruj
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
Husain Dalal
 
Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015
Iran Entrepreneurship Association
 

What's hot (20)

TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDBTDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
TDC2016POA | Trilha .NET - CQRS e ES na prática com RavenDB
 
Closure, Higher-order function in Swift
Closure, Higher-order function in SwiftClosure, Higher-order function in Swift
Closure, Higher-order function in Swift
 
Collection v3
Collection v3Collection v3
Collection v3
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applications
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기
 
PDBC
PDBCPDBC
PDBC
 
Collections Framework
Collections FrameworkCollections Framework
Collections Framework
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to Python
 
Implementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with SlickImplementing a many-to-many Relationship with Slick
Implementing a many-to-many Relationship with Slick
 
Using Scala Slick at FortyTwo
Using Scala Slick at FortyTwoUsing Scala Slick at FortyTwo
Using Scala Slick at FortyTwo
 
Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7Tuga IT 2017 - What's new in C# 7
Tuga IT 2017 - What's new in C# 7
 
What's New In C# 7
What's New In C# 7What's New In C# 7
What's New In C# 7
 
Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge Beginners python cheat sheet - Basic knowledge
Beginners python cheat sheet - Basic knowledge
 
Category theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) DataCategory theory, Monads, and Duality in the world of (BIG) Data
Category theory, Monads, and Duality in the world of (BIG) Data
 
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italyFrom java to kotlin beyond alt+shift+cmd+k - Droidcon italy
From java to kotlin beyond alt+shift+cmd+k - Droidcon italy
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheet
 
C# 7
C# 7C# 7
C# 7
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
Groovy grails types, operators, objects
Groovy grails types, operators, objectsGroovy grails types, operators, objects
Groovy grails types, operators, objects
 
Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015Pooya Khaloo Presentation on IWMC 2015
Pooya Khaloo Presentation on IWMC 2015
 

Similar to Ciklum net sat12112011-alexander fomin-expressions and all, all, all

HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6Dmitry Soshnikov
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
Dmitry Sheiko
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
James Titcumb
 
7 Habits For a More Functional Swift
7 Habits For a More Functional Swift7 Habits For a More Functional Swift
7 Habits For a More Functional Swift
Jason Larsen
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
Eugene Zharkov
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
James Titcumb
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET Application
Joni
 
Les nouveautés de C# 6
Les nouveautés de C# 6Les nouveautés de C# 6
Les nouveautés de C# 6
Microsoft
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
HamletDRC
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewPaulo Morgado
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
Simone Federici
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
Sérgio Rafael Siqueira
 
Pragmatic metaprogramming
Pragmatic metaprogrammingPragmatic metaprogramming
Pragmatic metaprogramming
Mårten Rånge
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)riue
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
Dmitry Soshnikov
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
Richard Fox
 
New C# features
New C# featuresNew C# features
New C# features
Alexej Sommer
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
How te bring common UI patterns to ADF
How te bring common UI patterns to ADFHow te bring common UI patterns to ADF
How te bring common UI patterns to ADF
Getting value from IoT, Integration and Data Analytics
 
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."
sjabs
 

Similar to Ciklum net sat12112011-alexander fomin-expressions and all, all, all (20)

HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
HelsinkiJS meet-up. Dmitry Soshnikov - ECMAScript 6
 
TypeScript Introduction
TypeScript IntroductionTypeScript Introduction
TypeScript Introduction
 
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
Mirror, mirror on the wall: Building a new PHP reflection library (DPC 2016)
 
7 Habits For a More Functional Swift
7 Habits For a More Functional Swift7 Habits For a More Functional Swift
7 Habits For a More Functional Swift
 
Elm: give it a try
Elm: give it a tryElm: give it a try
Elm: give it a try
 
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
Mirror, mirror on the wall - Building a new PHP reflection library (Nomad PHP...
 
Tips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET ApplicationTips and Tricks of Developing .NET Application
Tips and Tricks of Developing .NET Application
 
Les nouveautés de C# 6
Les nouveautés de C# 6Les nouveautés de C# 6
Les nouveautés de C# 6
 
Ast transformations
Ast transformationsAst transformations
Ast transformations
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 preview
 
Java VS Python
Java VS PythonJava VS Python
Java VS Python
 
Functional programming with php7
Functional programming with php7Functional programming with php7
Functional programming with php7
 
Pragmatic metaprogramming
Pragmatic metaprogrammingPragmatic metaprogramming
Pragmatic metaprogramming
 
関数潮流(Function Tendency)
関数潮流(Function Tendency)関数潮流(Function Tendency)
関数潮流(Function Tendency)
 
FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6FalsyValues. Dmitry Soshnikov - ECMAScript 6
FalsyValues. Dmitry Soshnikov - ECMAScript 6
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and Inference
 
New C# features
New C# featuresNew C# features
New C# features
 
Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++Using the Windows 8 Runtime from C++
Using the Windows 8 Runtime from C++
 
How te bring common UI patterns to ADF
How te bring common UI patterns to ADFHow te bring common UI patterns to ADF
How te bring common UI patterns to ADF
 
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."
Kamil Chmielewski, Jacek Juraszek - "Hadoop. W poszukiwaniu złotego młotka."
 

More from Ciklum Ukraine

"How keep normal blood pressure using TDD" By Roman Loparev
"How keep normal blood pressure using TDD" By Roman Loparev"How keep normal blood pressure using TDD" By Roman Loparev
"How keep normal blood pressure using TDD" By Roman Loparev
Ciklum Ukraine
 
"Through the three circles of the it hell" by Roman Liashenko
"Through the three circles of the it hell" by Roman Liashenko"Through the three circles of the it hell" by Roman Liashenko
"Through the three circles of the it hell" by Roman Liashenko
Ciklum Ukraine
 
Alex Pazhyn: Google_Material_Design
Alex Pazhyn: Google_Material_DesignAlex Pazhyn: Google_Material_Design
Alex Pazhyn: Google_Material_Design
Ciklum Ukraine
 
Introduction to amazon web services for developers
Introduction to amazon web services for developersIntroduction to amazon web services for developers
Introduction to amazon web services for developers
Ciklum Ukraine
 
Your 1st Apple watch Application
Your 1st Apple watch ApplicationYour 1st Apple watch Application
Your 1st Apple watch Application
Ciklum Ukraine
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Ciklum Ukraine
 
Back to the future: ux trends 2015
Back to the future: ux trends 2015Back to the future: ux trends 2015
Back to the future: ux trends 2015
Ciklum Ukraine
 
Developing high load systems using C++
Developing high load systems using C++Developing high load systems using C++
Developing high load systems using C++
Ciklum Ukraine
 
Collection view layout
Collection view layoutCollection view layout
Collection view layout
Ciklum Ukraine
 
Introduction to auto layout
Introduction to auto layoutIntroduction to auto layout
Introduction to auto layout
Ciklum Ukraine
 
Groovy on Android
Groovy on AndroidGroovy on Android
Groovy on Android
Ciklum Ukraine
 
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special Cases
Ciklum Ukraine
 
Material design
Material designMaterial design
Material design
Ciklum Ukraine
 
Kanban development
Kanban developmentKanban development
Kanban development
Ciklum Ukraine
 
Mobile sketching
Mobile sketching Mobile sketching
Mobile sketching
Ciklum Ukraine
 
More UX in our life
More UX in our lifeMore UX in our life
More UX in our life
Ciklum Ukraine
 
Model-View-Controller: Tips&Tricks
Model-View-Controller: Tips&TricksModel-View-Controller: Tips&Tricks
Model-View-Controller: Tips&Tricks
Ciklum Ukraine
 
Unit Tesing in iOS
Unit Tesing in iOSUnit Tesing in iOS
Unit Tesing in iOS
Ciklum Ukraine
 
Future of Outsourcing report published in The Times featuring Ciklum's CEO To...
Future of Outsourcing report published in The Times featuring Ciklum's CEO To...Future of Outsourcing report published in The Times featuring Ciklum's CEO To...
Future of Outsourcing report published in The Times featuring Ciklum's CEO To...Ciklum Ukraine
 
Михаил Попчук "Cкрытые резервы команд или 1+1=3"
Михаил Попчук "Cкрытые резервы команд или 1+1=3"Михаил Попчук "Cкрытые резервы команд или 1+1=3"
Михаил Попчук "Cкрытые резервы команд или 1+1=3"
Ciklum Ukraine
 

More from Ciklum Ukraine (20)

"How keep normal blood pressure using TDD" By Roman Loparev
"How keep normal blood pressure using TDD" By Roman Loparev"How keep normal blood pressure using TDD" By Roman Loparev
"How keep normal blood pressure using TDD" By Roman Loparev
 
"Through the three circles of the it hell" by Roman Liashenko
"Through the three circles of the it hell" by Roman Liashenko"Through the three circles of the it hell" by Roman Liashenko
"Through the three circles of the it hell" by Roman Liashenko
 
Alex Pazhyn: Google_Material_Design
Alex Pazhyn: Google_Material_DesignAlex Pazhyn: Google_Material_Design
Alex Pazhyn: Google_Material_Design
 
Introduction to amazon web services for developers
Introduction to amazon web services for developersIntroduction to amazon web services for developers
Introduction to amazon web services for developers
 
Your 1st Apple watch Application
Your 1st Apple watch ApplicationYour 1st Apple watch Application
Your 1st Apple watch Application
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Back to the future: ux trends 2015
Back to the future: ux trends 2015Back to the future: ux trends 2015
Back to the future: ux trends 2015
 
Developing high load systems using C++
Developing high load systems using C++Developing high load systems using C++
Developing high load systems using C++
 
Collection view layout
Collection view layoutCollection view layout
Collection view layout
 
Introduction to auto layout
Introduction to auto layoutIntroduction to auto layout
Introduction to auto layout
 
Groovy on Android
Groovy on AndroidGroovy on Android
Groovy on Android
 
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special Cases
 
Material design
Material designMaterial design
Material design
 
Kanban development
Kanban developmentKanban development
Kanban development
 
Mobile sketching
Mobile sketching Mobile sketching
Mobile sketching
 
More UX in our life
More UX in our lifeMore UX in our life
More UX in our life
 
Model-View-Controller: Tips&Tricks
Model-View-Controller: Tips&TricksModel-View-Controller: Tips&Tricks
Model-View-Controller: Tips&Tricks
 
Unit Tesing in iOS
Unit Tesing in iOSUnit Tesing in iOS
Unit Tesing in iOS
 
Future of Outsourcing report published in The Times featuring Ciklum's CEO To...
Future of Outsourcing report published in The Times featuring Ciklum's CEO To...Future of Outsourcing report published in The Times featuring Ciklum's CEO To...
Future of Outsourcing report published in The Times featuring Ciklum's CEO To...
 
Михаил Попчук "Cкрытые резервы команд или 1+1=3"
Михаил Попчук "Cкрытые резервы команд или 1+1=3"Михаил Попчук "Cкрытые резервы команд или 1+1=3"
Михаил Попчук "Cкрытые резервы команд или 1+1=3"
 

Recently uploaded

GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
Neo4j
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
James Anderson
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
mikeeftimakis1
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
Neo4j
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
Neo4j
 

Recently uploaded (20)

GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
GraphSummit Singapore | Enhancing Changi Airport Group's Passenger Experience...
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
Alt. GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using ...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Introduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - CybersecurityIntroduction to CHERI technology - Cybersecurity
Introduction to CHERI technology - Cybersecurity
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024GraphSummit Singapore | The Art of the  Possible with Graph - Q2 2024
GraphSummit Singapore | The Art of the Possible with Graph - Q2 2024
 
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
GraphSummit Singapore | The Future of Agility: Supercharging Digital Transfor...
 

Ciklum net sat12112011-alexander fomin-expressions and all, all, all

  • 3. Expression …остальные trees плюшки Expression Visitor
  • 4.
  • 6. private static void Main() { Func<int, int, int> f = (x, y) => x + y; Console.WriteLine(f); } System.Func`3[System.Int32,System.Int32,System.Int32] [CompilerGenerated] private static int <Main>b__0(int x, int y) { return x+y; } private static void Main() { var f = new Func<int, int, int>(Program.<Main>b__0)); Console.WriteLine(f); }
  • 7. static void Main() { Expression<Func<int, int, int>> f = (x, y) => x + y; Console.WriteLine(f); } (x, y) => (x + y) ParameterExpression CS0 = Expression.Parameter(typeof (int), "x"); ParameterExpression CS1 = Expression.Parameter(typeof (int), "y"); Expression<Func<int, int, int>> f = Expression.Lambda<Func<int, int, int>>( Expression.Add(CS0, CS1), new ParameterExpression[] {CS0, CS1} );
  • 8. Expression<Func<DateTime, int>> f = d => (int) Math.Abs((DateTime.Now - d).TotalSeconds);
  • 9. d => (int) Math.Abs((DateTime.Now - d).TotalSeconds); ParameterExpression CS0 = Expression.Parameter(typeof (DateTime), "d"); Expression<Func<DateTime, int>> f = Expression.Lambda<Func<DateTime, int>>( Expression.Convert( Expression.Call( null, (MethodInfo) methodof (Math.Abs), new Expression[] { Expression.Property( Expression.Subtract( Expression.Property(null, (MethodInfo) methodof (DateTime.get_Now)), CS0, (MethodInfo) methodof (DateTime.op_Subtraction) ), (MethodInfo) methodof (TimeSpan.get_TotalSeconds) ) } ), typeof (int) ), new ParameterExpression[] {CS0} );
  • 10. Expression tree
  • 11. d => (int) Math.Abs((DateTime.Now - d).TotalSeconds);
  • 12. .NET 3.0 .NET 4.0 • Operators • Blocks • Method calls • Loops • Property getters • Try/Catch/Finally • Collection initializers • Goto/Labels • Object initializers • Variables • Convert/Cast • Assignments • Constants • If/Then/Else (x,y)=>x+y (x,y) => { return x+y; }*
  • 13.
  • 15. protected virtual Expression VisitBinary(BinaryExpression b) { Expression left = this.Visit(b.Left); Expression right = this.Visit(b.Right); return b; }
  • 16. protected virtual Expression VisitBinary(BinaryExpression b) { Expression left = this.Visit(b.Left); Expression right = this.Visit(b.Right); if (left != b.Left || right != b.Right) { return Expression.MakeBinary( b.NodeType, left, right, b.Method ); } return b; }
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22. IQueryable<Tree> forest = // ... var queryable = from tree in forest where tree.HasHollow select tree.ColectSomeHoney(); var queryable = forest.Where(tree => tree.HasHollow) .Select(tree => tree.ColectSomeHoney()); var queryable = Queryable.Select( Queryable.Where(forest, tree => tree.HasHollow), tree => tree.ColectSomeHoney() ); var queryable = Enumerable.Select( Enumerable.Where(forest.AsEnumerable (), tree => tree.HasHollow), tree => tree.ColectSomeHoney() );
  • 23. internal override Expression VisitMethodCall(MethodCallExpression m) { Expression instance = base.VisitMethodCall(m); if (m.Method.DeclaringType == typeof(Queryable)) { MethodInfo info = FindEnumerableMethod(m.Method); return Expression.Call(instance, info, source); } return m; }
  • 24. internal override Expression VisitMethodCall(MethodCallExpression m) { Expression instance = base.VisitMethodCall(m); if (m.Method.DeclaringType == typeof(Queryable)) { MethodInfo info = FindEnumerableMethod(m.Method); return Expression.Call(instance, info, source); } return m; }
  • 25.
  • 26.
  • 27. Compiled expressions string PasswordPhrase(bool isBear) { return string.Format("{0} очень любит {1}", isBear ? "Мишка" : "Ослик", isBear ? "мёд" : "йод"); }
  • 28. ILGenerator generator = //... var label1 = generator.DefineLabel(); var label2 = generator.DefineLabel(); var label3 = generator.DefineLabel(); var label4 = generator.DefineLabel(); generator.Emit(OpCodes.Ldstr, "{0} очень любит {1}"); generator.Emit(OpCodes.Ldarg_1); generator.Emit(OpCodes.Brtrue_S, label1); generator.Emit(OpCodes.Ldstr, "Мишка"); generator.Emit(OpCodes.Br_S, label2); generator.MarkLabel(label1); generator.Emit(OpCodes.Ldstr, ”Ослик"); generator.MarkLabel(label2); generator.Emit(OpCodes.Ldarg_1); generator.Emit(OpCodes.Brtrue_S, label3); generator.MarkLabel(label3); generator.Emit(OpCodes.Ldstr, ”мёд"); generator.Emit(OpCodes.Br_S, label4); generator.Emit(OpCodes.Ldstr, "йод"); generator.MarkLabel(label4); generator.EmitCall(OpCodes.Call, typeof(String).GetMethod("Format"), new[] { typeof(string), typeof(ob ject), typeof(object) }); generator.Emit(OpCodes.Ret);
  • 29. Func<bool, string> Emit() { var isBear = Expression.Parameter(typeof (bool), "isBear"); var lambda = Expression.Lambda<Func<bool, string>>( Expression.Call( Method(() => string.Format("", null, null)), Expression.Constant("{0} очень любит {1}"), Expression.Condition(isBear, Expression.Constant("Мишка"), Expression.Constant("Ослик")), Expression.Condition(isBear, Expression.Constant("мёд"), Expression.C onstant("йод") ) ) ); Func<bool, string> func = lambda.Compile(); return func; }
  • 30. Reflection in compile time public class Tree { public Honey ColectSomeHoney() { //... return new Honey(); } } private static void Main() { MethodInfo method = typeof(Tree).GetMethod( "ColectSomeHoney", BindingFlags.Public | BindingFlags.Instance ); }
  • 31. Reflection in compile time public class Tree { public Honey CollectSomeHoney() { //... return new Honey(); } } private static void Main() { MethodInfo method = typeof(Tree).GetMethod( "ColectSomeHoney", BindingFlags.Public | BindingFlags.Instance ); }
  • 32. Reflection in compile time public class Tree { public Honey CollectSomeHoney() { //... return new Honey(); } } private static void Main() { MethodInfo method = typeof(Tree).GetMethod( "ColectSomeHoney", BindingFlags.Public | BindingFlags.Instance ); }
  • 33. Reflection in compile time private static void Main() { var method = GetMethod<Tree>(x => x.ColectSomeHoney()); } public static MethodInfo GetMethod<T>(Expression<Action<T>> e) { return ((MethodCallExpression) e.Body) .Method; }
  • 34. Reflection in compile time private static void Main() { var method = GetMethod<Tree>(x => x.CollectSomeHoney()); } public static MethodInfo GetMethod<T>(Expression<Action<T>> e) { return ((MethodCallExpression) e.Body) .Method; }
  • 35. IQueryable interface IQueryable<T> : IEnumerable<T> , IQueryable { Type ElementType { get; } Expression Expression { get; } IQueryProvider Provider { get; } } interface IQueryProvider { IQueryable CreateQuery(Expression e) ; IQueryable<T> CreateQuery<T> (Expression e); object Execute (Expression expression); object Execute (Expression expression); }
  • 37.
  • 38. Expressions в C# — impress yourself! http://habrahabr.ru/blogs/net/83169/
  • 39. LINQ: Building an IQueryable provider series http://blogs.msdn.com/b/mattwar/archive/2008/11/18/linq-links.aspx
  • 40. Винни-Пух и Все-Все-все ISBN: 978-5-17-064151-2