Skip to content

Instantly share code, notes, and snippets.

@ch-hristov
Created May 5, 2015 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ch-hristov/905313ef009aa71b69a9 to your computer and use it in GitHub Desktop.
Save ch-hristov/905313ef009aa71b69a9 to your computer and use it in GitHub Desktop.
Delphi properties to C# properties
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GenerateProperties
{
class Program
{
static void Main(string[] args)
{
string fileName = "";
const int startLine = 45;
string write = string.Empty;
string toClass = "string"; ;
string dir = Directory.GetCurrentDirectory();
using (var fs = File.Open(Path.Combine(dir, fileName), FileMode.Open))
using (var sr = new StreamReader(fs))
{
int i = 1;
while (i++ < 45) sr.ReadLine();
while (!sr.EndOfStream)
{
string line = sr.ReadLine();
if (line.Length <= 10 && line.Contains("("))
{
write += "new " + toClass + "() {\n";
}
else
{
if (line.Length <= 10 && line.Contains(")"))
{
write += "},\n";
}
else
{
var spl = line.Split(':');
spl[1] = spl[1].Replace("'", "\"");
if (spl[1].Where(x => x == '"').Count() == 1)
{
spl[1] += "\",";
}
if (spl[1].Contains(";"))
spl[1] = spl[1].Replace(';', ',');
if (spl[1].Contains("TRUE")) spl[1] = spl[1].Replace("TRUE", "true");
if (spl[1].Contains("FALSE")) spl[1] = spl[1].Replace("FALSE", "false");
write += spl[0] + " = " + spl[1];
write += "\n";
}
}
i++;
if (i == 1204) break;
}
}
using (var fs = File.Create(Directory.GetCurrentDirectory() + "newData.cs"))
using (var sw = new StreamWriter(fs))
sw.Write(write);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment