InternalsVisibleToAttribute 클래스

정의

일반적으로는 현재 어셈블리 내에서만 볼 수 있는 형식을 지정된 어셈블리에서 볼 수 있도록 지정합니다.

public ref class InternalsVisibleToAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true, Inherited=false)]
public sealed class InternalsVisibleToAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Assembly, AllowMultiple=true, Inherited=false)>]
type InternalsVisibleToAttribute = class
    inherit Attribute
Public NotInheritable Class InternalsVisibleToAttribute
Inherits Attribute
상속
InternalsVisibleToAttribute
특성

예제

서명된 어셈블리

다음 예제에서는 특성을 사용하여 InternalsVisibleToAttribute 서명된 internal 어셈블리의 라는 AppendDirectorySeparator 메서드를 다른 서명된 어셈블리에 표시합니다. 내부 AppendDirectorySeparator 메서드를 FileUtilities 포함하는 클래스를 정의합니다. 특성은 InternalsVisibleToAttribute 클래스를 포함하는 어셈블리에 FileUtilities 적용됩니다. 특성을 사용하면 라는 Friend1 어셈블리가 이 내부 멤버에 액세스할 수 있습니다.

//
// The source code should be saved in a file named Example1.cs. It 
// can be compiled at the command line as follows:
//
//    csc /t:library /keyfile:<snkfilename> Assembly1.cs
//
// The public key of the Friend1 file should be changed to the full
// public key stored in your strong-named key file.
//
using System;
using System.IO;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Friend1, PublicKey=002400000480000094" + 
                              "0000000602000000240000525341310004000" +
                              "001000100bf8c25fcd44838d87e245ab35bf7" +
                              "3ba2615707feea295709559b3de903fb95a93" +
                              "3d2729967c3184a97d7b84c7547cd87e435b5" +
                              "6bdf8621bcb62b59c00c88bd83aa62c4fcdd4" +
                              "712da72eec2533dc00f8529c3a0bbb4103282" +
                              "f0d894d5f34e9f0103c473dce9f4b457a5dee" +
                              "fd8f920d8681ed6dfcb0a81e96bd9b176525a" +
                              "26e0b3")]

public class FileUtilities
{
   internal static string AppendDirectorySeparator(string dir)
   {
      if (! dir.Trim().EndsWith(Path.DirectorySeparatorChar.ToString()))
         return dir.Trim() + Path.DirectorySeparatorChar;
      else
         return dir;
   }
}
'
' The source code should be saved in a file named Example1.cs. It 
' can be compiled at the command line as follows:
'
'    vbc Assembly1.vb /t:library /keyfile:<snkfilename> 
'
' The public key of the Friend1 file should be changed to the full
' public key stored in your strong-named key file.
'
Imports System.IO
Imports System.Runtime.CompilerServices

<Assembly:InternalsVisibleTo("Friend1, PublicKey=002400000480000094" + _
                             "0000000602000000240000525341310004000" + _
                             "001000100bf8c25fcd44838d87e245ab35bf7" + _
                             "3ba2615707feea295709559b3de903fb95a93" + _
                             "3d2729967c3184a97d7b84c7547cd87e435b5" + _
                             "6bdf8621bcb62b59c00c88bd83aa62c4fcdd4" + _
                             "712da72eec2533dc00f8529c3a0bbb4103282" + _
                             "f0d894d5f34e9f0103c473dce9f4b457a5dee" + _
                             "fd8f920d8681ed6dfcb0a81e96bd9b176525a" + _
                             "26e0b3")>

Public Class FileUtilities
   Friend Shared Function AppendDirectorySeparator(dir As String) As String
      If Not dir.Trim().EndsWith(Path.DirectorySeparatorChar) Then
         Return dir.Trim() + Path.DirectorySeparatorChar
      Else
         Return dir
      End If   
   End Function
End Class

다음 예제가 라는 Friend1Example.Main 강력한 이름의 어셈블리로 컴파일되는 경우 의 메서드 Friend1 는 메서드를 성공적으로 호출 FileUtilities.AppendDirectorySeparator 할 수 있지만 메서드는 어셈블리 내부 Assembly1 입니다. 명령줄에서 C#으로 컴파일하는 경우 /out 컴파일러 스위치를 사용하여 컴파일러가 외부 참조에 바인딩할 때 friend 어셈블리의 이름을 사용할 수 있도록 해야 합니다.

//
// The assembly that exposes its internal types to this assembly should be
// named Assembly1.dll.
//
// The public key of this assembly should correspond to the public key
// specified in the class constructor of the InternalsVisibleTo attribute in the
// Assembly1 assembly.
//
#using <Assembly1.dll> as_friend

using namespace System;

void main()
{
   String^ dir = L"C:\\Program Files";
   dir = FileUtilities::AppendDirectorySeparator(dir);
   Console::WriteLine(dir);
}
// The example displays the following output:
//       C:\Program Files\
//
// The source code should be saved in a file named Friend1.cs. It 
// can be compiled at the command line as follows:
//
//    csc /r:Assembly1.dll /keyfile:<snkfilename> /out:Friend1.dll Friend1.cs
//
// The public key of the Friend1 assembly should correspond to the public key
// specified in the class constructor of the InternalsVisibleTo attribute in the
// Assembly1 assembly.
//
using System;

public class Example
{
   public static void Main()
   {
      string dir = @"C:\Program Files";
      dir = FileUtilities.AppendDirectorySeparator(dir);
      Console.WriteLine(dir);
   }
}
// The example displays the following output:
//       C:\Program Files\
'
' The source code should be saved in a file named Friend1.vb. It 
' can be compiled at the command line as follows:
'
'    vbc Friend1.vb /r:Assembly1.dll /keyfile:<snkfilename> 
'
' The public key of the Friend1 assembly should correspond to the public key
' specified in the class constructor of the InternalsVisibleTo attribute in the
' Assembly1 assembly.
'
Module Example
   Public Sub Main()
      Dim dir As String = "C:\Program Files"
      dir = FileUtilities.AppendDirectorySeparator(dir)
      Console.WriteLine(dir)
   End Sub
End Module
' The example displays the following output:
'       C:\Program Files\

서명되지 않은 어셈블리

다음 예제에서는 특성을 사용하여 InternalsVisibleToAttributeinternal 서명되지 않은 어셈블리의 멤버를 다른 서명되지 않은 어셈블리에 표시합니다. 특성은 라는 어셈블리의 internalStringLib.IsFirstLetterUpperCase 메서드가 라는 UtilityLibFriend2어셈블리의 코드에 표시되는지 확인합니다. 다음은 UtilityLib.dll 소스 코드입니다.

using System;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleToAttribute("Friend2")]

namespace Utilities.StringUtilities
{
   public class StringLib
   {
      internal static bool IsFirstLetterUpperCase(String s)
      {
         string first = s.Substring(0, 1);
         return first == first.ToUpper();
      }
   }
}

Imports System.Runtime.CompilerServices

<assembly: InternalsVisibleTo("Friend2")>

Namespace Utilities.StringUtilities
   Public Class StringLib
      Friend Shared Function IsFirstLetterUpperCase(s As String) As Boolean
         Dim first As String = s.Substring(0, 1)
         Return first = first.ToUpper()
      End Function
   End Class
End Namespace

다음 예제에서는 어셈블리에 대한 Friend2 소스 코드를 제공합니다. 명령줄에서 C#으로 컴파일하는 경우 /out 컴파일러 스위치를 사용하여 컴파일러가 외부 참조에 바인딩할 때 friend 어셈블리의 이름을 사용할 수 있도록 해야 합니다.

#using <UtilityLib.dll> as_friend

using namespace System;
using namespace Utilities::StringUtilities;

void main()
{
   String^ s = "The Sign of the Four";
   Console::WriteLine(StringLib::IsFirstLetterUpperCase(s));
}
using System;
using Utilities.StringUtilities;

public class Example
{
   public static void Main()
   {
      String s = "The Sign of the Four";
      Console.WriteLine(StringLib.IsFirstLetterUpperCase(s));
   }
}
Imports Utilities.StringUtilities

Module Example
   Public Sub Main()
      Dim s As String = "The Sign of the Four"
      Console.WriteLine(StringLib.IsFirstLetterUpperCase(s))
   End Sub
End Module

설명

이 API에 대한 자세한 내용은 InternalsVisibleToAttribute에 대한 추가 API 설명을 참조하세요.

생성자

InternalsVisibleToAttribute(String)

지정된 friend 어셈블리의 이름을 사용하여 InternalsVisibleToAttribute 클래스의 새 인스턴스를 초기화합니다.

속성

AllInternalsVisible

이 속성이 구현되지 않습니다.

AssemblyName

internal 키워드로 표시된 모든 형식 및 형식 멤버가 표시되도록 지정할 friend 어셈블리의 이름을 가져옵니다.

TypeId

파생 클래스에서 구현된 경우 이 Attribute에 대한 고유 식별자를 가져옵니다.

(다음에서 상속됨 Attribute)

메서드

Equals(Object)

이 인스턴스가 지정된 개체와 같은지를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
GetHashCode()

이 인스턴스의 해시 코드를 반환합니다.

(다음에서 상속됨 Attribute)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
IsDefaultAttribute()

파생 클래스에서 재정의된 경우 이 인스턴스 값이 파생 클래스에 대한 기본값인지 여부를 표시합니다.

(다음에서 상속됨 Attribute)
Match(Object)

파생 클래스에서 재정의된 경우 이 인스턴스가 지정된 개체와 같은지 여부를 나타내는 값을 반환합니다.

(다음에서 상속됨 Attribute)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

명시적 인터페이스 구현

_Attribute.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr)

이름 집합을 해당하는 디스패치 식별자 집합에 매핑합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다.

(다음에서 상속됨 Attribute)
_Attribute.GetTypeInfoCount(UInt32)

개체에서 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1).

(다음에서 상속됨 Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

개체에서 노출하는 메서드와 속성에 대한 액세스를 제공합니다.

(다음에서 상속됨 Attribute)

적용 대상