ServiceElement(ElementType, Object) Constructor

Initializes a new instance of the ServiceElement class.

Definition

Namespace: InTheHand.Net.Bluetooth.Sdp
Assembly: InTheHand.Net.Bluetooth (in InTheHand.Net.Bluetooth.dll) Version: 4.0.32+5cdf1cfd21064ea31c5de33d160200ca1c4bc218
C#
public ServiceElement(
	ElementType type,
	Object value
)

Parameters

type  ElementType
The type of the element as an ElementType.
value  Object
The value for the new element, must suit the type of the element. See the remarks for more information.

Remarks

The type of the object passed in the value parameter must suit the type of the element. For instance if the element type is UInt8 then the object passed in must be a Byte, if the element type is TextString then the object must either be a String or the string encoded as an array of Byte, and if the element type is Uuid16 then the object passed in must be a UInt16, etc. For the full list of types see the class level documentation (ServiceElement).

For numerical element types the CreateNumericalServiceElement(ElementType, Object) factory method will accept any integer type and attempt to convert it to the required type before creating the ServiceElement, for example for element type UInt8 it will accept an Int32 parameter and convert it to a Byte internally.

Example

C#
ServiceElement e
e = new ServiceElement(ElementType.TextString, "Hello world");
e = new ServiceElement(ElementType.TextString, new byte[] { (byte)'h', (byte)'i', });
e = new ServiceElement(ElementType.Uuid16, (UInt16)0x1101);


int i = 10;
int j = -1;

// Error, Int32 not suitable for element type UInt8.
ServiceElement e0 = new ServiceElement(ElementType.UInt8, i);

// Success, Byte value 10 stored.
ServiceElement e1 = ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, i);

// Error, -1 not in range of type Byte.
ServiceElement e2 = ServiceElement.CreateNumericalServiceElement(ElementType.UInt8, j);

See Also