StateInvariantAttribute Class
Indicates that a Boolean property, field, or parameter-free method is a state invariant.
Namespace: Microsoft.Modeling
Assembly: Microsoft.Xrt.Runtime (in Microsoft.Xrt.Runtime.dll)
Usage
'Usage
Syntax
'Declaration
[AttributeUsageAttribute(AttributeTargets.Method|AttributeTargets.Property, AllowMultiple=false, Inherited=false)]
public sealed class StateInvariantAttribute : Attribute
Example
The following example shows a StateInvariant method.
namespace Microsoft.MyModel
{
class AccountsClass
{
struct accountStruct
{
public string accountType;
public float Balance;
}
float Minimum = 100.0F;
SetContainer<accountStruct> Accounts = new SetContainer<accountStruct> { };
[StateInvariant]
public bool MinimumBalance()
{
//No model rule should ever make the balance less than Minimum.
return !Accounts.Any(a => a.accountType == "Savings" && a.Balance < Minimum);
}
}
}
Remarks
A state invariant is a Boolean property, field, or parameter-free method that MUST hold in every state. If it does not hold in a given state, that state is an error state.
If the target of a StateInvariant attribute is a method, it can be static or instance-based. If it is instance-based, the state invariant is said to hold if the return value is true for all reachable instances of the type. The return type of the method must be System.Boolean
.
For more information about using attributes, see Extending Metadata Using Attributes.
Inheritance Hierarchy
System.Object
System.Attribute
Microsoft.Modeling.StateInvariantAttribute
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Platforms
Development Platforms
Microsoft Windows 7, Microsoft Windows Vista, Microsoft Windows XP SP2 or later, Microsoft Windows Server 2008, Microsoft Windows Server 2003
Change History
See Also
Reference
StateInvariantAttribute Members
Microsoft.Modeling Namespace