public sealed class ServiceElement
Public NotInheritable Class ServiceElement
public ref class ServiceElement sealed
[<SealedAttribute>]
type ServiceElement = class end
A Service Element hold the data in a SDP Service Record. It can hold various types of data, being like the ‘variant’ type in some environments. Each ServiceAttribute in a ServiceRecord holds its content in a Service Element.
The types currently defined in the Service Discovery specification include unsigned and signed integers of various sizes (8-bit, 16-bit etc), UUIDs in the full 128-bit form or in the 16 and 32-bit forms, TextString, Url etc. An element can itself also contain a list of element, either as a ‘sequence’ or an ‘alternative’, and thus an attribute can contain a tree of values, e.g. as used by the ProtocolDescriptorList attribute.
The type that an element is holding can be accessed with the ElementTypeDescriptor and ElementType properties which are of type ElementTypeDescriptor and ElementType respectively, the former being the ‘major’ type e.g. UnsignedInteger, and the latter the ‘minor’ type e.g. UInt16.
The element's value can be accessed in various ways, either directly in its internal form through its Value property. It has return type Object so the value will have to be cast before use, see the UInt16 example below. There are also a number of type-specific methods, e.g. GetValueAsElementArray, GetValueAsUuid, GetValueAsString(Encoding) etc. Each will throw an InvalidOperationException if the element is not of a suitable type. The complete set is:
ElementType | Access method, or .NET Type for direct access |
---|---|
Nil | |
Uint8 | Byte |
Uint16 | UInt16 |
Uint32 | UInt32 |
Uint64 | Currently unsupported. |
Uint128 | Currently unsupported. |
Int8 | SByte |
Int16 | Int16 |
Int32 | Int32 |
Int64 | Currently unsupported. |
Int128 | Currently unsupported. |
Uuid16 | Via GetValueAsUuid, or as UInt16 |
Uuid32 | Via GetValueAsUuid, or as UInt16 |
Uuid128 | Via GetValueAsUuid |
TextString | With GetValueAsString(Encoding) or GetValueAsStringUtf8 etc. The underlying value can be an array of bytes, or as a String the ServiceRecordParser will set an array of bytes, whereas a manually created record will likely contain a String. |
Boolean | Boolean |
ElementSequence | With GetValueAsElementArray or GetValueAsElementList |
ElementSequence | -"- |
Url | Via GetValueAsUri, can be stored interally as Uri or as an array of bytes |
Note that there are no access methods for the numeric type for instance so the Value property will have to be used e.g.
// ElementType is UInt16
ushort x = (ushort)element.Value;
// ElementType is UInt16
Dim x As UShort = CUShort(element.Value);
Additional type-specific methods can be added as required, in fact the full set of 19+ could be added, it just requires implementation and test…
ServiceElement(ElementType, ServiceElement) | Initializes a new instance of the ServiceElement class. |
ServiceElement(ElementType, IListServiceElement) | Initializes a new instance of the ServiceElement class. |
ServiceElement(ElementType, Object) | Initializes a new instance of the ServiceElement class. |
ElementType | Gets the type of the element as an ElementType. |
ElementTypeDescriptor | Gets the SDP Element Type Descriptor of the element as an ElementTypeDescriptor. |
Value | Gets the value of the element as the .NET type it is stored as. |
CreateNumericalServiceElement | Create an instance of ServiceElement but internally converting the numeric value to the required type. |
Equals | (Inherited from Object) |
GetHashCode | (Inherited from Object) |
GetType | (Inherited from Object) |
GetValueAsElementArray | Gets the value as a array of ServiceElement. |
GetValueAsElementList | Gets the value as a list of ServiceElement. |
GetValueAsString(Encoding) | Get the value of the TextString, where it is encoded using the given encoding form. |
GetValueAsString(LanguageBaseItem) | Get the value of the TextString, when it is encoded as specified by the given IETF Charset identifer. |
GetValueAsStringUtf8 | Get the value of the TextString, when it is encoded as UTF-8. |
GetValueAsUri | Gets the value as a Uri. |
GetValueAsUuid | Gets the value as a Guid. |
ToString | (Inherited from Object) |