DynamicValue Class

Dynamic value (uses RuntimeBinding for ISymbol value reading / writing).

Inheritance Hierarchy

System.Object
  System.Dynamic.DynamicObject
    TwinCAT.TypeSystem.DynamicValue
      TwinCAT.TypeSystem.DynamicPointerValue
      TwinCAT.TypeSystem.DynamicReferenceValue
Namespace:  TwinCAT.TypeSystem
Assembly:  TwinCAT.Ads (in TwinCAT.Ads.dll) Version: 4.3.0.0

Syntax

C#

public class DynamicValue : DynamicObject, 
    IValue, IStructValue, IArrayValue

VB

Public Class DynamicValue
    Inherits DynamicObject
    Implements IValue, IStructValue, IArrayValue

The DynamicValue type exposes the following members.

Properties

 

Name

Description

Age

Gets the age of the value (last successful read of the value)

CachedRaw

Gets the cached Raw internal Data.

DataType

Gets the data type bound to this IValue

IsPrimitive

Gets a value indicating whether this IValue is a primitive value.

ResolvedType

Gets the resolved type.

Symbol

Gets the symbol that is bound to this value.

UtcTimeStamp

Gets the Time stamp of the last successful read of the Value.

Methods

 

Name

Description

Equals

Determines whether the specified object is equal to the current object. (Inherited from Object.)

Finalize

Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)

GetDynamicMemberNames

Returns the enumeration of all dynamic member names. (Overrides DynamicObject.GetDynamicMemberNames..)

GetHashCode

Serves as the default hash function. (Inherited from Object.)

GetMetaObject

Provides a DynamicMetaObject that dispatches to the dynamic virtual methods. The object can be encapsulated inside another DynamicMetaObject to provide custom behavior for individual actions. This method supports the Dynamic Language Runtime infrastructure for language implementers and it is not intended to be used directly from your code. (Inherited from DynamicObject.)

GetType

Gets the Type of the current instance. (Inherited from Object.)

MemberwiseClone

Creates a shallow copy of the current Object. (Inherited from Object.)

Read

Reads the value (via ADS)

ReadMember

Reads the specified member element.

ResolveValue

Resolves the Value object to its primitive value.

ToString

Returns a String that represents this instance. (Overrides Object.ToString..)

TryBinaryOperation

Provides implementation for binary operations. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations such as addition and multiplication. (Inherited from DynamicObject.)

TryConvert

Provides implementation for type conversion operations. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations that convert an object from one type to another. (Overrides DynamicObject.TryConvert(ConvertBinder, Object.).)

TryCreateInstance

Provides the implementation for operations that initialize a new instance of a dynamic object. This method is not intended for use in C# or Visual Basic. (Inherited from DynamicObject.)

TryDeleteIndex

Provides the implementation for operations that delete an object by index. This method is not intended for use in C# or Visual Basic. (Inherited from DynamicObject.)

TryDeleteMember

Provides the implementation for operations that delete an object member. This method is not intended for use in C# or Visual Basic. (Inherited from DynamicObject.)

TryGetArrayElementValues

Returns Array Element values.

TryGetIndex

Provides the implementation for operations that get a value by index. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for indexing operations. (Overrides DynamicObject.TryGetIndex(GetIndexBinder, .Object., Object.).)

TryGetIndexValue(.Int32., Object.)

Reads the specified array element.

TryGetIndexValue(.Object., Object.)

Tries the get index value.

TryGetMember

Provides the implementation for operations that get member values. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations such as getting a value for a property. (Overrides DynamicObject.TryGetMember(GetMemberBinder, Object.).)

TryGetMemberValue

Tries the get member value.

TryInvoke

Provides the implementation for operations that invoke an object. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations such as invoking an object or a delegate. (Overrides DynamicObject.TryInvoke(InvokeBinder, .Object., Object.).)

TryInvokeMember

Provides the implementation for operations that invoke a member. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations such as calling a method. (Overrides DynamicObject.TryInvokeMember(InvokeMemberBinder, .Object., Object.).)

TryResolveValue

Tries to resolves the Value object to its primitive value.

TrySetIndex

Provides the implementation for operations that set a value by index. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations that access objects by a specified index. (Overrides DynamicObject.TrySetIndex(SetIndexBinder, .Object., Object).)

TrySetIndexValue

Tries to set the indexed value on Arrays

TrySetMember

Provides the implementation for operations that set member values. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations such as setting a value for a property. (Overrides DynamicObject.TrySetMember(SetMemberBinder, Object).)

TrySetMemberValue

Tries to Set a Member/Property Value

TryUnaryOperation

Provides implementation for unary operations. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations such as negation, increment, or decrement. (Inherited from DynamicObject.)

Write

Writes the value (via ADS)

WriteMember

Writes the specified member element.

Fields

 

Name

Description

_symbol

Symbol that is bound to this value.

valueFactory

The value factory

Remarks

The DynamicValue adds dynamic run time behaviour to the IValueValue/IValue. That means e.g. for struct values that .NET Properties are on-the-fly defined and dispatched at runtime just like defined in the structs structs data type definition. Another example is the access of Array Element values through indexes.

Examples

Sample for the dynamic resolution of Symbols and reading values:

Dynamic Symbol access

/// <summary>
/// Defines the entry point of the application.
/// </summary>
/// <param name="args">The arguments.</param>
static void Main(string[] args)
{
    // Get the AdsAddress from command-line arguments
    AmsAddress address = ArgParser.Parse(args);

    using (TcAdsClient client = new TcAdsClient())
    {
    // Connect to the target device
    client.Connect(address);

    // Usage of "dynamic" Type and Symbols (>= .NET4 only)
    SymbolLoaderSettings settings = new SymbolLoaderSettings(SymbolsLoadMode.DynamicTree);
    IAdsSymbolLoader dynLoader = (IAdsSymbolLoader)SymbolLoaderFactory.Create(client, settings);

Reference

TwinCAT.TypeSystem Namespace

TwinCAT.TypeSystem.DynamicSymbol

System.Dynamic.DynamicObject

TwinCAT.TypeSystem.IValue