SlideShare ist ein Scribd-Unternehmen logo
1 von 41
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
Expressions и все-все-все in C

Weitere ähnliche Inhalte

Was ist angesagt?

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 RavenDBtdc-globalcode
 
Closure, Higher-order function in Swift
Closure, Higher-order function in SwiftClosure, Higher-order function in Swift
Closure, Higher-order function in SwiftSeongGyu Jo
 
Collection v3
Collection v3Collection v3
Collection v3Sunil OS
 
Patterns for slick database applications
Patterns for slick database applicationsPatterns for slick database applications
Patterns for slick database applicationsSkills Matter
 
Swift 함수 커링 사용하기
Swift 함수 커링 사용하기Swift 함수 커링 사용하기
Swift 함수 커링 사용하기진성 오
 
Collections Framework
Collections FrameworkCollections Framework
Collections FrameworkSunil OS
 
Introduction to Python
Introduction to PythonIntroduction to Python
Introduction to PythonUC 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 SlickHermann Hueck
 
Using Scala Slick at FortyTwo
Using Scala Slick at FortyTwoUsing Scala Slick at FortyTwo
Using Scala Slick at FortyTwoEishay 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# 7Paulo 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) Datagreenwop
 
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 italyFabio Collini
 
Python3 cheatsheet
Python3 cheatsheetPython3 cheatsheet
Python3 cheatsheetGil Cohen
 
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, objectsHusain Dalal
 

Was ist angesagt? (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
 

Ähnlich wie Expressions и все-все-все in C

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 IntroductionDmitry 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 SwiftJason Larsen
 
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 ApplicationJoni
 
Les nouveautés de C# 6
Les nouveautés de C# 6Les nouveautés de C# 6
Les nouveautés de C# 6Microsoft
 
Ast transformations
Ast transformationsAst transformations
Ast transformationsHamletDRC
 
C# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewC# 6.0 - April 2014 preview
C# 6.0 - April 2014 previewPaulo Morgado
 
Pragmatic metaprogramming
Pragmatic metaprogrammingPragmatic metaprogramming
Pragmatic metaprogrammingMå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 6Dmitry Soshnikov
 
Generics and Inference
Generics and InferenceGenerics and Inference
Generics and InferenceRichard Fox
 
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
 

Ähnlich wie Expressions и все-все-все in C (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."
 

Mehr von 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 LoparevCiklum 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 LiashenkoCiklum Ukraine
 
Alex Pazhyn: Google_Material_Design
Alex Pazhyn: Google_Material_DesignAlex Pazhyn: Google_Material_Design
Alex Pazhyn: Google_Material_DesignCiklum 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 developersCiklum Ukraine
 
Your 1st Apple watch Application
Your 1st Apple watch ApplicationYour 1st Apple watch Application
Your 1st Apple watch ApplicationCiklum Ukraine
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentCiklum 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 2015Ciklum 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 layoutCiklum Ukraine
 
Introduction to auto layout
Introduction to auto layoutIntroduction to auto layout
Introduction to auto layoutCiklum Ukraine
 
Unit Testing: Special Cases
Unit Testing: Special CasesUnit Testing: Special Cases
Unit Testing: Special CasesCiklum Ukraine
 
Model-View-Controller: Tips&Tricks
Model-View-Controller: Tips&TricksModel-View-Controller: Tips&Tricks
Model-View-Controller: Tips&TricksCiklum 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
 

Mehr von 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"
 

Kürzlich hochgeladen

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
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 DevelopmentsTrustArc
 
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 Scriptwesley chun
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
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 Processorsdebabhi2
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
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...Drew Madelung
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024The Digital Insurer
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilV3cube
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfEnterprise Knowledge
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 

Kürzlich hochgeladen (20)

04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
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
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Developing An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of BrazilDeveloping An App To Navigate The Roads of Brazil
Developing An App To Navigate The Roads of Brazil
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 

Expressions и все-все-все in C

  • 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