125 lines
2.6 KiB
C#
Raw Normal View History

2016-12-31 15:56:10 +03:00
using System;
2016-11-12 19:02:48 +03:00
using System.Collections;
2016-12-31 15:56:10 +03:00
using System.Collections.Generic;
2016-11-12 19:02:48 +03:00
using System.Linq;
namespace SonicAudioLib.CriMw
{
2016-12-31 15:56:10 +03:00
internal class CriRowRecord
{
public CriField Field { get; set; }
public object Value { get; set; }
}
2016-11-12 19:02:48 +03:00
public class CriRow : IEnumerable
{
2016-12-31 15:56:10 +03:00
private List<CriRowRecord> records = new List<CriRowRecord>();
2016-11-12 19:02:48 +03:00
private CriTable parent;
public object this[CriField criField]
{
get
{
2016-12-31 15:56:10 +03:00
return this[records.FindIndex(record => record.Field == criField)];
2016-11-12 19:02:48 +03:00
}
set
{
2016-12-31 15:56:10 +03:00
this[records.FindIndex(record => record.Field == criField)] = value;
2016-11-12 19:02:48 +03:00
}
}
public object this[int index]
{
get
{
2016-12-31 15:56:10 +03:00
if (index < 0 || index >= records.Count)
{
return null;
}
return records[index].Value;
2016-11-12 19:02:48 +03:00
}
set
{
2016-12-31 15:56:10 +03:00
if (index < 0 || index >= records.Count)
{
return;
}
records[index].Value = value;
2016-11-12 19:02:48 +03:00
}
}
public object this[string name]
{
get
{
2016-12-31 15:56:10 +03:00
return this[records.FindIndex(record => record.Field.FieldName == name)];
2016-11-12 19:02:48 +03:00
}
set
{
2016-12-31 15:56:10 +03:00
this[records.FindIndex(record => record.Field.FieldName == name)] = value;
2016-11-12 19:02:48 +03:00
}
}
public CriTable Parent
{
get
{
return parent;
}
internal set
{
parent = value;
}
}
2016-12-31 15:56:10 +03:00
internal List<CriRowRecord> Records
2016-11-12 19:02:48 +03:00
{
get
{
return records;
}
}
public int FieldCount
{
get
{
return records.Count;
}
}
public object[] GetValueArray()
{
object[] values = new object[records.Count];
for (int i = 0; i < records.Count; i++)
{
2016-12-31 15:56:10 +03:00
values[i] = records[i].Value;
2016-11-12 19:02:48 +03:00
}
return values;
}
public IEnumerator GetEnumerator()
{
2016-12-31 15:56:10 +03:00
foreach (var record in records)
2016-11-12 19:02:48 +03:00
{
2016-12-31 15:56:10 +03:00
yield return record.Value;
2016-11-12 19:02:48 +03:00
}
yield break;
}
internal CriRow(CriTable parent)
{
this.parent = parent;
}
}
}