public ServiceElement(
ElementType type,
Object value
)
Public Sub New (
type As ElementType,
value As Object
)
public:
ServiceElement(
ElementType type,
Object^ value
)
new :
type : ElementType *
value : Object -> ServiceElement
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.
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);