Freigeben über


DomainAttribute Class

Specifies a domain for a rule method parameter.

Namespace: Microsoft.Modeling
Assembly: Microsoft.Xrt.Runtime (in Microsoft.Xrt.Runtime.dll)

Usage

'Usage

Syntax

'Declaration
[AttributeUsageAttribute(AttributeTargets.Parameter, AllowMultiple=false, Inherited=false)] 
public sealed class DomainAttribute : Attribute

Example

The following example shows how to use parameter domains.

public class C
{
   [Rule]
   static void MyParameterDomain([Domain("SomeInts")] int x)
   {
      /* ... */
   }
   public static IEnumerable<int> SomeInts()
   {
      return new int[] {1, 2, 3, 4};
   }
}

Spec Explorer supports the following forms of domains for reference types:

[Domain("{null}")]
[Domain("instances(implementationType)")]
[Domain("{null} + instances(implementationType)")]

Remarks

Domains can be assigned to rule method parameters with the Domain attribute. The Domain attribute takes one string parameter, domain.

If domain starts with "{", "instances", "(.", or null, it is interpreted as a Cord domain expression. If the rule method is static, then domain must be a string that names one of the following:

  1. A public static method, where the containing class is also public. The method must be parameterless and the return value must be an IEnumerable<T>.

  2. A public static property with a get accessor, where the containing class is also public.

  3. A public static field in the class containing the Domain attribute, where the containing class is also public.

If the rule method is instance-based, the restrictions above apply with the exception that the method, property, or field can be either static or instance-based.

Note that the domain is specified in terms of the implementation type, not the model type. In practice, this usually does not matter, as the implementation type and model type are typically the same. However, if a model type has been bound to a different implementation type through the use of the TypeBinding attribute, domain is still specified in terms of the implementation type, but the associated model type will be used during model exploration.

For more information about using attributes, see Extending Metadata Using Attributes.

Inheritance Hierarchy

System.Object
   System.Attribute
    Microsoft.Modeling.DomainAttribute

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

DomainAttribute Members
Microsoft.Modeling Namespace

Other Resources

Parameter Domains
Rule Attribute
Domain