SharedProperty Classe

Définition

Accède à une propriété partagée. Cette classe ne peut pas être héritée.

public ref class SharedProperty sealed
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class SharedProperty
[<System.Runtime.InteropServices.ComVisible(false)>]
type SharedProperty = class
Public NotInheritable Class SharedProperty
Héritage
SharedProperty
Attributs

Exemples

L’exemple de code suivant montre comment créer une propriété partagée et définir et récupérer la valeur stockée dans la propriété partagée.

#using <System.EnterpriseServices.dll>

using namespace System;
using namespace System::EnterpriseServices;
using namespace System::Reflection;

[assembly:AssemblyKeyFile("..\\common\\key.snk")];
[assembly:ApplicationName("ReceiptNumberGenerator")];
[assembly:ApplicationActivation(ActivationOption::Library)];

public ref class ReceiptNumberGeneratorClass
{
public:

   // Generates a new receipt number based on the receipt number
   // stored by the Shared Property Manager (SPM)
   int GetNextReceiptNumber()
   {
      bool groupExists;
      bool propertyExists;
      int nextReceiptNumber = 0;
      PropertyLockMode lockMode = PropertyLockMode::SetGet;
      PropertyReleaseMode releaseMode = PropertyReleaseMode::Standard;
      
      // Create a shared property group manager.
      SharedPropertyGroupManager^ groupManager = gcnew SharedPropertyGroupManager;

      // Create a shared property group.
      SharedPropertyGroup^ group =
         groupManager->CreatePropertyGroup( "Receipts",  lockMode,  releaseMode,  groupExists );

      // Create a shared property.
      SharedProperty^ ReceiptNumber;
      ReceiptNumber = group->CreateProperty( "ReceiptNumber",  propertyExists );

      // Retrieve the value from shared property, and increment the shared 
      // property value.
      nextReceiptNumber =  safe_cast<int>(ReceiptNumber->Value);
      ReceiptNumber->Value = nextReceiptNumber + 1;

      // Return nextReceiptNumber
      return nextReceiptNumber;
   }
};
using System;
using System.EnterpriseServices;
using System.Reflection;

[assembly: ApplicationName("ReceiptNumberGenerator")]
[assembly: ApplicationActivation(ActivationOption.Library)]

public class ReceiptNumberGeneratorClass
{
    // Generates a new receipt number based on the receipt number
    // stored by the Shared Property Manager (SPM)
    public int GetNextReceiptNumber()
    {
        bool groupExists,propertyExists;
        int nextReceiptNumber = 0;
        PropertyLockMode lockMode = PropertyLockMode.SetGet;
        PropertyReleaseMode releaseMode = PropertyReleaseMode.Standard;

        // Create a shared property group manager.
        SharedPropertyGroupManager groupManager = new SharedPropertyGroupManager();
        // Create a shared property group.
        SharedPropertyGroup group = groupManager.CreatePropertyGroup("Receipts",
                                   ref lockMode, ref releaseMode, out groupExists);
        // Create a shared property.
        SharedProperty ReceiptNumber;
        ReceiptNumber = group.CreateProperty("ReceiptNumber",out propertyExists);
        // Retrieve the value from shared property, and increment the shared
        // property value.
        nextReceiptNumber = (int) ReceiptNumber.Value;
        ReceiptNumber.Value = nextReceiptNumber + 1;
        // Return nextReceiptNumber
        return nextReceiptNumber;
    }
}
Imports System.EnterpriseServices
Imports System.Reflection

<Assembly: ApplicationName("ReceiptNumberGenerator")> 
<Assembly: ApplicationActivation(ActivationOption.Library)> 
 

Public Class ReceiptNumberGeneratorClass
    
    ' Generates a new receipt number based on the receipt number
    ' stored by the Shared Property Manager (SPM)
    Public Function GetNextReceiptNumber() As Integer 
        Dim groupExists, propertyExists As Boolean
        Dim nextReceiptNumber As Integer = 0
        Dim lockMode As PropertyLockMode = PropertyLockMode.SetGet
        Dim releaseMode As PropertyReleaseMode = PropertyReleaseMode.Standard
        
        ' Create a shared property group manager.
        Dim groupManager As New SharedPropertyGroupManager()

        ' Create a shared property group.
        Dim group As SharedPropertyGroup = groupManager.CreatePropertyGroup("Receipts", lockMode, releaseMode, groupExists)
        ' Create a shared property.
        Dim ReceiptNumber As SharedProperty
        ReceiptNumber = group.CreateProperty("ReceiptNumber", propertyExists)

        ' Retrieve the value from shared property, and increment the shared 
        ' property value.
        nextReceiptNumber = Fix(ReceiptNumber.Value)
        ReceiptNumber.Value = nextReceiptNumber + 1

        ' Return nextReceiptNumber
        Return nextReceiptNumber
    
    End Function 'GetNextReceiptNumber

End Class

Propriétés

Value

Obtient ou définit la valeur de la propriété partagée.

Méthodes

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

S’applique à