RTI Connext C# API  6.1.2
MyType Struct Reference

Example C# class generated from the IDL struct MyType More...

Inherits IEquatable< MyType >.

Public Member Functions

 MyType ()
 Creates a fully initialized new instance with the default values More...
 
 MyType (int MyKey, string MyString, Example.Point MyPoint, ISequence< int > MyIntSequence, ISequence< Example.Point > MyPointSequence, Example.Point[] MyPointArray, int? MyOptionalInt, Example.Point MyOptionalPoint)
 Creates a new instance with a given value for each property More...
 
 MyType (MyType other_)
 Creates a new instance by making a deep copy of an existing one More...
 
bool Equals (MyType other)
 Compares two MyType instances for equality (IEquatable implementation). The comparison is deep. More...
 
override bool Equals (object obj)
 Compares this instance with another object (override of object.Equals) More...
 
override string ToString ()
 Provides a readable string representation More...
 
override int GetHashCode ()
 Calculates the hash code based on the values of each property More...
 

Properties

int MyKey [get, set]
 Gets or sets the value for the field MyKey More...
 
string MyString [get, set]
 Gets or sets the value for the field MyString More...
 
Example.Point MyPoint [get, set]
 Gets or sets the value for the field MyPoint. More...
 
ISequence< int > MyIntSequence [get]
 Gets the sequence MyIntSequence More...
 
ISequence< Example.PointMyPointSequence [get]
 Gets the sequence MyPointSequence More...
 
Example.Point[] MyPointArray [get, set]
 Gets or sets the array MyPointArray. More...
 
int? MyOptionalInt [get, set]
 Gets or sets the optional value of MyOptionalInt. A null value is allowed. More...
 
Example.Point MyOptionalPoint [get, set]
 Gets or sets the optional value of MyOptionalPoint. A null value is allowed. More...
 

Detailed Description

Example C# class generated from the IDL struct MyType

Use the documentation of this example class as a guide to understand the IDL-to-C# mapping of user data types, based on the OMG IDL4-CSHARP specification.

The IDL definition of MyType is the following:

// MyType.idl
module Example {
struct Point {
int32 X;
int32 Y;
};
struct MyType {
@key int32 MyKey;
string<512> MyString;
Point MyPoint;
sequence<int32, 128> MyIntSequence;
sequence<Point, 8> MyPointSequence;
Point MyPointArray[5];
@optional int32 MyOptionalInt;
@optional Point MyOptionalPoint;
};
};
Example.Point MyOptionalPoint
Gets or sets the optional value of MyOptionalPoint. A null value is allowed.
Definition: MyType.cs:339
MyType()
Creates a fully initialized new instance with the default values
Definition: MyType.cs:150
Example.Point MyPoint
Gets or sets the value for the field MyPoint.
Definition: MyType.cs:253
string MyString
Gets or sets the value for the field MyString
Definition: MyType.cs:244
Example.Point[] MyPointArray
Gets or sets the array MyPointArray.
Definition: MyType.cs:311
ISequence< int > MyIntSequence
Gets the sequence MyIntSequence
Definition: MyType.cs:277
int? MyOptionalInt
Gets or sets the optional value of MyOptionalInt. A null value is allowed.
Definition: MyType.cs:325
ISequence< Example.Point > MyPointSequence
Gets the sequence MyPointSequence
Definition: MyType.cs:301
int MyKey
Gets or sets the value for the field MyKey
Definition: MyType.cs:216
Definition: MyType.cs:17

The code generation tool (rtiddsgen) generates the C# types:

rtiddsgen -language c# MyType.idl
See also
IDL examples

Constructor & Destructor Documentation

◆ MyType() [1/3]

MyType ( )

Creates a fully initialized new instance with the default values

Each member is fully initialized as follows:

  • MyKey is set to 0
  • MyString is set to string.Empty
  • MyPoint is created with the default constructor (which sets X and Y to 0)
  • MyIntSequence is created as an empty Rti.Types.Sequence.
  • MyPointSequence is created as an empty Rti.Types.Sequence.
  • MyPointArray is created as an array of 5 Points, each created using Point's default constructor
  • MyOptionalInt is set to null
  • MyOptionalPoint is set to null

◆ MyType() [2/3]

MyType ( int  MyKey,
string  MyString,
Example.Point  MyPoint,
ISequence< int >  MyIntSequence,
ISequence< Example.Point MyPointSequence,
Example.Point[]  MyPointArray,
int?  MyOptionalInt,
Example.Point  MyOptionalPoint 
)

Creates a new instance with a given value for each property

The parameters are directly assigned to the properties; they're not deeply copied.

◆ MyType() [3/3]

MyType ( MyType  other_)

Creates a new instance by making a deep copy of an existing one

Parameters
other_The object to copy

Each property is deeply copied. For example:

var a = new MyType();
a.MyPoint = new Point(x: 5, y: 7);
var b = new MyType(a);
Debug.Assert(!ReferenceEquals(a.MyPoint, b.MyPoint);
Debug.Assert(Equals(a.MyPoint, b.MyPoint);
bool Equals(MyType other)
Compares two MyType instances for equality (IEquatable implementation). The comparison is deep.
Definition: MyType.cs:350
@ Debug
The message contains debug information that might be relevant to your application.

Member Function Documentation

◆ Equals() [1/2]

bool Equals ( MyType  other)

Compares two MyType instances for equality (IEquatable implementation). The comparison is deep.

Parameters
otherThe instance to compare
Returns
Whether the two instances have the same values for all their properties and all the elements in the sequence and array fields.

◆ Equals() [2/2]

override bool Equals ( object  obj)

Compares this instance with another object (override of object.Equals)

Parameters
objAny object
Returns
True only if obj is of type MyType and both are equal

◆ GetHashCode()

override int GetHashCode ( )

Calculates the hash code based on the values of each property

For sequence types only the sequence length is used in the hash; for arrays only the first element is used to calculate the hash.

◆ ToString()

override string ToString ( )

Provides a readable string representation

MyTypeSupport provides additional options (such as XML and JSON formatting) via Rti.Dds.Topics.TypeSupport<T>.ToString(T, Rti.Dds.Topics.PrintFormatProperty).

Property Documentation

◆ MyIntSequence

ISequence<int> MyIntSequence
get

Gets the sequence MyIntSequence

This property is defined as follows:

[Bound(128)]
public ISequence<int> MyIntSequence { get; }

Sequences do not provide a setter, only a getter, which allows adding or removing elements.

If a bounded sequence contains more elements than its bound (in this case, 128), Rti.Dds.Publication.DataWriter<T>.Write(T) will fail.

See also
Omg.Types.BoundAttribute

◆ MyKey

int MyKey
getset

Gets or sets the value for the field MyKey

This property is defined as follows:

[Key]
public int MyKey { get; set; }
See also
Omg.Types.KeyAttribute

◆ MyOptionalInt

int? MyOptionalInt
getset

Gets or sets the optional value of MyOptionalInt. A null value is allowed.

This property is defined as follows:

[Optional]
public int? MyOptionalInt { get; set; }
See also
Omg.Types.OptionalAttribute

◆ MyOptionalPoint

Example.Point MyOptionalPoint
getset

Gets or sets the optional value of MyOptionalPoint. A null value is allowed.

This property is defined as follows:

[Optional]
public Example.Point MyOptionalPoint { get; set; }
Example C# class generated from the IDL struct Point, used by MyType.
Definition: MyType.cs:23
See also
Omg.Types.OptionalAttribute

◆ MyPoint

Example.Point MyPoint
getset

Gets or sets the value for the field MyPoint.

The property can't be set to null unless the field is optional. Otherwise Rti.Dds.Publication.DataWriter<T>.Write(T) will fail.

◆ MyPointArray

Example.Point [] MyPointArray
getset

Gets or sets the array MyPointArray.

If a new array is set, it must contain exactly the number of elements that was specified in the IDL file (5). Otherwise Rti.Dds.Publication.DataWriter<T>.Write(T) will fail.

◆ MyPointSequence

ISequence<Example.Point> MyPointSequence
get

Gets the sequence MyPointSequence

This property is defined as follows:

[Bound(8)]
public ISequence<Example.Point> MyPointSequence { get; }

Sequences do not provide a setter, only a getter, which allows adding or removing elements.

If a bounded sequence contains more elements than its bound (in this case, 8), Rti.Dds.Publication.DataWriter<T>.Write(T) will fail.

See also
Omg.Types.BoundAttribute

◆ MyString

string MyString
getset

Gets or sets the value for the field MyString

This property is defined as follows:

[Bound(512)]
public string MyString { get; set; } = string.Empty;

The property can't be set to null (because it's not @optional) and can't contain more bytes than its bound (512). In any of these cases Rti.Dds.Publication.DataWriter<T>.Write(T) would fail.

Note
Both IDL string and wstring map to C# string. However, an IDL string is encoded in UTF-8, whereas a wstring is encoded in UTF-16. The bound of a string refers to the total number of bytes in UTF-8, after being encoded. In the case of wstring, the bound refers to the total number of characters.
See also
Omg.Types.BoundAttribute