InternalsVisibleToAttribute Sınıf

Tanım

Normalde yalnızca geçerli derleme içinde görünen türlerin belirtilen bir derlemeye görünür olduğunu belirtir.

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
Devralma
InternalsVisibleToAttribute
Öznitelikler

Örnekler

İmzalı derlemeler

Aşağıdaki örnek, imzalı derlemede adlı AppendDirectorySeparator bir yöntemi başka bir internal imzalı derlemeye görünür hale getirmek için özniteliğini kullanırInternalsVisibleToAttribute. İç AppendDirectorySeparator yöntem içeren bir FileUtilities sınıf tanımlar. InternalsVisibleToAttribute özniteliği, sınıfını içeren derlemeye FileUtilities uygulanır. özniteliği adlı Friend1 bir derlemenin bu iç üyeye erişmesine izin verir.

//
// 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

Aşağıdaki örnek adlı Friend1Example.Main tanımlayıcı adlandırılmış bir derlemede derlenmişse, yöntemi Friend1 derlemenin FileUtilities.AppendDirectorySeparator içinde Assembly1 olmasına rağmen içindeki yöntemi başarıyla çağırabilir. Komut satırından C# dilinde derleniyorsanız, derleyici dış başvurulara bağlandığında arkadaş derlemesinin adının kullanılabilir olduğundan emin olmak için /out derleyici anahtarını kullanmanız gerektiğini unutmayın.

//
// 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\

İmzasız derlemeler

Aşağıdaki örnek, imzalanmamış bir derlemenin üyesini başka bir internal imzasız derlemeye görünür hale getirmek için özniteliğini kullanırInternalsVisibleToAttribute. özniteliği, adlı bir derlemedeki yönteminin internalStringLib.IsFirstLetterUpperCase adlı UtilityLibFriend2derlemedeki koda görünür olmasını sağlar. UtilityLib.dll kaynak kodu aşağıdadır:

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

Aşağıdaki örnek, derleme için Friend2 kaynak kodu sağlar. Komut satırından C# dilinde derleniyorsanız, derleyici dış başvurulara bağlandığında arkadaş derlemesinin adının kullanılabilir olduğundan emin olmak için /out derleyici anahtarını kullanmanız gerektiğini unutmayın.

#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

Açıklamalar

Bu API hakkında daha fazla bilgi için bkz . InternalsVisibleToAttribute için ek API açıklamaları.

Oluşturucular

InternalsVisibleToAttribute(String)

Belirtilen arkadaş derlemesinin InternalsVisibleToAttribute adıyla sınıfının yeni bir örneğini başlatır.

Özellikler

AllInternalsVisible

Bu özellik uygulanmadı.

AssemblyName

Anahtar sözcüğüyle işaretlenen tüm türlerin ve tür üyelerinin görünür hale getirileceği arkadaş derlemesinin internal adını alır.

TypeId

Türetilmiş bir sınıfta uygulandığında, bu Attributeiçin benzersiz bir tanımlayıcı alır.

(Devralındığı yer: Attribute)

Yöntemler

Equals(Object)

Bu örneğin belirtilen bir nesneye eşit olup olmadığını gösteren bir değeri döndürür.

(Devralındığı yer: Attribute)
GetHashCode()

Bu örneğe ilişkin karma kodu döndürür.

(Devralındığı yer: Attribute)
GetType()

Type Geçerli örneğini alır.

(Devralındığı yer: Object)
IsDefaultAttribute()

Türetilmiş bir sınıfta geçersiz kılındığında, bu örneğin değerinin türetilmiş sınıf için varsayılan değer olup olmadığını gösterir.

(Devralındığı yer: Attribute)
Match(Object)

Türetilmiş bir sınıfta geçersiz kılındığında, bu örneğin belirtilen bir nesneye eşit olup olmadığını gösteren bir değer döndürür.

(Devralındığı yer: Attribute)
MemberwiseClone()

Geçerli Objectöğesinin sığ bir kopyasını oluşturur.

(Devralındığı yer: Object)
ToString()

Geçerli nesneyi temsil eden dizeyi döndürür.

(Devralındığı yer: Object)

Belirtik Arabirim Kullanımları

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

Bir ad kümesini karşılık gelen bir dağıtma tanımlayıcısı kümesine eşler.

(Devralındığı yer: Attribute)
_Attribute.GetTypeInfo(UInt32, UInt32, IntPtr)

Bir arabirimin tür bilgilerini almak için kullanılabilecek bir nesnenin tür bilgilerini alır.

(Devralındığı yer: Attribute)
_Attribute.GetTypeInfoCount(UInt32)

Bir nesnenin sağladığı tür bilgisi arabirimlerinin sayısını alır (0 ya da 1).

(Devralındığı yer: Attribute)
_Attribute.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr)

Bir nesne tarafından sunulan özelliklere ve yöntemlere erişim sağlar.

(Devralındığı yer: Attribute)

Şunlara uygulanır