Get(T) Method

MS Activities Extensions

Collapse image Expand Image Copy image CopyHover image
Gets the value of an argument or the default value if there is no expression

Namespace: Microsoft.Activities.Extensions
Assembly: Microsoft.Activities.Extensions (in Microsoft.Activities.Extensions.dll) Version: 2.0.6.9 (2.0.6.9)

Syntax

C#
public static T Get<T>(
	this InArgument<T> argument,
	ActivityContext context,
	T defaultValue
)
Visual Basic
<ExtensionAttribute> _
Public Shared Function Get(Of T) ( _
	argument As InArgument(Of T), _
	context As ActivityContext, _
	defaultValue As T _
) As T
Visual C++
public:
[ExtensionAttribute]
generic<typename T>
static T Get(
	InArgument<T>^ argument, 
	ActivityContext^ context, 
	T defaultValue
)

Parameters

argument
Type: System.Activities..::..InArgument<(Of <(<'T>)>)>
The argument.
context
Type: System.Activities..::..ActivityContext
The context.
defaultValue
Type: T
The default value.

Type Parameters

T
The type of the argument

Return Value

the value of an argument or the default value if there is no expression

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type InArgument<(Of <(<'T>)>)>. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Examples

An activity that has an optional in argument
CopyC#
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ActivityWithOptionalArgs.cs" company="Microsoft">
//   Copyright (c) Microsoft Corporation. All rights reserved.
// </copyright>
// --------------------------------------------------------------------------------------------------------------------

using System.Activities;
using System.ComponentModel;

using Microsoft.Activities.Extensions;

/// <summary>
/// An activity with optional args
/// </summary>
// ReSharper disable CheckNamespace
public sealed class ActivityWithOptionalArgs : CodeActivity<string>
// ReSharper restore CheckNamespace
{
    #region Constants

    /// <summary>
    /// </summary>
    public const int DefaultOptionalValue = 1;

    #endregion

    // Prevent serialization of null value
    #region Public Properties

    /// <summary>
    /// Gets or sets OptionalArg.
    /// </summary>
    [DefaultValue(null)]
    public InArgument<int> OptionalArg { get; set; }

    /// <summary>
    /// Gets or sets RequiredArg.
    /// </summary>
    [RequiredArgument]
    public InArgument<string> RequiredArg { get; set; }

    #endregion

    #region Methods

    /// <summary>
    /// When implemented in a derived class, performs the execution of the activity.
    /// </summary>
    /// <returns>
    /// The result of the activity’s execution.
    /// </returns>
    /// <param name="context">The execution context under which the activity executes.</param>
    protected override string Execute(CodeActivityContext context)
    {
        var num = this.OptionalArg.Get(context, DefaultOptionalValue);

        return string.Format("{0}: {1}", this.RequiredArg.Get(context), num);
    }

    #endregion
}

See Also