Click here to Skip to main content
15,893,190 members
Home / Discussions / C#
   

C#

 
GeneralRe: Resolution independent forms Pin
Heath Stewart4-Aug-04 6:07
protectorHeath Stewart4-Aug-04 6:07 
Generali want to open new form Pin
shdelpiero3-Aug-04 21:14
shdelpiero3-Aug-04 21:14 
GeneralRe: i want to open new form Pin
sreejith ss nair3-Aug-04 21:41
sreejith ss nair3-Aug-04 21:41 
GeneralRe: i want to open new form Pin
Jay Shankar3-Aug-04 22:08
Jay Shankar3-Aug-04 22:08 
GeneralRe: i want to open new form Pin
exhaulted3-Aug-04 22:36
exhaulted3-Aug-04 22:36 
QuestionReflection: Can base class know about derived class? Pin
PJules3-Aug-04 21:11
PJules3-Aug-04 21:11 
AnswerRe: Reflection: Can base class know about derived class? Pin
Syed Abdul Khader4-Aug-04 0:10
Syed Abdul Khader4-Aug-04 0:10 
AnswerRe: Reflection: Can base class know about derived class? Pin
leppie4-Aug-04 1:16
leppie4-Aug-04 1:16 
PJules wrote:
Is it possible for a base class to determine with reflection the type of the derived class that called the base constructor?

Ok had to read that a few times. I think I have, quite tricky! I think this will explain what you need:

#region Using directives

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Reflection;

#endregion

namespace ConsoleApplication1
{
  class Program
  {
    protected Program()
    {
      Console.WriteLine("{0:X8}\t:default", GetHashCode());
      foreach (StackFrame sf in new StackTrace().GetFrames())
      {
        MethodBase mi = sf.GetMethod();
        Console.WriteLine("{0}::{1}", mi.DeclaringType, mi);
      }
    }

    protected Program(string overload)
    {
      Console.WriteLine("{0:X8}\t:overload", GetHashCode());
      foreach (StackFrame sf in new StackTrace().GetFrames())
      {
        MethodBase mi = sf.GetMethod();
        Console.WriteLine("{0}::{1}", mi.DeclaringType, mi);
      }
    }

    protected Program(int someother) : this(someother.ToString())
    {
      Console.WriteLine("{0:X8}\t:overload -> someother", GetHashCode());
      foreach (StackFrame sf in new StackTrace().GetFrames())
      {
        MethodBase mi = sf.GetMethod();
        Console.WriteLine("{0}::{1}", mi.DeclaringType, mi);
      }
    }

    static void Main(string[] args)
    {
      Derived a = new Derived();
      Derived b = new Derived("foo");
      Derived c = new Derived(100);
      Derived d = new Derived(true);

      Console.ReadLine();
    }
  }

  class Derived : Program
  {
    public Derived() : base("dummy") { }
    public Derived(string overload) : base(100) { }
    public Derived(int crossref) : base() { }
    public Derived(bool v) : this() { }

  }
}


Output:

03B95145	:overload
ConsoleApplication1.Program::Void .ctor(System.String)
ConsoleApplication1.Derived::Void .ctor()
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
00AE0419	:overload
ConsoleApplication1.Program::Void .ctor(System.String)
ConsoleApplication1.Program::Void .ctor(Int32)
ConsoleApplication1.Derived::Void .ctor(System.String)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
00AE0419	:overload -> someother
ConsoleApplication1.Program::Void .ctor(Int32)
ConsoleApplication1.Derived::Void .ctor(System.String)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
03DEA808	:default
ConsoleApplication1.Program::Void .ctor()
ConsoleApplication1.Derived::Void .ctor(Int32)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()
02A8E964	:overload
ConsoleApplication1.Program::Void .ctor(System.String)
ConsoleApplication1.Derived::Void .ctor()
ConsoleApplication1.Derived::Void .ctor(Boolean)
ConsoleApplication1.Program::Void Main(System.String[])
System.AppDomain::Int32 nExecuteAssembly(System.Reflection.Assembly, System.String[])
System.AppDomain::Int32 ExecuteAssembly(System.String, System.Security.Policy.Evidence, System.String[])
VSHostUtil.HostProc::Void RunUsersAssembly()
System.Threading._Thread::Void ThreadStart_Context(System.Object)
System.Threading.ExecutionContext::Void Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, System.Threading.StackCrawlMark ByRef)
System.Threading._Thread::Void ThreadStart()


Got it? Good Smile | :)

top secret xacc-ide 0.0.1
GeneralRe: Reflection: Can base class know about derived class? Pin
PJules4-Aug-04 8:51
PJules4-Aug-04 8:51 
GeneralRe: Reflection: Can base class know about derived class? Pin
leppie4-Aug-04 20:45
leppie4-Aug-04 20:45 
GeneralHailing those adept at DirectSound using C# .NET Pin
NietzscheDisciple3-Aug-04 20:45
NietzscheDisciple3-Aug-04 20:45 
GeneralRe: Hailing those adept at DirectSound using C# .NET Pin
4-Aug-04 2:17
suss4-Aug-04 2:17 
GeneralRe: Hailing those adept at DirectSound using C# .NET Pin
NietzscheDisciple4-Aug-04 6:19
NietzscheDisciple4-Aug-04 6:19 
QuestionHow to get image name of a process exactly ? Pin
zuken213-Aug-04 20:26
zuken213-Aug-04 20:26 
Generallocal VCS in .net IDE Pin
samithas3-Aug-04 20:04
samithas3-Aug-04 20:04 
Generalstruct and pointer question in c# Pin
Rulala3-Aug-04 19:54
Rulala3-Aug-04 19:54 
GeneralRe: struct and pointer question in c# Pin
Bret Mulvey9-Aug-04 17:03
Bret Mulvey9-Aug-04 17:03 
GeneralRe: struct and pointer question in c# Pin
Rulala9-Aug-04 17:44
Rulala9-Aug-04 17:44 
GeneralMultithreading in Windows UI Pin
naths3-Aug-04 19:28
naths3-Aug-04 19:28 
GeneralRe: Multithreading in Windows UI Pin
Stefan Troschuetz4-Aug-04 9:04
Stefan Troschuetz4-Aug-04 9:04 
GeneralEnable System.Diagnostics.Trace.WriteLine Pin
Amir Zicherman3-Aug-04 19:13
Amir Zicherman3-Aug-04 19:13 
GeneralRe: Enable System.Diagnostics.Trace.WriteLine Pin
KevinMac3-Aug-04 19:35
KevinMac3-Aug-04 19:35 
GeneralRe: Enable System.Diagnostics.Trace.WriteLine Pin
Amir Zicherman3-Aug-04 20:37
Amir Zicherman3-Aug-04 20:37 
GeneralStaticlly Link Assemblys Pin
MKlucher3-Aug-04 19:11
MKlucher3-Aug-04 19:11 
GeneralRe: Staticlly Link Assemblys Pin
Colin Angus Mackay3-Aug-04 20:05
Colin Angus Mackay3-Aug-04 20:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.