Class ResourceOptions

Definition

Namespace:
Tizen.Network.IoTConnectivity
Assembly:
Tizen.Network.IoTConnectivity.dll
API Level:
3

This class represents resource options. It provides APIs to manage them.

The iotcon options API provides methods for managing vendor specific options of coap packet.

See more about coap packet in http://tools.ietf.org/html/rfc7252.

C#
Copy
public class ResourceOptions : IDictionary<ushort, string>, ICollection<KeyValuePair<ushort, string>>, IEnumerable<KeyValuePair<ushort, string>>, IEnumerable, IDisposable
Inheritance
ResourceOptions
Implements
System.Collections.Generic.IDictionary<System.UInt16, System.String>
System.Collections.Generic.ICollection<System.Collections.Generic.KeyValuePair<System.UInt16, System.String>>
System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<System.UInt16, System.String>>
System.Collections.IEnumerable
System.IDisposable

Constructors

View Source

ResourceOptions()

The resource options constructor.

Declaration
C#
Copy
public ResourceOptions()
Examples
Copy
ResourceOptions options = new ResourceOptions();
Exceptions
Type Condition
System.NotSupportedException

Thrown when the iotcon is not supported.

OutOfMemoryException

Thrown when there is not enough memory.

API Level: 3
Feature: http://tizen.org/feature/iot.ocf

Properties

View Source

Count

Gets the number of options.

Declaration
C#
Copy
public int Count { get; }
Property Value
Type Description
System.Int32

The number of options.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); options.Add(2055, "sample value"); var count = options.Count; Console.WriteLine("There are {0} keys in the options object", count);
API Level: 3
View Source

IsReadOnly

Represents whether the collection is readonly.

Declaration
C#
Copy
public bool IsReadOnly { get; }
Property Value
Type Description
System.Boolean

Whether the collection is readonly.

Examples
Copy
ResourceOptions options = new ResourceOptions(); if (options.IsReadOnly) Console.WriteLine("Read only options");
API Level: 3
View Source

Item[UInt16]

Gets or sets the option data.

Declaration
C#
Copy
public string this[ushort key] { get; set; }
Parameters
Type Name Description
System.UInt16 key

The option ID to get or set.

Property Value
Type Description
System.String

The option data.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options[2055] = "sample-data"; Console.WriteLine("Option has : {0}", options[2055]);
API Level: 3
View Source

Keys

Contains all the Option keys.

Declaration
C#
Copy
public ICollection<ushort> Keys { get; }
Property Value
Type Description
System.Collections.Generic.ICollection<System.UInt16>

All the Option keys.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); options.Add(2055, "sample value"); var keys = options.Keys; Console.WriteLine("Resource options contains keys {0} and {1}", keys.ElementAt(0), keys.ElementAt(1));
API Level: 3
View Source

Values

Contains all the Option values.

Declaration
C#
Copy
public ICollection<string> Values { get; }
Property Value
Type Description
System.Collections.Generic.ICollection<System.String>

All the Option values.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); options.Add(2055, "sample value"); var values = options.Values; Console.WriteLine("Resource options contains values {0} and {1}", values.ElementAt(0), values.ElementAt(1));
API Level: 3

Methods

View Source

Add(KeyValuePair<UInt16, String>)

Adds options key and value as a key value pair.

Declaration
C#
Copy
public void Add(KeyValuePair<ushort, string> item)
Parameters
Type Name Description
System.Collections.Generic.KeyValuePair<System.UInt16, System.String> item

The key value pair.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345"));
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Add(UInt16, String)

Adds a new ID and a correspoding data into the options.

Declaration
C#
Copy
public void Add(ushort key, string value)
Parameters
Type Name Description
System.UInt16 key

The ID of the option to insert.

System.String value

The string data to insert into the options.

Remarks

ResourceOptions can have up to 2 options.

key is always situated between 2048 and 3000.

Length of option data is less than or equal to 15.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data");
Exceptions
Type Condition
System.NotSupportedException

Thrown when the iotcon is not supported.

System.ArgumentException

Thrown when there is an invalid parameter.

See Also
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Clear()

Clears the Options collection.

Declaration
C#
Copy
public void Clear()
Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(2050, "12345"); options.Add(2055, "sample"); options.Clear();
Exceptions
Type Condition
System.NotSupportedException

Thrown when the iotcon is not supported.

API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Contains(KeyValuePair<UInt16, String>)

Checks if the given option pair exists.

Declaration
C#
Copy
public bool Contains(KeyValuePair<ushort, string> item)
Parameters
Type Name Description
System.Collections.Generic.KeyValuePair<System.UInt16, System.String> item

The key value pair.

Returns
Type Description
System.Boolean

True if exists. Otherwise, false.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345")); var isPresent = options.Contains(new KeyValuePair<ushort, string>(2050, "12345")); if (isPresent) Console.WriteLine("Key value pair is present");
API Level: 3
View Source

ContainsKey(UInt16)

Checks whether the given key exists in Options collection.

Declaration
C#
Copy
public bool ContainsKey(ushort key)
Parameters
Type Name Description
System.UInt16 key

The key to look for.

Returns
Type Description
System.Boolean

true if exists. Otherwise, false.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(2050, "sample-data"); if (options.ContainsKey(2050)) Console.WriteLine("options conatins key : 2050");
API Level: 3
View Source

CopyTo(KeyValuePair<UInt16, String>[], Int32)

Copies the elements of the options collection to an array, starting at a particular index.

Declaration
C#
Copy
public void CopyTo(KeyValuePair<ushort, string>[] array, int arrayIndex)
Parameters
Type Name Description
System.Collections.Generic.KeyValuePair<System.UInt16, System.String>[] array

The destination array.

System.Int32 arrayIndex

Index parameter.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345")); KeyValuePair<ushort, string>[] dest = new KeyValuePair<ushort, string>[options.Count]; options.CopyTo(dest, 0); Console.WriteLine("Dest conatins ({0}, {1})", dest[0].Key, dest[0].Value);
API Level: 3
View Source

Dispose()

Releases any unmanaged resources used by this object.

Declaration
C#
Copy
public void Dispose()
API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Dispose(Boolean)

Releases any unmanaged resources used by this object. Can also dispose any other disposable objects.

Declaration
C#
Copy
protected virtual void Dispose(bool disposing)
Parameters
Type Name Description
System.Boolean disposing

If true, disposes any disposable objects. If false, does not dispose disposable objects.

API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Finalize()

Destructor of the ResourceOptions class.

Declaration
C#
Copy
protected void Finalize()
View Source

GetEnumerator()

Get the enumerator to options collection.

Declaration
C#
Copy
public IEnumerator<KeyValuePair<ushort, string>> GetEnumerator()
Returns
Type Description
System.Collections.Generic.IEnumerator<System.Collections.Generic.KeyValuePair<System.UInt16, System.String>>

Enumerator to option pairs.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "sample1")); options.Add(new KeyValuePair<ushort, string>(2055, "sample2")); foreach (KeyValuePair<string, object> pair in options) { Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); }
API Level: 3
View Source

Remove(KeyValuePair<UInt16, String>)

Removes the given key value pair from the options.

Declaration
C#
Copy
public bool Remove(KeyValuePair<ushort, string> item)
Parameters
Type Name Description
System.Collections.Generic.KeyValuePair<System.UInt16, System.String> item

The key value pair to remove

Returns
Type Description
System.Boolean

True if operation is successful. Otherwise, false

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "12345")); var result = options.Remove(new KeyValuePair<ushort, string>(2050, "12345"));
Exceptions
Type Condition
System.ArgumentException

Thrown when there is an invalid parameter

API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

Remove(UInt16)

Removes the ID and its associated data from the options.

Declaration
C#
Copy
public bool Remove(ushort key)
Parameters
Type Name Description
System.UInt16 key

The ID of the option to delete.

Returns
Type Description
System.Boolean

True if operation is successful. Otherwise, false.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(2050, "12345"); var result = options.Remove(2050);
Exceptions
Type Condition
System.NotSupportedException

Thrown when the iotcon is not supported.

System.ArgumentException

Thrown when there is an invalid parameter.

API Level: 3
Feature: http://tizen.org/feature/iot.ocf
View Source

TryGetValue(UInt16, out String)

Gets the value associated with the specified key.

Declaration
C#
Copy
public bool TryGetValue(ushort key, out string value)
Parameters
Type Name Description
System.UInt16 key

The option ID.

System.String value

Value corresponding to option ID.

Returns
Type Description
System.Boolean

True if the key exists, false otherwise.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(2050, "12345"); string value; var isPresent = options.TryGetValue(2050, out value); if (isPresent) Console.WriteLine("value : {0}", value);
API Level: 3

Explicit Interface Implementations

View Source

IEnumerable.GetEnumerator()

Gets the enumerator to options collection.

Declaration
C#
Copy
IEnumerator IEnumerable.GetEnumerator()
Returns
Type Description
System.Collections.IEnumerator

Enumerator to option pairs.

Examples
Copy
ResourceOptions options = new ResourceOptions(); options.Add(new KeyValuePair<ushort, string>(2050, "sample1")); options.Add(new KeyValuePair<ushort, string>(2055, "sample2")); foreach (KeyValuePair<string, object> pair in options) { Console.WriteLine("key : {0}, value : {1}", pair.Key, pair.Value); }
API Level: 3

Implements

System.Collections.Generic.IDictionary<TKey, TValue>
System.Collections.Generic.ICollection<T>
System.Collections.Generic.IEnumerable<T>
System.Collections.IEnumerable
System.IDisposable