English 中文(简体)
如何(如果有可能)提及产生另一类案件的类别
原标题:How do i get (is it possible to) a reference to the class that creates an instance of another class

A. Od的局面...... 我需要创立一个需要打电话的班级成员的新例子。 但是,我可以通过施工人提及电离层。

解决办法一如:

Public Class ChildClass
    Public Sub New(args)
        _MyMember = GetMemberFromCallingClass()
        ...
        ...
    End Sub
End Class

我想这样做,而不必手工地从打电话的那类物品或变数转至新的儿童地图集。

这样做是可能的,如果是的话,那么我应想把这一部分列入我的法典。

问题回答

你们如以下法典那样做,以获得打电话的类别:

Dim trace As New System.Diagnostics.StackTrace()
System.Diagnostics.Debug.WriteLine(trace.GetFrame(1).GetMethod().ReflectedType.Name)

然后,你可以打电话到<条码>GetMethods,或找成员或类似反映的类型,以摆脱你想要的实际方法。

不过,我要指出,“反饥饿计划”将永远回到基类,因此,如果你的方法是从一个儿童类别上调来,那么这项工作可能不会适当进行。

如果成员表示,你想要把财产或方法称作打电话类别的实际例子,那么你就无法这样做。 最好的办法是通过<条形码>StackTrace抽取电话类别的类型信息,但你无法提取实际证据。 如果你想要在另一类别中制定守则,让某类人员进入另一类人员,那么你就必须通过这一提法。





相关问题
Is Shared ReadOnly lazyloaded?

I was wondering when I write Shared ReadOnly Variable As DataType = New DataType() Or alternatively Shared ReadOnly Variable As New DataType() Is it lazy loaded or as the instance initializes? ...

Entertaining a baby with VB.NET

I would like to write a little application in VB.NET that will detect a baby s cry. How would I get started with such an application?

Choose Enter Rather than Pressing Ok button

I have many fields in the page and the last field is a dropdown with list of values. When I select an item in a dropdown and press Enter, it doesn t do the "Ok". Instead I have to manually click on Ok ...

ALT Key Shortcuts Hidden

I am using VS2008 and creating forms. By default, the underscore of the character in a textbox when using an ampersand is not shown when I run the application. ex. "&Goto Here" is not ...

Set Select command in code

On button Click I want to Set the Select command of a Gridview. I do this and then databind the grid but it doesn t work. What am i doing wrong? protected void bttnView_Click(object sender, ...

Hover tooltip on specific words in rich text box?

I m trying to create something like a tooltip suddenly hoovering over the mouse pointer when specific words in the richt text box is hovered over. How can this be done?

热门标签