Yet another blog about WPF, Surface, SL, MVVM, NUI.... - .NET - Comments In this blog we talk about WPF, Natural User Interface(NUI), Microsoft Surface, WIndows 7, Multitouch, Touchless, JavaFX, MVVM, patterns, tips, tricks .... and a lot of other things ! 2021-06-10T22:58:33+02:00 Jonathan ANTOINE urn:md5:627146f22bec1346990949372a159bfa Dotclear [UPDATED] How to call the method from the base of the base of the current class ? (base.base.MyMethod) - Jonathan ANTOINE urn:md5:453c0832f348b8ff12dc912038e3a432 2011-05-13T10:25:44+02:00 2011-05-13T10:27:26+02:00 Jonathan ANTOINE <p>@<a href="http://blog.lexique-du-net.com/index.php?post/2011/05/11/How-to-call-the-method-from-the-base-of-the-base-of-the-current-class-%28base.base.MyMethod%29#c3025" rel="nofollow">Thomas Levesque</a>&nbsp;:Hello Thomas,</p> <p>Thank you for your comment and it works like a charm <img src="themes/default/smilies/wink.png" alt=";-)" class="smiley" /> !</p> <p>Btw, there is still reflection in your solution, the only difference is that we use 'this' as the current instance without recreating one.</p> <p>I will update my post to add your solution <img src="themes/default/smilies/smile.png" alt=":-)" class="smiley" /></p> <p>Thx a lot !</p> [UPDATED] How to call the method from the base of the base of the current class ? (base.base.MyMethod) - Thomas Levesque urn:md5:305c99d1c08a3d64b04642e5989c0527 2011-05-13T00:31:53+02:00 2011-05-13T10:27:49+02:00 Thomas Levesque <p>Interesting...<br /> .<br /> Normally, you should never need to call base.base.SomeMethod, it's usually a sign of a bad design because you're not supposed to be aware of implementation details of the base class. But of course in the case of the TabControl you're not in control of the base classes, so it's different...<br /> .<br /> Anyway, I don't really like this solution... Two main reasons :<br /> - you have to create a dummy instance of the class, which is pretty bad for performance and could have unexpected side effects<br /> - it uses reflection (also bad for performance) on a non documented private field of the Delegate class. The implementation of this class could change in future versions, and this solution wouldn't work any more.<br /> .<br /> What you need to achieve this is a non-virtual call to GrandFather.MyMethod. This can be done by generating code at runtime with DynamicMethod:</p> <pre> class Child : Father { private delegate void MyMethodOpenDelegate(GrandFather instance, object param); private static readonly MyMethodOpenDelegate _grandFather_MyMethod; static Child() { DynamicMethod dm = new DynamicMethod( "grandFather_MyMethod", typeof(void), new Type[] {typeof(GrandFather), typeof(object)}, typeof(Child)); var il = dm.GetILGenerator(); il.Emit(OpCodes.Ldarg_0); il.Emit(OpCodes.Ldarg_1); il.EmitCall(OpCodes.Call, typeof(GrandFather).GetMethod("MyMethod"), null); il.Emit(OpCodes.Ret); _grandFather_MyMethod = (MyMethodOpenDelegate)dm.CreateDelegate( typeof(MyMethodOpenDelegate)); } public override void MyMethod(object param) { _grandFather_MyMethod(this, param); } }</pre> <p>(note the use of OpCodes.Call instead of OpCodes.Callvirt)</p> [ping] [UPDATED] How to call the method from the base of the base of the current class ? (base.base.MyMethod) - DotNetKicks.com urn:md5:761147145e4258d01f6fd2d6605c32e1 2011-05-12T00:00:34+02:00 2011-05-12T00:00:34+02:00 DotNetKicks.com <p><a href="http://www.dotnetkicks.com/csharp/How_to_call_the_method_from_the_base_of_the_base_of_the_current_class">How to call the method from the base of the base of the</a></p> <!-- TB --> <p>You've been kicked (a good thing) - Trackback from DotNetKicks.com...</p> [ping] [UPDATED] How to call the method from the base of the base of the current class ? (base.base.MyMethod) - DotNetShoutout urn:md5:2f9a841379c0f7838a8e765a2175e57e 2011-05-12T00:00:22+02:00 2011-05-12T00:00:22+02:00 DotNetShoutout <p><a href="http://dotnetshoutout.com/How-to-call-the-method-from-the-base-of-the-base-of-the-current-class-basebaseMyMethod">How to call the method from the base of the base of the</a></p> <!-- TB --> <p>Thank you for submitting this cool story - Trackback from DotNetShoutout...</p> Simple properties Mapper by reflection : stop copying manually each property of your objects ! - Christophe urn:md5:1fb1a0a5ef615349502eedff0f8d4895 2010-04-26T15:20:59+02:00 2010-04-28T00:24:57+02:00 Christophe <p>EmitMapper seems even better than AutoMapper ...<br /> <a href="http://emitmapper.codeplex.com/wikipage?title=Benchmark%3a%20EmitMapper%20vs%20Handwritten%20code%20vs%20AutoMapper&amp;referringTitle=Home" title="http://emitmapper.codeplex.com/wikipage?title=Benchmark%3a%20EmitMapper%20vs%20Handwritten%20code%20vs%20AutoMapper&amp;referringTitle=Home" rel="nofollow">http://emitmapper.codeplex.com/wiki...</a></p> [ping] Simple properties Mapper by reflection : stop copying manually each property of your objects ! - DotNetShoutout urn:md5:b6832fe907cf7dd44f6bd89163f7e456 2010-04-08T23:38:17+02:00 2010-04-08T23:38:17+02:00 DotNetShoutout <p><a href="http://dotnetshoutout.com/Simple-properties-Mapper-by-reflection-stop-copying-manually-each-property-of-your-objects-">Simple properties Mapper by reflection : stop copying</a></p> <!-- TB --> <p>Thank you for submitting this cool story - Trackback from DotNetShoutout...</p> [ping] Simple properties Mapper by reflection : stop copying manually each property of your objects ! - DotNetKicks.com urn:md5:b8836db6d0d945697f5ab1bce414574a 2010-04-08T23:36:10+02:00 2010-04-08T23:36:10+02:00 DotNetKicks.com <p><a href="http://www.dotnetkicks.com/tipsandtricks/Simple_properties_Mapper_by_reflection_stop_doing_it_manually">Simple properties Mapper by reflection : stop doing it</a></p> <!-- TB --> <p>You've been kicked (a good thing) - Trackback from DotNetKicks.com...</p> [ping] Sync framework - choose your primary keys type carefully - DotNetKicks.com urn:md5:66fce9c2b7ac0d55d1c185c8d3a50aab 2010-03-05T01:43:50+01:00 2010-03-05T02:43:50+01:00 DotNetKicks.com <p><a href="http://www.dotnetkicks.com/other/Sync_framework_choose_your_primary_keys_type_carefully">Sync framework - choose your primary keys type carefully</a></p> <!-- TB --> <p>You've been kicked (a good thing) - Trackback from DotNetKicks.com...</p> [ping] Sync framework - choose your primary keys type carefully - DotNetShoutout urn:md5:56543605f7dd69f838cb5789ee269e9d 2010-03-05T01:43:04+01:00 2010-03-05T02:43:04+01:00 DotNetShoutout <p><a href="http://dotnetshoutout.com/Microsoft-Sync-Framework-choose-your-primary-keys-type-carefully">Microsoft Sync Framework - choose your primary keys type</a></p> <!-- TB --> <p>Thank you for submitting this cool story - Trackback from DotNetShoutout...</p> [ping] Serialize DependencyObject : it's easy ! - DotNetKicks.com urn:md5:632d998516d6c203d84fd91c6f3505cd 2010-02-25T16:06:42+01:00 2010-02-25T17:06:42+01:00 DotNetKicks.com <p><a href="http://www.dotnetkicks.com/wpf/Serialize_DependencyObject_it_s_easy">Serialize DependencyObject : it's easy !</a></p> <!-- TB --> <p>You've been kicked (a good thing) - Trackback from DotNetKicks.com...</p> [ping] Serialize DependencyObject : it's easy ! - DotNetShoutout urn:md5:4a48878bf7f2c4b00d5f748c7c1ac08a 2010-02-25T16:05:26+01:00 2010-02-25T17:05:26+01:00 DotNetShoutout <p><a href="http://dotnetshoutout.com/Serialize-DependencyObject-its-easy-">Serialize DependencyObject : it's easy !</a></p> <!-- TB --> <p>Thank you for submitting this cool story - Trackback from DotNetShoutout...</p>