Assembly.GetCallingAssembly 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
Assembly 현재 실행 중인 메서드를 호출한 메서드를 반환합니다.
public:
static System::Reflection::Assembly ^ GetCallingAssembly();
public static System.Reflection.Assembly GetCallingAssembly();
static member GetCallingAssembly : unit -> System.Reflection.Assembly
Public Shared Function GetCallingAssembly () As Assembly
반품
Assembly 현재 실행 중인 메서드를 호출한 메서드의 개체입니다.
예제
다음 예제에서는 현재 메서드의 호출 어셈블리를 가져옵니다.
// Assembly FirstAssembly
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
namespace FirstAssembly
{
public class InFirstAssembly
{
public static void Main()
{
FirstMethod();
SecondAssembly.InSecondAssembly.OtherMethod();
}
[MethodImpl(MethodImplOptions.NoInlining)]
public static void FirstMethod()
{
Console.WriteLine("FirstMethod called from: " + Assembly.GetCallingAssembly().FullName);
}
}
}
// Assembly SecondAssembly
namespace SecondAssembly
{
class InSecondAssembly
{
[MethodImpl(MethodImplOptions.NoInlining)]
public static void OtherMethod()
{
Console.WriteLine("OtherMethod executing assembly: " + Assembly.GetExecutingAssembly().FullName);
Console.WriteLine("OtherMethod called from: " + Assembly.GetCallingAssembly().FullName);
}
}
}
// The example produces output like the following:
// "FirstMethod called from: FirstAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
// "OtherMethod executing assembly: SecondAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
// "OtherMethod called from: FirstAssembly, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null"
Imports System.Reflection
Module Example
Public Sub Main()
' Instantiate a target object.
Dim int1 As Integer
' Set the Type instance to the target class type.
Dim type1 As Type =int1.GetType()
' Instantiate an Assembly class to the assembly housing the Integer type.
Dim sampleAssembly = Assembly.GetAssembly(int1.GetType())
' Display the name of the assembly that is calling the method.
Console.WriteLine(("GetCallingAssembly = " + Assembly.GetCallingAssembly().FullName))
End Sub
End Module
' The example displays output like the following:
' GetCallingAssembly = Example, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
설명
메서드를 호출 GetCallingAssembly 하는 메서드가 JIT(Just-In-Time) 컴파일러에 의해 인라인으로 확장되거나 호출자가 인라인으로 확장되는 경우 반환 GetCallingAssembly 되는 어셈블리가 예기치 않게 다를 수 있습니다. 예를 들어 다음 메서드 및 어셈블리를 고려합니다.
어셈블리
A1호출GetCallingAssembly의 메서드M1입니다.어셈블리
A2호출M1의 메서드M2입니다.어셈블리
A3호출M2의 메서드M3입니다.
인라인이 없으면 M1 .를 GetCallingAssembly 반환합니다 A2.
M1 인라인 처리되면 .를 GetCallingAssembly 반환합니다A3. 마찬가지로 인라인되지 않은 경우 M2 .를 GetCallingAssembly 반환합니다 A2.
M2 인라인 처리되면 .를 GetCallingAssembly 반환합니다A3.
이 효과는 테일 호출로 실행되거나 테일 호출M2M3로 실행되는 경우에도 M2 발생 M1 합니다. JIT 컴파일러가 플래그를 사용하여 특성을 MethodImplOptions.NoInlining 적용하여 MethodImplAttribute 호출GetCallingAssembly하는 메서드를 인라인하는 것을 방지할 수 있지만 비상 호출을 방지하기 위한 유사한 메커니즘은 없습니다.