Table of Contents

Class List

Namespace
Dynamitey.DynamicObjects
Assembly
Dynamitey.Community.dll

Expando-Type List for dynamic objects

public class List : BaseDictionary, IDynamicMetaObjectProvider, IEquivalentType, INotifyPropertyChanged, IList<object>, ICollection<object>, IEnumerable<object>, IDictionary<string, object>, ICollection<KeyValuePair<string, object>>, IEnumerable<KeyValuePair<string, object>>, INotifyCollectionChanged, IList, ICollection, IEnumerable
Inheritance
List
Implements
Inherited Members
Extension Methods

Constructors

List(IEnumerable<object>?, IEnumerable<KeyValuePair<string, object>>?)

Initializes a new instance of the List 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.")]
public List(IEnumerable<object>? contents = null, IEnumerable<KeyValuePair<string, object>>? members = null)

Parameters

contents IEnumerable<dynamic>

The contents.

members IEnumerable<KeyValuePair<string, object>>

The members.

Fields

_list

Wrapped list

protected IList<object> _list

Field Value

IList<dynamic>

Properties

Count

Gets the count.

public int Count { get; }

Property Value

int

The count.

IsFixedSize

Gets a value indicating whether this instance is fixed size.

public bool IsFixedSize { get; }

Property Value

bool

true if this instance is fixed size; otherwise, false.

IsSynchronized

Gets a value indicating whether this instance is synchronized.

public bool IsSynchronized { get; }

Property Value

bool

true if this instance is synchronized; otherwise, false.

this[int]

Gets or sets the object at the specified index.

public dynamic this[int index] { get; set; }

Parameters

index int

The index.

Property Value

dynamic

The object.

OverrideGettingItemMethodNames

Gets or sets the override getting item method names. USED for GetItemProperties

public Func<IEnumerable<object>, IEnumerable<string>>? OverrideGettingItemMethodNames { get; set; }

Property Value

Func<IEnumerable<object>, IEnumerable<string>>

The override getting item method names.

SyncRoot

Gets the sync root.

public object SyncRoot { get; }

Property Value

object

The sync root.

Methods

Add(dynamic)

Adds the specified item.

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The item parameter is statically typed 'dynamic', so this call binds through the DLR binder even though the underlying operation is a plain list add. Can't carry [RequiresUnreferencedCode] itself: it implements a plain BCL collection interface member that isn't annotated, and the two must match. The actionable warning belongs to whichever 'dynamic'-typed argument the caller supplied, which already carries this requirement at its own declaration.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Same reasoning as the IL2026 suppression on this member.")]
public void Add(dynamic item)

Parameters

item dynamic

The item.

Clear()

Clears this instance.

public void Clear()

Contains(dynamic?)

Determines whether [contains] [the specified item].

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The item parameter is statically typed 'dynamic', so this call binds through the DLR binder even though the underlying operation is a plain list lookup. Can't carry [RequiresUnreferencedCode] itself: it implements a plain BCL collection interface member that isn't annotated, and the two must match. The actionable warning belongs to whichever 'dynamic'-typed argument the caller supplied, which already carries this requirement at its own declaration.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Same reasoning as the IL2026 suppression on this member.")]
public bool Contains(dynamic? item)

Parameters

item dynamic

The item.

Returns

bool

true if [contains] [the specified item]; otherwise, false.

CopyTo(Array, int)

Copies to.

public void CopyTo(Array array, int index)

Parameters

array Array

The array.

index int

The index.

CopyTo(object[], int)

Copies to.

public void CopyTo(object[] array, int arrayIndex)

Parameters

array object[]

The array.

arrayIndex int

Index of the array.

Equals(List?)

Determines whether the specified List is equal to this instance.

public bool Equals(List? other)

Parameters

other List

The other.

Returns

bool

true when both instances are views over the same backing stores - the same IList<T> of elements and the same dictionary of dynamic properties.

Remarks

This is deliberately store identity, not content comparison: these types are mutable views over a store someone else owns, so two wrappers over one store are one value, while two stores that merely happen to hold equal data are not. Comparing content would also force a content-derived GetHashCode() on a mutable type, which makes an instance unfindable in a hash container as soon as it is mutated.

This previously opened with base.Equals(other), which resolves to Equals(object?) - a method whose body type-tests against typeof(Dictionary) and so, for a List, compared the backing dictionary against the List itself and returned false. That made the whole method return false unconditionally and left the element comparison below it unreachable, even for two wrappers over one IList<T>. See issue #52.

Equals(object?)

Determines whether the specified object is equal to this instance.

public override bool Equals(object? obj)

Parameters

obj object

The object to compare with this instance.

Returns

bool

true if the specified object is equal to this instance; otherwise, false.

GetEnumerator()

Gets the enumerator.

public IEnumerator<dynamic> GetEnumerator()

Returns

IEnumerator<object>

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.

GetRepresentedItem()

Gets the represented item. USED fOR GetItemProperties

protected virtual dynamic? GetRepresentedItem()

Returns

dynamic

IndexOf(dynamic?)

Indexes the of.

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The item parameter is statically typed 'dynamic', so this call binds through the DLR binder even though the underlying operation is a plain list lookup. Can't carry [RequiresUnreferencedCode] itself: it implements a plain BCL collection interface member that isn't annotated, and the two must match. The actionable warning belongs to whichever 'dynamic'-typed argument the caller supplied, which already carries this requirement at its own declaration.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Same reasoning as the IL2026 suppression on this member.")]
public int IndexOf(dynamic? item)

Parameters

item dynamic

The item.

Returns

int

Insert(int, dynamic?)

Inserts the specified index.

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The item parameter is statically typed 'dynamic', so this call binds through the DLR binder even though the underlying operation is a plain list insert. Can't carry [RequiresUnreferencedCode] itself: it implements a plain BCL collection interface member that isn't annotated, and the two must match. The actionable warning belongs to whichever 'dynamic'-typed argument the caller supplied, which already carries this requirement at its own declaration.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Same reasoning as the IL2026 suppression on this member.")]
public void Insert(int index, dynamic? item)

Parameters

index int

The index.

item dynamic

The item.

OnCollectionChanged(NotifyCollectionChangedAction, object?, object?, int?, int?)

Called when [collection changed].

protected virtual void OnCollectionChanged(NotifyCollectionChangedAction action, object? oldItem = null, object? newItem = null, int? oldIndex = null, int? newIndex = null)

Parameters

action NotifyCollectionChangedAction

The action.

oldItem object

The old item.

newItem object

The new item.

oldIndex int?

The old index.

newIndex int?

The new index.

Remove(dynamic)

Removes the specified item.

[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "The item parameter is statically typed 'dynamic', so this call binds through the DLR binder even though the underlying operation is a plain list remove. Can't carry [RequiresUnreferencedCode] itself: it implements a plain BCL collection interface member that isn't annotated, and the two must match. The actionable warning belongs to whichever 'dynamic'-typed argument the caller supplied, which already carries this requirement at its own declaration.")]
[UnconditionalSuppressMessage("AOT", "IL3050", Justification = "Same reasoning as the IL2026 suppression on this member.")]
public bool Remove(dynamic item)

Parameters

item dynamic

The item.

Returns

bool

RemoveAt(int)

Removes at.

public void RemoveAt(int index)

Parameters

index int

The index.

Events

CollectionChanged

Occurs when the collection changes.

public event NotifyCollectionChangedEventHandler? CollectionChanged

Event Type

NotifyCollectionChangedEventHandler