Lambda expressions how much state | conceptbmのブログ

conceptbmのブログ

ブログの説明を入力します。

Our progressive approach to analysis of what Lambda Lambda expressions happy expressions (a) - on a story behind it. Know it and trust as well as the difference between the conventional method, and by comparison of the performance test between them, then we understand the IL code Lambda expressions, and describes how to implement .NET using Lambda expressions in JavaScript popular Some modes. Today, we then look at Lambda expressions 2015 Nike KD 7 Kids Basketball Shoes Sport Turq Charcoal Atomic Green Outlet in .NET What fresh gameplay. Fun polymorphic Lambda Lambda expressions how much state? We use abstract classes and virtual methods, why Lambda use this stuff? Let us look at the following code: class MyBaseClass {public Action SomeAction {get; protected set;} public MyBaseClass () {SomeAction = () = \u0026 gt; {// Do something};}!} Class MyInheritedClass: MyBaseClass {public MyInheritedClass () {SomeAction = () = \u0026 gt;! {// Do something different};}} Our class is not an abstract base class, there is no virtual methods, but the property is exposed by way of commission, and then again in the subclass for us The SomeAction given a new expression. This is Mens Nike Air Max 2011 Womens Blue Free 3.0 V2 Shoes White Black Red our multi-state procedure, of course, the parent class has protected SomeAction a set Air Max 2011 Womens Grey Green Black level of protection, otherwise it will be outside with easily modified. But that's not perfect, after the parent class SomeAction be overridden in a subclass, we can not fully access it, you want to know the real situation is that we can access the parent class base of the original method. The next step is to realize that the Air Max 2011 Womens Blue Black class MyBaseClass {public Action SomeAction {get; private set;} Stack \u0026 lt; Action \u0026 gt; previousActions; protected void AddSomeAction (Action newMethod) {previousActions.Push (SomeAction); SomeAction = newMethod;} protected void RemoveSomeAction () {if (previousActions.Count == 0) return; SomeAction = previousActions.Pop ();} public MyBaseClass () {previousActions = new Stack \u0026 lt; Action \u0026 gt; (); SomeAction = () Air Max 2011 Navy Blue Black = \u0026 gt;! {// Do something} ;}} The above code, we achieved simultaneously by AddSomeAction coverage, the original method of preservation in previousActions. So that we can keep both exist. We all know that is a static method subclasses can not override the parent class, but suppose we want to achieve coverage of a static method it? void Main () {var mother = HotDaughter.Activator () Message;. // mother = \u0026 quot; I am the mother \u0026 quot; var create = new HotDaughter 2015 Nike Free 5.0 ();. var daughter = HotDaughter.Activator () Message; // daughter = \u0026 quot; I am the daughter \u0026 quot;} class CoolMother {public static Func \u0026 lt; CoolMother \u0026 gt; Activator {get; protected set;} // We are only doing Nike Hyperdunk 2013 this to avoid NULL references static CoolMother () {Activator = () = \u0026 gt;! new CoolMother ();} public CoolMother () {// Message of every mother Message = \u0026 quot; I am the mother \u0026 quot ;;} public string Message {get; protected set;}} class HotDaughter: Mens Nike Free 3.0 V2 Shoes White Black Red CoolMother {public HotDaughter () {// Once this constructor has been \u0026 quot; touched \u0026 quot; we set the Activator ... Activator = () = \u0026 gt; new HotDaughter (); // Message of every daughter Message = \u0026 quot; I am the daughter \u0026 quot ;;}} Here is the use of the The Lambda expressions as property, it can always re-assigned characteristics. Of course, this is just a simple example, a real project does not suggest that you do so. In fact, this pattern dictionary method us on a return method has been talked about, Nike Air Max 2015 Women but there is no such a name only, even if it is a summary of it. The story is this, you are not often written to switch-case statement is Air Jordan Outlet not enough time to feel elegant? But what you do not want the entire factory model or strategy mode, then how to make your code looks a little advanced it? public Action GetFinalizer (string input) {switch {case \u0026 quot; random \u0026 quot ;: return () = \u0026 gt; {/ Nike Air Max 2015 Men * ... * /}; case \u0026 quot; dynamic \u0026 quot ;: return () = \u0026 gt; {/ * ... * /}; default: return () = \u0026 gt; {/ * ... * /};}} // ------------------- turned after - --------------------- Dictionary \u0026 lt; string, Action \u0026 gt; finalizers; public void BuildFinalizers () {finalizers = new Dictionary \u0026 lt; string, Action \u0026 gt; (); finalizers.Add (\u0026 quot; random \u0026 quot ;, () = \u0026 gt; {/ * ... * /}); finalizers.Add (\u0026 quot; dynamic \u0026 quot ;, () = \u0026 gt; {/ * ... * /});} public Action GetFinalizer (string input) {if (finalizers.ContainsKey (input)) return finalizers [input]; return () = \u0026 gt; {/ * ... * /};} is not so little seems to look the same, taste ʱ?? But one would have to put all the methods that BuildFinalizers inside this Nike Air Max 95 organization method it is difficult to accept, to learn the way we plug-in development, let it go all the way we need. static Dictionary \u0026 lt; string, Action \u0026 gt; finalizers; // static constructor by calling the method public static void BuildFinalizers () {finalizers = new Dictionary \u0026 lt; string, Action \u0026 gt; (); // get all the types of the current running assembly var types = Assembly.GetExecutingAssembly () GetTypes ();. foreach (var type in types) {// Check type, we can define in advance interface or abstract class if (type.IsSubclassOf (typeof (MyMotherClass))) {// get The default no-argument constructor var m = type.GetConstructor (Type.EmptyTypes); // call the default no-argument constructor if (m = null!) {var instance = m.Invoke (null) as MyMotherClass; var name = type.Name.Remove (\u0026 quot; Mother \u0026 quot;); var method = instance.MyMethod; finalizers.Add (name, method);}}}} public Action GetFinalizer (string input) {if (finalizers.ContainsKey (input)) return finalizers Nike Air Max [input]; return () = \u0026 gt; {/ * ... * /};} If you want to achieve the plug-oriented, we not only want to be able to set the process of this program under the load, but also can run at any time even when to load outside, 2015 Nike KD 7 Kids Basketball Shoes Sport Turq Charcoal Atomic Green Outlet please continue to read: internal static void BuildInitialFinalizers () {finalizers = new Dictionary \u0026 lt; string, Action \u0026 gt; (); LoadPlugin (Assembly.GetExecutingAssembly ());} public static void LoadPlugin (Assembly assembly) {var types = assembly.GetTypes (); foreach (var type in types) {if (type.IsSubclassOf (typeof (MyMotherClass))) {var m = type.GetConstructor (Type.EmptyTypes); if (! m = null) {var instance = m.Invoke (null) as MyMotherClass; var name = type.Name.Remove (\u0026 quot; Mother \u0026 quot;); var method = instance.MyMethod; finalizers.Add (name, method);}}}} Now, we can In this way, giving it the specified assembly to load what we need. The last to leave you a question, we can write a recursive expression it? The following method if an expression how to write? int factorial (int n) {if (n == 0) return 1; else return n * factorial (n - 1);} The story behind the- Happy Lambda expressions (II)