Class BaseDictionary
- Namespace
- Dynamitey.DynamicObjects
- Assembly
- Dynamitey.Community.dll
Base class of Expando-Type objects
public abstract class BaseDictionary : BaseObject, IDynamicMetaObjectProvider, IEquivalentType, INotifyPropertyChanged
- Inheritance
-
BaseDictionary
- Implements
- Derived
- Inherited Members
Constructors
BaseDictionary(IEnumerable<KeyValuePair<string, object>>?)
Initializes a new instance of the Dictionary class.
[RequiresDynamicCode("Constructing any BaseObject-derived type instantiates System.Dynamic.DynamicObject, whose default constructor requires the DLR's runtime code generation; not supported when AOT-compiled.")]
protected BaseDictionary(IEnumerable<KeyValuePair<string, object>>? dict = null)
Parameters
dictIEnumerable<KeyValuePair<string, object>>The dict.
Fields
_dictionary
Wrapped Dictionary
protected IDictionary<string, object> _dictionary
Field Value
Properties
IsReadOnly
Gets a value indicating whether this instance is read only.
public virtual bool IsReadOnly { get; }
Property Value
- bool
trueif this instance is read only; otherwise,false.
Keys
Gets the keys.
public ICollection<string> Keys { get; }
Property Value
- ICollection<string>
The keys.
Values
Gets the values.
public ICollection<object> Values { get; }
Property Value
- ICollection<object>
The values.
Methods
Add(KeyValuePair<string, object>)
Adds the specified item.
public void Add(KeyValuePair<string, object> item)
Parameters
itemKeyValuePair<string, object>The item.
Add(string, object)
Adds the specified key.
public void Add(string key, object value)
Parameters
Contains(KeyValuePair<string, object>)
Determines whether [contains] [the specified item].
public bool Contains(KeyValuePair<string, object> item)
Parameters
itemKeyValuePair<string, object>The item.
Returns
- bool
trueif [contains] [the specified item]; otherwise,false.
ContainsKey(string)
Determines whether the specified key contains key.
public bool ContainsKey(string key)
Parameters
keystringThe key.
Returns
- bool
trueif the specified key contains key; otherwise,false.
CopyTo(KeyValuePair<string, object>[], int)
Copies to.
public void CopyTo(KeyValuePair<string, object>[] array, int arrayIndex)
Parameters
arrayKeyValuePair<string, object>[]The array.
arrayIndexintIndex of the array.
Equals(Dictionary?)
Determines whether the specified Dictionary is equal to this instance.
public bool Equals(Dictionary? other)
Parameters
otherDictionaryThe other.
Returns
- bool
truewhen both instances are views over the same backing dictionary.
Remarks
Store identity, not content comparison. These types are mutable views over a dictionary someone else owns, so two wrappers over one store are one value, while two stores that merely hold equal data are not - and GetHashCode() matches, returning the backing store's hash. Comparing content would instead require a content-derived hash on a mutable type, which makes an instance unfindable in a hash container the moment it is mutated. List documents and now implements the same contract; see issue #52.
Equals(object?)
Determines whether the specified object is equal to this instance.
public override bool Equals(object? obj)
Parameters
Returns
GetDynamicMemberNames()
Returns the enumeration of all dynamic member names.
public override IEnumerable<string> GetDynamicMemberNames()
Returns
- IEnumerable<string>
A sequence that contains dynamic member names.
GetHashCode()
Returns a hash code for this instance.
public override int GetHashCode()
Returns
- int
A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
OnPropertyChanged(string)
Called when [property changed].
protected virtual void OnPropertyChanged(string key)
Parameters
keystringThe key.
Remove(KeyValuePair<string, object>)
Removes the specified item.
public bool Remove(KeyValuePair<string, object> item)
Parameters
itemKeyValuePair<string, object>The item.
Returns
Remove(string)
Removes the specified key.
public bool Remove(string key)
Parameters
keystringThe key.
Returns
SetProperty(string, object?)
Sets the property.
protected void SetProperty(string key, object? value)
Parameters
ToString()
Returns a string that represents this instance.
public override string ToString()
Returns
TryGetMember(GetMemberBinder, out object?)
Provides the implementation for operations that get member values. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations such as getting a value for a property.
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Calls the annotated MassageResultBasedOnInterface. This is a DynamicObject.TryGetMember override: it can't carry [RequiresUnreferencedCode] itself without mismatching the unannotated base member, and the DLR invokes it only after the consumer's own dynamic member access already triggered the framework's warning.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Same MassageResultBasedOnInterface call as above; see the IL2026 suppression on this member.")]
public override bool TryGetMember(GetMemberBinder binder, out object? result)
Parameters
binderGetMemberBinderProvides information about the object that called the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the Console.WriteLine(sampleObject.SampleProperty) statement, where sampleObject is an instance of the class derived from the DynamicObject class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.
resultobjectThe result of the get operation. For example, if the method is called for a property, you can assign the property value to
result.
Returns
- bool
true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a run-time exception is thrown.)
TryGetValue(string, out object)
Tries the get value.
public bool TryGetValue(string key, out object value)
Parameters
Returns
TryInvokeMember(InvokeMemberBinder, object?[]?, out object?)
Provides the implementation for operations that invoke a member. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations such as calling a method.
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "Calls the annotated InvokeMethodDelegate/Dynamic.Invoke/MassageResultBasedOnInterface. This is a DynamicObject.TryInvokeMember override: it can't carry [RequiresUnreferencedCode] itself without mismatching the unannotated base member, and the DLR invokes it only after the consumer's own dynamic call site already triggered the framework's warning.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Same InvokeMethodDelegate/Dynamic.Invoke/MassageResultBasedOnInterface calls as above; see the IL2026 suppression on this member.")]
public override bool TryInvokeMember(InvokeMemberBinder binder, object?[]? args, out object? result)
Parameters
binderInvokeMemberBinderProvides information about the dynamic operation. The binder.Name property provides the name of the member on which the dynamic operation is performed. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is an instance of the class derived from the DynamicObject class, binder.Name returns "SampleMethod". The binder.IgnoreCase property specifies whether the member name is case-sensitive.
argsobject[]The arguments that are passed to the object member during the invoke operation. For example, for the statement sampleObject.SampleMethod(100), where sampleObject is derived from the DynamicObject class,
args[0] is equal to 100.resultobjectThe result of the member invocation.
Returns
- bool
true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.)
TrySetMember(SetMemberBinder, object?)
Provides the implementation for operations that set member values. Classes derived from the DynamicObject class can override this method to specify dynamic behavior for operations such as setting a value for a property.
public override bool TrySetMember(SetMemberBinder binder, object? value)
Parameters
binderSetMemberBinderProvides information about the object that called the dynamic operation. The binder.Name property provides the name of the member to which the value is being assigned. For example, for the statement sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class derived from the DynamicObject class, binder.Name returns "SampleProperty". The binder.IgnoreCase property specifies whether the member name is case-sensitive.
valueobjectThe value to set to the member. For example, for sampleObject.SampleProperty = "Test", where sampleObject is an instance of the class derived from the DynamicObject class, the
valueis "Test".
Returns
- bool
true if the operation is successful; otherwise, false. If this method returns false, the run-time binder of the language determines the behavior. (In most cases, a language-specific run-time exception is thrown.)
Events
PropertyChanged
Occurs when a property value changes.
public event PropertyChangedEventHandler? PropertyChanged