SharedPropertyGroup 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
表示共用屬性的集合。 此類別無法獲得繼承。
public ref class SharedPropertyGroup sealed
[System.Runtime.InteropServices.ComVisible(false)]
public sealed class SharedPropertyGroup
[<System.Runtime.InteropServices.ComVisible(false)>]
type SharedPropertyGroup = class
Public NotInheritable Class SharedPropertyGroup
- 繼承
-
SharedPropertyGroup
- 屬性
範例
下列程式代碼範例示範如何使用 SharedPropertyGroupManager 類別來建立 SharedPropertyGroup。
#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
備註
共用屬性群組是由包含管理員同步處理。
方法
CreateProperty(String, Boolean) |
建立具有指定名稱的屬性。 |
CreatePropertyByPosition(Int32, Boolean) |
建立指定位置的屬性。 |
Equals(Object) |
判斷指定的物件是否等於目前的物件。 (繼承來源 Object) |
GetHashCode() |
做為預設雜湊函式。 (繼承來源 Object) |
GetType() |
取得目前執行個體的 Type。 (繼承來源 Object) |
MemberwiseClone() |
建立目前 Object 的淺層複製。 (繼承來源 Object) |
Property(String) |
傳回具有指定名稱的屬性。 |
PropertyByPosition(Int32) |
傳回在指定位置的屬性。 |
ToString() |
傳回代表目前物件的字串。 (繼承來源 Object) |