Skip to content

Commit

Permalink
test concept
Browse files Browse the repository at this point in the history
  • Loading branch information
nimrof committed Apr 4, 2024
1 parent 3c05064 commit fcc1349
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 74 deletions.
77 changes: 3 additions & 74 deletions libEDSsharp/eds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ public class DcfExport : EdsExport
/// <summary>
/// Section of info in EDS or DCF file
/// </summary>
public class InfoSection
public partial class InfoSection
{
protected Dictionary<string, string> section;

Expand All @@ -344,24 +344,6 @@ public enum Filetype
File_DCF
}

public virtual void Parse(Dictionary<string, string> section,string sectionname)
{

this.section = section;

FieldInfo[] fields = this.GetType().GetFields();

foreach (FieldInfo f in fields)
{
if(Attribute.IsDefined(f, typeof(EdsExport)))
GetField(f.Name, f.Name);

if (Attribute.IsDefined(f, typeof(DcfExport)))
GetField(f.Name, f.Name);
}

}

public bool GetField(string name, string varname)
{
FieldInfo f = null;
Expand Down Expand Up @@ -450,80 +432,27 @@ public override string ToString()

return msg;
}
/// <summary>
/// Write object to stream
/// </summary>
/// <param name="writer">stream to write the data to</param>
/// <param name="ft">file type</param>
public void Write(StreamWriter writer, Filetype ft)
{
writer.WriteLine("[" + edssection + "]");
Type tx = this.GetType();
FieldInfo[] fields = this.GetType().GetFields();

foreach (FieldInfo f in fields)
{

if ((ft==Filetype.File_EDS) && (!Attribute.IsDefined(f, typeof(EdsExport))))
continue;

if ((ft == Filetype.File_DCF) && (!(Attribute.IsDefined(f, typeof(DcfExport)) || Attribute.IsDefined(f, typeof(EdsExport)))))
continue;

if (f.GetValue(this) == null)
continue;

EdsExport ex = (EdsExport)f.GetCustomAttribute(typeof(EdsExport));

bool comment = ex.IsReadOnly();

if (f.FieldType.Name == "Boolean")
{
writer.WriteLine(string.Format("{2}{0}={1}", f.Name, ((bool)f.GetValue(this)) == true ? 1 : 0,comment==true?";":""));
}
else
{
writer.WriteLine(string.Format("{2}{0}={1}", f.Name, f.GetValue(this).ToString(), comment == true ? ";" : ""));
}
}

writer.WriteLine("");

}

}


public class MandatoryObjects : SupportedObjects
public partial class MandatoryObjects : SupportedObjects
{
public MandatoryObjects()
: base()
{
infoheader = "Mandatory Objects";
edssection = "MandatoryObjects";
}

public MandatoryObjects(Dictionary<string, string> section)
: this()
{
Parse(section);
}
}

public class OptionalObjects : SupportedObjects
public partial class OptionalObjects : SupportedObjects
{
public OptionalObjects()
: base()
{
infoheader = "Optional Objects";
edssection = "OptionalObjects";
}

public OptionalObjects(Dictionary<string, string> section)
: this()
{
Parse(section);
}
}

public class ManufacturerObjects : SupportedObjects
Expand Down
102 changes: 102 additions & 0 deletions libEDSsharp/edsImportExport.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
This file is part of libEDSsharp.
libEDSsharp is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
libEDSsharp is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libEDSsharp. If not, see <http://www.gnu.org/licenses/>.
Copyright(c) 2016 - 2019 Robin Cornelius <[email protected]>
*/

using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;

namespace libEDSsharp
{
public partial class InfoSection
{
public virtual void Parse(Dictionary<string, string> section, string sectionname)
{
this.section = section;

FieldInfo[] fields = this.GetType().GetFields();

foreach (FieldInfo f in fields)
{
if (Attribute.IsDefined(f, typeof(EdsExport)))
GetField(f.Name, f.Name);

if (Attribute.IsDefined(f, typeof(DcfExport)))
GetField(f.Name, f.Name);
}
}

/// <summary>
/// Write object to stream
/// </summary>
/// <param name="writer">stream to write the data to</param>
/// <param name="ft">file type</param>
public void Write(StreamWriter writer, Filetype ft)
{
writer.WriteLine("[" + edssection + "]");
Type tx = this.GetType();
FieldInfo[] fields = this.GetType().GetFields();

foreach (FieldInfo f in fields)
{
if ((ft == Filetype.File_EDS) && (!Attribute.IsDefined(f, typeof(EdsExport))))
continue;

if ((ft == Filetype.File_DCF) && (!(Attribute.IsDefined(f, typeof(DcfExport)) || Attribute.IsDefined(f, typeof(EdsExport)))))
continue;

if (f.GetValue(this) == null)
continue;

EdsExport ex = (EdsExport)f.GetCustomAttribute(typeof(EdsExport));

bool comment = ex.IsReadOnly();

if (f.FieldType.Name == "Boolean")
{
writer.WriteLine(string.Format("{2}{0}={1}", f.Name, ((bool)f.GetValue(this)) == true ? 1 : 0, comment == true ? ";" : ""));
}
else
{
writer.WriteLine(string.Format("{2}{0}={1}", f.Name, f.GetValue(this).ToString(), comment == true ? ";" : ""));
}
}

writer.WriteLine("");
}
}

public partial class MandatoryObjects : SupportedObjects
{
public MandatoryObjects(Dictionary<string, string> section)
: this()
{
Parse(section);
}
}

public partial class OptionalObjects : SupportedObjects
{
public OptionalObjects(Dictionary<string, string> section)
: this()
{
Parse(section);
}
}
}

0 comments on commit fcc1349

Please sign in to comment.