ReadOnlyCollection <T> implements IList <T>, but does not implement the add method
How does it System.Collections.ObjectModel.ReadOnlyCollection<T>implement System.Collections.Generic.IList<T>but not implement its method Add?
I am not asking why it does not have a method Add- this is obvious because it should be read-only; I ask how this can do without implementing the method that is required by the interface contract IList<T>.
He explicitly implements the method along with several others that usually modify the base collection. See the Explicit Interface Implementations section on the next page:
Add , :
. ,
ReadOnlyCollection<T>ICollection<T>.
Add ReadOnlyCollection<T> ( ). , - , ( ).
. ( #)
:
, , - , . , IOleCommandTarget.QueryStatus ( ). . - .
/// <inheritdoc/>
int IOleCommandTarget.QueryStatus(ref Guid guidCmdGroup, uint cCmds, OLECMD[] prgCmds, IntPtr pCmdText)
{
using (OleCommandText oleCommandText = OleCommandText.FromQueryStatus(pCmdText))
{
Guid cmdGroup = guidCmdGroup;
for (uint i = 0; i < cCmds; i++)
{
OLECMDF status = QueryCommandStatus(ref cmdGroup, prgCmds[i].cmdID, oleCommandText);
if (status == default(OLECMDF) && _next != null)
{
int hr = _next.QueryStatus(ref cmdGroup, cCmds, prgCmds, pCmdText);
if (ErrorHandler.Failed(hr))
return hr;
}
else
{
prgCmds[i].cmdf = (uint)status;
}
}
return VSConstants.S_OK;
}
}
protected virtual public virtual, pCmdText _next prgCmds ( ).
/// <summary>
/// Gets the current status of a particular command.
/// </summary>
/// <remarks>
/// The base implementation returns 0 for all commands, indicating the command is
/// not supported by this command filter.
/// </remarks>
/// <param name="commandGroup">The command group.</param>
/// <param name="commandId">The command ID.</param>
/// <param name="oleCommandText">A wrapper around the <see cref="OLECMDTEXT"/>
/// object passed to <see cref="IOleCommandTarget.QueryStatus"/>, or
/// <see langword="null"/> if this parameter should be ignored.</param>
/// <returns>A collection of <see cref="OLECMDF"/> flags indicating the current
/// status of a particular command, or 0 if the command is not supported by the
/// current command filter.</returns>
protected virtual OLECMDF QueryCommandStatus(ref Guid commandGroup, uint commandId, OleCommandText oleCommandText)
{
return default(OLECMDF);
}
ReadOnlyCollection<>, , Add :
int IList.Add(object value)
{
ThrowHelper.ThrowNotSupportedException(ExceptionResource.NotSupported_ReadOnlyCollection);
return -1;
}
IList.Add. , Add ReadOnlyCollection<>. IList, , NotSupportedException.
, IList, Clear, Insert Remove , ICollection<>: .
.NET 4.5, System.Collections.Generic.IReadOnlyCollection<>. ReadOnlyCollection<> , IList, , , . , 4.5 , , IList IReadOnlyCollection<>.