diff options
| author | Mirta <mirta@twine-s.com> | 2020-12-30 16:39:52 +0200 |
|---|---|---|
| committer | Mirta <mirta@twine-s.com> | 2020-12-30 16:39:52 +0200 |
| commit | 00a491d93733d4625ad329b2ba8237f445364b3f (patch) | |
| tree | 4b24c6fa78d7648f4bb7cefafa464bb0b063fec4 /Software/Visual_Studio/Tango.CSV | |
| parent | 124ad4150f80c6846fdee41dbbda9848c105f6e5 (diff) | |
| download | Tango-00a491d9.tar.gz Tango-00a491d9.zip | |
merge
Diffstat (limited to 'Software/Visual_Studio/Tango.CSV')
| -rw-r--r-- | Software/Visual_Studio/Tango.CSV/CsvFile.cs | 16 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.CSV/CsvFileReader.cs | 32 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.CSV/CsvOrderAttribute.cs | 19 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.CSV/DynamicCsvFile.cs | 102 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.CSV/DynamicCsvFileColumn.cs | 13 | ||||
| -rw-r--r-- | Software/Visual_Studio/Tango.CSV/Tango.CSV.csproj | 3 |
6 files changed, 8 insertions, 177 deletions
diff --git a/Software/Visual_Studio/Tango.CSV/CsvFile.cs b/Software/Visual_Studio/Tango.CSV/CsvFile.cs index 9b1d23bb3..1f21ce6e8 100644 --- a/Software/Visual_Studio/Tango.CSV/CsvFile.cs +++ b/Software/Visual_Studio/Tango.CSV/CsvFile.cs @@ -73,18 +73,6 @@ namespace Tango.CSV } /// <summary> - /// Gets the columns. - /// </summary> - /// <typeparam name="T"></typeparam> - /// <param name="csvSource">The CSV source.</param> - /// <returns></returns> - public static IEnumerable<string> GetColumns<T>(CsvSource csvSource) where T : new() - { - var csvFileReader = new CsvFileReader<T>(csvSource); - return csvFileReader.Columns; - } - - /// <summary> /// Gets the field separator. /// </summary> /// <value> @@ -106,7 +94,7 @@ namespace Tango.CSV /// <value> /// The columns. /// </value> - public IEnumerable<String> Columns { get; protected set; } + public IEnumerable<String> Columns { get; private set; } /// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. @@ -305,7 +293,7 @@ namespace Tango.CSV if (pi == null) //Then try get by column index, { pi = typeof(T).GetProperties()[index]; - pi = typeof(T).GetProperties()[index]; //Workaround for some weired problem that makes the program not take the value. + pi = typeof(T).GetProperties()[index]; } if (CsvFile.UseLambdas) diff --git a/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs b/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs index 79f716aab..6d1deded2 100644 --- a/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs +++ b/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs @@ -35,8 +35,6 @@ namespace Tango.CSV private readonly char textQualifier; private readonly StringBuilder parseFieldResult = new StringBuilder(); - - /// <summary> /// Initializes a new instance of the <see cref="CsvFileReader{T}"/> class. /// </summary> @@ -242,39 +240,22 @@ namespace Tango.CSV /// <param name="c">The c.</param> /// <param name="staticMember">if set to <c>true</c> [static member].</param> /// <returns></returns> - private static Action<T, string> FindSetter(string c, bool staticMember, int? index = null) + private static Action<T, string> FindSetter(string c, bool staticMember) { var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase | (staticMember ? BindingFlags.Static : BindingFlags.Instance); Action<T, string> action = null; - PropertyInfo pi = typeof(T).GetProperty(c, flags); if (pi != null) { var pFunc = StringToObject(pi.PropertyType); action = EmitSetValueAction(pi, pFunc); } - - if (action == null) - { - FieldInfo fi = typeof(T).GetField(c, flags); - if (fi != null) - { - var fFunc = StringToObject(fi.FieldType); - action = EmitSetValueAction(fi, fFunc); - } - } - - if (action == null && index != null) + FieldInfo fi = typeof(T).GetField(c, flags); + if (fi != null) { - var propByIndex = typeof(T).GetProperties(flags).SingleOrDefault(x => x.GetCustomAttribute<CsvOrderAttribute>() != null && x.GetCustomAttribute<CsvOrderAttribute>().Index == index); - - if (propByIndex != null) - { - var pFunc = StringToObject(propByIndex.PropertyType); - action = EmitSetValueAction(propByIndex, pFunc); - } + var fFunc = StringToObject(fi.FieldType); + action = EmitSetValueAction(fi, fFunc); } - return action; } @@ -311,7 +292,7 @@ namespace Tango.CSV Action<T, string> action = null; if (columnName.IndexOf(' ') >= 0) columnName = columnName.Replace(" ", ""); - action = FindSetter(columnName, false, i) ?? FindSetter(columnName, true, i); + action = FindSetter(columnName, false) ?? FindSetter(columnName, true); list.Add(action); } @@ -422,7 +403,6 @@ namespace Tango.CSV break; } this.columns = readColumns.ToArray(); - Columns = this.columns; } /// <summary> diff --git a/Software/Visual_Studio/Tango.CSV/CsvOrderAttribute.cs b/Software/Visual_Studio/Tango.CSV/CsvOrderAttribute.cs deleted file mode 100644 index cf04334cb..000000000 --- a/Software/Visual_Studio/Tango.CSV/CsvOrderAttribute.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.CSV -{ - [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] - public class CsvOrderAttribute : Attribute - { - public int Index { get; set; } - - public CsvOrderAttribute(int index) - { - Index = index; - } - } -} diff --git a/Software/Visual_Studio/Tango.CSV/DynamicCsvFile.cs b/Software/Visual_Studio/Tango.CSV/DynamicCsvFile.cs deleted file mode 100644 index ec04de3ff..000000000 --- a/Software/Visual_Studio/Tango.CSV/DynamicCsvFile.cs +++ /dev/null @@ -1,102 +0,0 @@ -using System; -using System.Collections; -using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.CSV -{ - public class DynamicCsvFile : IDisposable - { - private bool _isDisposed; - private Stream _stream; - private StreamWriter _writer; - private bool _disposeStream; - private bool _columnsWritten; - - public List<DynamicCsvFileColumn> Columns { get; set; } - - public DynamicCsvFile() - { - Columns = new List<DynamicCsvFileColumn>(); - } - - public DynamicCsvFile(Stream stream) : this() - { - _stream = stream; - _writer = new StreamWriter(_stream); - } - - public DynamicCsvFile(String file) : this(new FileStream(file, FileMode.Create)) - { - _disposeStream = true; - } - - private void WriteColumns() - { - if (!_columnsWritten) - { - _columnsWritten = true; - _writer.WriteLine(String.Join(",", Columns.Select(x => x.Name))); - } - } - - public void Append(params Object[] values) - { - Append((IEnumerable)values); - } - - public void Append<T>(IEnumerable<T> values, Func<T, Object> modifier = null) - { - if (modifier != null) - { - Append((IEnumerable)values, (x) => { return modifier((T)x); }); - } - else - { - Append((IEnumerable)values, null); - } - } - - public void Append(IEnumerable values, Func<Object, Object> modifier = null) - { - if (!_columnsWritten) - { - WriteColumns(); - } - - List<String> valuesStr = new List<string>(); - - foreach (var value in values) - { - Object finalValue = value; - - if (modifier != null) - { - finalValue = modifier(finalValue); - } - - valuesStr.Add(finalValue != null ? finalValue.ToString() : String.Empty); - } - - _writer.WriteLine(String.Join(",", valuesStr)); - _writer.Flush(); - } - - public void Dispose() - { - if (!_isDisposed) - { - _isDisposed = true; - - if (_disposeStream) - { - _writer?.Dispose(); - _stream?.Dispose(); - } - } - } - } -} diff --git a/Software/Visual_Studio/Tango.CSV/DynamicCsvFileColumn.cs b/Software/Visual_Studio/Tango.CSV/DynamicCsvFileColumn.cs deleted file mode 100644 index c8fd850e7..000000000 --- a/Software/Visual_Studio/Tango.CSV/DynamicCsvFileColumn.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace Tango.CSV -{ - public class DynamicCsvFileColumn - { - public String Name { get; set; } - } -} diff --git a/Software/Visual_Studio/Tango.CSV/Tango.CSV.csproj b/Software/Visual_Studio/Tango.CSV/Tango.CSV.csproj index b6743bede..eee9649e6 100644 --- a/Software/Visual_Studio/Tango.CSV/Tango.CSV.csproj +++ b/Software/Visual_Studio/Tango.CSV/Tango.CSV.csproj @@ -85,10 +85,7 @@ <Compile Include="CsvFileLinqExtensions.cs" /> <Compile Include="CsvFileReader.cs" /> <Compile Include="CsvIgnoreAttribute.cs" /> - <Compile Include="CsvOrderAttribute.cs" /> <Compile Include="CsvSource.cs" /> - <Compile Include="DynamicCsvFile.cs" /> - <Compile Include="DynamicCsvFileColumn.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> |
