Class UserData
- Namespace
- CADability
- Assembly
- CADability.dll
A table, that associates names with objects. Its purpose is to attach any kind of (user) information to existing CADability objects. Many objects of the CADability namespace provide a UserData property, by means of which you can connect any object to it. If the object is serializable, it will be serialized together with the CADability object. If it implements IClonable it will be cloned when the containing object is cloned. If it implements IShowProperty it will be displayed together with the object in the ControlCenter. If it implements IMultiObjectUserData it will be displayed as a common property when multiple objects are displayed in the ControlCenter
public class UserData : ISerializable, IDictionary<string, object>, ICollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, IDictionary, ICollection, IEnumerable, IJsonSerialize
- Inheritance
-
UserData
- Implements
- Inherited Members
- Extension Methods
Constructors
UserData()
Creates an empty table.
public UserData()
UserData(SerializationInfo, StreamingContext)
Constructor required by deserialization
protected UserData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInfoSerializationInfo
contextStreamingContextStreamingContext
Properties
AllItems
Gets an array of the names of all entries
public string[] AllItems { get; }
Property Value
- string[]
Count
The number of entries.
public int Count { get; }
Property Value
IsFixedSize
Always false: entries can be added and removed at any time.
public bool IsFixedSize { get; }
Property Value
IsReadOnly
Always false: the table can be modified.
public bool IsReadOnly { get; }
Property Value
IsSynchronized
Always false: access to the table is not synchronized.
public bool IsSynchronized { get; }
Property Value
this[object]
Untyped access to an entry (IDictionary). Reading an entry that does not exist or whose key is not a string gives null; setting requires a string key and adds or replaces the entry without raising the UserDataAddedEvent. Use this[string] for typed access.
public object this[object key] { get; set; }
Parameters
keyobjectthe key of the entry, a string
Property Value
this[string]
Indexer to read or write values to a given name
public object this[string Name] { get; set; }
Parameters
Namestring
Property Value
Keys
The keys of all entries (strings). AllItems returns them as an array.
public ICollection Keys { get; }
Property Value
SyncRoot
The object to lock on when the table is accessed from several threads (SyncRoot).
public object SyncRoot { get; }
Property Value
Values
The values of all entries.
public ICollection Values { get; }
Property Value
Methods
Add(UserData)
Add all entries given in the parameter to this UserData
public void Add(UserData userData)
Parameters
userDataUserDataentries to add
Add(object, object)
Untyped add (IDictionary). Unlike Add(string, object) it throws an ArgumentException when the key already exists or is not a string, and it does not raise the UserDataAddedEvent.
public void Add(object key, object value)
Parameters
Add(string, object)
Adds or replaces the named entry of the Userdata
public void Add(string Name, object Data)
Parameters
Clear()
Removes all entries without raising the UserDataRemovedEvent.
public void Clear()
Clone()
Returns a clone of the UserData object. The containe dictionary of string-object pairs is cloned so the result is independant from this object. The values are also cloned if they implement the ICloneable interface. If the value of an entry implements CADability.IManageUserData, CADability.IManageUserData.Clone() will be called.
public UserData Clone()
Returns
- UserData
The cloned UserData
Contains(object)
Untyped check (IDictionary) whether an entry with the given key exists.
public bool Contains(object key)
Parameters
keyobjectthe key, a string
Returns
- bool
true when the entry exists, false when it does not or the key is not a string
Contains(string)
Checks whether an entry with the given key exists; the same as ContainsData(string).
public bool Contains(string key)
Parameters
keystringthe key to look for
Returns
- bool
true when the entry exists
ContainsData(string)
Checks whether an entry with the provided name exists.
public bool ContainsData(string Name)
Parameters
NamestringName to check
Returns
- bool
true if the entry exists
CopyTo(Array, int)
Copies the entries as DictionaryEntry items into an array (CopyTo(Array, int)).
public void CopyTo(Array array, int index)
Parameters
GetData(string)
Returns the entry with the provided name. The result may be null if the entry doesn't exist. The result must be casted to the required type.
public object GetData(string Name)
Parameters
NamestringName of the entry
Returns
GetEnumerator()
Returns an enumerator over the entries as DictionaryEntry items with the key as string.
public IDictionaryEnumerator GetEnumerator()
Returns
- IDictionaryEnumerator
the enumerator
GetObjectData(IJsonWriteData)
Writes the entries for the JSON serialization (IJsonSerialize), each as a property named by its key. Only values that can be written are stored: primitive types, objects implementing IJsonSerialize, types marked with the System.SerializableAttribute, and arrays of those. Null values and keys starting with "$" (reserved for the serializer) are skipped.
public void GetObjectData(IJsonWriteData data)
Parameters
dataIJsonWriteDatareceives the data
GetObjectData(SerializationInfo, StreamingContext)
Writes the data of this object for the legacy binary serialization (ISerializable). Files are written in the JSON format (IJsonSerialize) now; the binary format is still read.
public void GetObjectData(SerializationInfo info, StreamingContext context)
Parameters
infoSerializationInforeceives the data
contextStreamingContextthe destination of the serialization
Remove(object)
Untyped remove (IDictionary) without raising the UserDataRemovedEvent. Does nothing when there is no such entry or the key is not a string.
public void Remove(object key)
Parameters
keyobjectthe key of the entry, a string
Remove(string)
Removes the entry with the given key without raising the UserDataRemovedEvent; use RemoveUserData(string) when the property pages should be notified. Does nothing when there is no such entry.
public void Remove(string key)
Parameters
keystringthe key of the entry
RemoveUserData(string)
Removes the entry with the provided name
public void RemoveUserData(string Name)
Parameters
NamestringName of the entry to be removed.
SetObjectData(IJsonReadData)
Reads the entries written by GetObjectData(IJsonWriteData) for the JSON deserialization (IJsonSerialize); the properties of the serializer itself ("$..." and "§Index") are skipped.
public void SetObjectData(IJsonReadData data)
Parameters
dataIJsonReadDataprovides the data
Events
UserDataAddedEvent
Raised when an entry is added or replaced with Add(string, object) or Add(UserData). The indexers and the IDictionary methods do not raise it. The property pages of the objects use it to show new entries.
public event UserData.UserDataAddedDelegate UserDataAddedEvent
Event Type
UserDataRemovedEvent
Raised when an entry is removed with RemoveUserData(string). The other remove methods and Clear() do not raise it.
public event UserData.UserDataRemovedDelegate UserDataRemovedEvent