101 lines
2.6 KiB
C#
101 lines
2.6 KiB
C#
using System;
|
|
using System.Collections;
|
|
|
|
namespace BCG
|
|
{
|
|
/// <summary>
|
|
/// Projected row just keeps a pointer to the original row its projecting and to the ProjectHelper
|
|
/// (which provided the projected schema and the mapping). All indexing to it, are redirected (though
|
|
/// the colMapper in ProjectHelper) to the original row
|
|
/// </summary>
|
|
internal class ProjectedRow : IBlueRow
|
|
{
|
|
private IBlueRow myRow;
|
|
private ProjectHelper myHelper;
|
|
|
|
internal ProjectedRow (IBlueRow row, ProjectHelper helper)
|
|
{
|
|
myRow = row;
|
|
myHelper = helper;
|
|
}
|
|
|
|
#region IBlueRow Members
|
|
|
|
public object? this [string colName] =>
|
|
this[myHelper.schema[colName].colNo];
|
|
|
|
public object? this [int index] =>
|
|
myRow[myHelper.colMap[index]];
|
|
|
|
public IBlueTableSchema schema {get {return myHelper.schema;}}
|
|
|
|
#endregion
|
|
|
|
#region IDictionary Members
|
|
|
|
public bool IsReadOnly {get {return true;}}
|
|
|
|
public IDictionaryEnumerator GetEnumerator() {return new BlueRowDictionaryEnumerator (this);}
|
|
|
|
object? IDictionary.this[object key]
|
|
{
|
|
get => key switch {
|
|
int i => this[i],
|
|
string s => this[s],
|
|
_ => throw new ArgumentException("Must be int or string", nameof(key)),
|
|
};
|
|
set {throw new ApplicationException ("Is read only");}
|
|
}
|
|
|
|
public void Remove(object key) {throw new ApplicationException ("Is read only");}
|
|
|
|
public bool Contains (object key) {return myHelper.schema [key as string] != null;}
|
|
|
|
public void Clear() {throw new ApplicationException ("Is read only");}
|
|
|
|
public ICollection Values
|
|
{
|
|
get
|
|
{
|
|
object[] retVal = new object[Count];
|
|
CopyTo (retVal, 0);
|
|
return retVal;
|
|
}
|
|
}
|
|
|
|
public void Add(object key, object? value) =>
|
|
throw new NotSupportedException();
|
|
|
|
public ICollection Keys {get {return myHelper.schema.columnNames;}}
|
|
|
|
public bool IsFixedSize {get {return true;}}
|
|
|
|
#endregion
|
|
|
|
#region ICollection Members
|
|
|
|
public bool IsSynchronized {get {return false;}}
|
|
|
|
public int Count {get {return myHelper.schema.columnNames.Length;}}
|
|
|
|
public void CopyTo (Array array, int index)
|
|
{
|
|
foreach (ColumnInfo ci in myHelper.schema.columnInfo)
|
|
array.SetValue (this[ci.colNo], index ++);
|
|
}
|
|
|
|
public object SyncRoot => this;
|
|
|
|
#endregion
|
|
|
|
#region IEnumerable Members
|
|
|
|
IEnumerator System.Collections.IEnumerable.GetEnumerator() {return new BlueRowEnumerator (this);}
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
|
|
}
|