LicenseProviderAttribute Класс

Определение

Задает объект LicenseProvider, используемый вместе с классом. Этот класс не наследуется.

public ref class LicenseProviderAttribute sealed : Attribute
[System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)]
public sealed class LicenseProviderAttribute : Attribute
[<System.AttributeUsage(System.AttributeTargets.Class, AllowMultiple=false, Inherited=false)>]
type LicenseProviderAttribute = class
    inherit Attribute
Public NotInheritable Class LicenseProviderAttribute
Inherits Attribute
Наследование
LicenseProviderAttribute
Атрибуты

Примеры

В следующем примере кода используется в LicFileLicenseProvider качестве поставщика лицензий для MyControl.

[LicenseProvider(LicFileLicenseProvider::typeid)]
ref class MyControl: public Control
{
protected:

   // Insert code here.
   ~MyControl()
   {
      /* All components must dispose of the licenses they grant. 
               * Insert code here to dispose of the license. */
   }
};
[LicenseProvider(typeof(LicFileLicenseProvider))]
 public class MyControl : Control {
 
    // Insert code here.
 
    protected override void Dispose(bool disposing) {
       /* All components must dispose of the licenses they grant. 
        * Insert code here to dispose of the license. */
    }
 }
<LicenseProvider(GetType(LicFileLicenseProvider))> _
Public Class MyControl
    Inherits Control
    
    ' Insert code here.
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        ' All components must dispose of the licenses they grant.
        ' Insert code here to dispose of the license.
    End Sub        

End Class

В следующем примере кода создается экземпляр MyControl класса . Затем он получает атрибуты для класса и выводит имя поставщика лицензий, используемого myNewControl.

int main()
{
   // Creates a new component.
   MyControl^ myNewControl = gcnew MyControl;

   // Gets the attributes for the component.
   AttributeCollection^ attributes = TypeDescriptor::GetAttributes( myNewControl );

   /* Prints the name of the license provider by retrieving the LicenseProviderAttribute 
        * from the AttributeCollection. */
   LicenseProviderAttribute^ myAttribute = dynamic_cast<LicenseProviderAttribute^>(attributes[ LicenseProviderAttribute::typeid ]);
   Console::WriteLine( "The license provider for this class is: {0}", myAttribute->LicenseProvider );
   return 0;
}
public static int Main() {
    // Creates a new component.
    MyControl myNewControl = new MyControl();
 
    // Gets the attributes for the component.
    AttributeCollection attributes = TypeDescriptor.GetAttributes(myNewControl);
 
    /* Prints the name of the license provider by retrieving the LicenseProviderAttribute 
     * from the AttributeCollection. */
    LicenseProviderAttribute myAttribute = (LicenseProviderAttribute)attributes[typeof(LicenseProviderAttribute)];
    Console.WriteLine("The license provider for this class is: " + myAttribute.LicenseProvider.ToString());
 
    return 0;
 }
Public Shared Function Main() As Integer
    ' Creates a new component.
    Dim myNewControl As New MyControl()
    
    ' Gets the attributes for the component.
    Dim attributes As AttributeCollection = TypeDescriptor.GetAttributes(myNewControl)
    
    ' Prints the name of the license provider by retrieving the LicenseProviderAttribute 
    ' from the AttributeCollection. 
    Dim myAttribute As LicenseProviderAttribute = _
        CType(attributes(GetType(LicenseProviderAttribute)), LicenseProviderAttribute)
        
    Console.WriteLine(("The license provider for this class is: " & _
        myAttribute.LicenseProvider.ToString()))
    Return 0
End Function

Комментарии

При создании компонента, который требуется лицензировать, необходимо указать , помечая LicenseProvider компонент с помощью LicenseProviderAttribute.

LicenseProvider Используйте свойство для получения Type объекта LicenseProvider.

Дополнительные сведения об атрибутах см. в разделе Атрибуты. Дополнительные сведения о лицензировании см. в разделе Практическое руководство. Компоненты и элементы управления лицензиями.

Примечание

Атрибут HostProtectionAttribute , применяемый к этому классу, имеет следующее Resources значение свойства: SharedState. Атрибут HostProtectionAttribute не оказывает влияния на настольные приложения (обычно запускаемые двойным щелчком значка, вводом команды или URL-адреса в браузере). Дополнительные сведения см. в HostProtectionAttribute разделе Класс или SQL Server Атрибуты программирования и защиты узла.

Конструкторы

LicenseProviderAttribute()

Инициализирует новый экземпляр класса LicenseProviderAttribute без поставщика лицензий.

LicenseProviderAttribute(String)

Инициализирует новый экземпляр класса LicenseProviderAttribute с указанным типом.

LicenseProviderAttribute(Type)

Инициализирует новый экземпляр класса LicenseProviderAttribute, используя указанный тип поставщика лицензий.

Поля

Default

Определяет значение по умолчанию, не являющееся поставщиком. Это статическое (static) поле доступно только для чтения.

Свойства

LicenseProvider

Возвращает поставщик лицензий, который должен использоваться вместе со связанным классом.

TypeId

Указывает уникальный идентификатор для атрибута данного типа.

Методы

Equals(Object)

Указывает, равен ли этот экземпляр заданному объекту.

GetHashCode()

Возвращает хэш-код данного экземпляра.

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)

Применяется к

См. также раздел