Yet another blog about WPF, Surface, SL, MVVM, NUI.... - .NET - CommentsIn 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 !2024-02-26T15:40:43+01:00Jonathan ANTOINEurn:md5:627146f22bec1346990949372a159bfaDotclear[UPDATED] How to call the method from the base of the base of the current class ? (base.base.MyMethod) - Jonathan ANTOINEurn:md5:453c0832f348b8ff12dc912038e3a4322011-05-13T10:25:44+02:002011-05-13T10:27:26+02:00Jonathan 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> :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 Levesqueurn:md5:305c99d1c08a3d64b04642e5989c05272011-05-13T00:31:53+02:002011-05-13T10:27:49+02:00Thomas 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.comurn:md5:761147145e4258d01f6fd2d6605c32e12011-05-12T00:00:34+02:002011-05-12T00:00:34+02:00DotNetKicks.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) - DotNetShoutouturn:md5:2f9a841379c0f7838a8e765a2175e57e2011-05-12T00:00:22+02:002011-05-12T00:00:22+02:00DotNetShoutout<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 ! - Christopheurn:md5:1fb1a0a5ef615349502eedff0f8d48952010-04-26T15:20:59+02:002010-04-28T00:24:57+02:00Christophe<p>EmitMapper seems even better than AutoMapper ...<br />
<a href="http://emitmapper.codeplex.com/wikipage?title=Benchmark%3a%20EmitMapper%20vs%20Handwritten%20code%20vs%20AutoMapper&referringTitle=Home" title="http://emitmapper.codeplex.com/wikipage?title=Benchmark%3a%20EmitMapper%20vs%20Handwritten%20code%20vs%20AutoMapper&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 ! - DotNetShoutouturn:md5:b6832fe907cf7dd44f6bd89163f7e4562010-04-08T23:38:17+02:002010-04-08T23:38:17+02:00DotNetShoutout<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.comurn:md5:b8836db6d0d945697f5ab1bce414574a2010-04-08T23:36:10+02:002010-04-08T23:36:10+02:00DotNetKicks.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.comurn:md5:66fce9c2b7ac0d55d1c185c8d3a50aab2010-03-05T01:43:50+01:002010-03-05T02:43:50+01:00DotNetKicks.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 - DotNetShoutouturn:md5:56543605f7dd69f838cb5789ee269e9d2010-03-05T01:43:04+01:002010-03-05T02:43:04+01:00DotNetShoutout<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.comurn:md5:632d998516d6c203d84fd91c6f3505cd2010-02-25T16:06:42+01:002010-02-25T17:06:42+01:00DotNetKicks.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 ! - DotNetShoutouturn:md5:4a48878bf7f2c4b00d5f748c7c1ac08a2010-02-25T16:05:26+01:002010-02-25T17:05:26+01:00DotNetShoutout<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>