Добавьте файлы проекта.
This commit is contained in:
parent
97e968e3e1
commit
d406f18d9c
25
delphi2csharp.sln
Normal file
25
delphi2csharp.sln
Normal file
@ -0,0 +1,25 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31424.327
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "delphi2csharp", "delphi2csharp\delphi2csharp.csproj", "{D722F27B-693F-471A-8166-8A7912531A4F}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D722F27B-693F-471A-8166-8A7912531A4F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D722F27B-693F-471A-8166-8A7912531A4F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D722F27B-693F-471A-8166-8A7912531A4F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D722F27B-693F-471A-8166-8A7912531A4F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {61D41C58-CBDF-4C21-BD22-DEFBD590FEF7}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
159
delphi2csharp/TStringList.cs
Normal file
159
delphi2csharp/TStringList.cs
Normal file
@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
|
||||
namespace delphi2csharp
|
||||
{
|
||||
public class TStringList
|
||||
{
|
||||
private List<string> FLines;
|
||||
private List<object> FObjects;
|
||||
private TStringListType type = TStringListType.sltBoth;
|
||||
public TStringListType Type { get => type; set => type = value; }
|
||||
public int Count => FLines.Count;
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is TStringList list &&
|
||||
Count == list.Count;
|
||||
}
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Count);
|
||||
}
|
||||
public void Add(string AString)
|
||||
{
|
||||
if (!(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
FLines.Add(AString);
|
||||
if (!(type == TStringListType.sltStringsOnly))
|
||||
{
|
||||
FObjects.Add(AString);
|
||||
}
|
||||
}
|
||||
}
|
||||
public void Add(object AObject)
|
||||
{
|
||||
if (!(type == TStringListType.sltStringsOnly))
|
||||
{
|
||||
if (!(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
FLines.Add(AObject.ToString());
|
||||
|
||||
}
|
||||
FObjects.Add(AObject);
|
||||
}
|
||||
}
|
||||
public void Add(string AString, object AObject)
|
||||
{
|
||||
if (!(type == TStringListType.sltStringsOnly) && !(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
FLines.Add(AString);
|
||||
FObjects.Add(AObject);
|
||||
}
|
||||
}
|
||||
public (string, object) Get(int Index) => (FLines[Index], FObjects[Index]);
|
||||
public string GetString(int Index)
|
||||
{
|
||||
string result = "";
|
||||
if (!(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
result = FLines[Index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public object GetObject(int Index)
|
||||
{
|
||||
object result = null;
|
||||
if (!(type == TStringListType.sltStringsOnly))
|
||||
{
|
||||
result = FObjects[Index];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public void Delete(int Index)
|
||||
{
|
||||
if (!(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
FLines.RemoveAt(Index);
|
||||
}
|
||||
if (!(type == TStringListType.sltStringsOnly))
|
||||
{
|
||||
FObjects.RemoveAt(Index);
|
||||
}
|
||||
}
|
||||
public int IndexOf(string AString) => FLines.IndexOf(AString);
|
||||
public int IndexOf(object AObject) => FObjects.IndexOf(AObject);
|
||||
public void Sort()
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case TStringListType.sltStringsOnly:
|
||||
FLines.Sort();
|
||||
break;
|
||||
case TStringListType.sltObjectsOnly:
|
||||
FObjects.Sort();
|
||||
break;
|
||||
case TStringListType.sltBoth:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void Clear()
|
||||
{
|
||||
FLines.Clear();
|
||||
FObjects.Clear();
|
||||
}
|
||||
public void Assign(List<string> ALines)
|
||||
{
|
||||
if (!(type == TStringListType.sltStringsOnly))
|
||||
{
|
||||
throw new ArgumentException("Assign method works in TStringList only for the sltStringsOnly type. Your changes are not applied!");
|
||||
}
|
||||
Clear();
|
||||
FLines.AddRange(ALines);
|
||||
}
|
||||
public string DelimetedText(char Delimeter)
|
||||
{
|
||||
string result = "";
|
||||
if (!(type == TStringListType.sltObjectsOnly))
|
||||
{
|
||||
for (int i = 0; i < FLines.Count; i++)
|
||||
{
|
||||
result = $"{result}{Delimeter}{FLines[i]}";
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public string Text()
|
||||
{
|
||||
char Delim = '\n';
|
||||
return DelimetedText(Delim);
|
||||
}
|
||||
public void LoadFromFile(string FileName)
|
||||
{
|
||||
if (!File.Exists(FileName))
|
||||
{
|
||||
throw new FileNotFoundException();
|
||||
}
|
||||
StreamReader sr = new StreamReader(FileName);
|
||||
string line = sr.ReadLine();
|
||||
while (line != null)
|
||||
{
|
||||
FLines.Add(line);
|
||||
line = sr.ReadLine();
|
||||
}
|
||||
sr.Close();
|
||||
}
|
||||
public void SaveToFile(string FileName)
|
||||
{
|
||||
StreamWriter sw = new StreamWriter(FileName);
|
||||
for (int i = 0; i < FLines.Count; i++)
|
||||
{
|
||||
sw.WriteLine(FLines[i]);
|
||||
}
|
||||
sw.Close();
|
||||
}
|
||||
}
|
||||
}
|
13
delphi2csharp/TStringListType.cs
Normal file
13
delphi2csharp/TStringListType.cs
Normal file
@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace delphi2csharp
|
||||
{
|
||||
public enum TStringListType
|
||||
{
|
||||
sltStringsOnly, //Только строки -- сортировка по строкам включена, имеющиеся объекты удалит
|
||||
sltObjectsOnly, //Только объекты -- сортировка по объектам включена
|
||||
sltBoth //И строки, и объекты -- сортировка отключена
|
||||
}
|
||||
}
|
12
delphi2csharp/delphi2csharp.csproj
Normal file
12
delphi2csharp/delphi2csharp.csproj
Normal file
@ -0,0 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||
<Version>0.1.0</Version>
|
||||
<Authors>Alexander Babaev</Authors>
|
||||
<Product>delphi2c#</Product>
|
||||
<Description>Library to import some useful functions from Delphi language to C# language.</Description>
|
||||
<Copyright />
|
||||
</PropertyGroup>
|
||||
|
||||
</Project>
|
29
delphi2csharp/delphimethods.cs
Normal file
29
delphi2csharp/delphimethods.cs
Normal file
@ -0,0 +1,29 @@
|
||||
using System;
|
||||
|
||||
namespace delphi2csharp
|
||||
{
|
||||
static public class delphi
|
||||
{
|
||||
public static string IncludeTrailingBackslash(string Path)
|
||||
{
|
||||
string result = Path;
|
||||
int Index = Path.Length - 1;
|
||||
if (Path[Index] != '\\')
|
||||
{
|
||||
result = $"{Path}\\";
|
||||
}
|
||||
return result;
|
||||
}
|
||||
public static string IntToStr(int AInt) => AInt.ToString();
|
||||
public static string IntToStr(long AInt) => AInt.ToString();
|
||||
public static long StrToInt(string AStr)
|
||||
{
|
||||
long result;
|
||||
if (!long.TryParse(AStr, out result))
|
||||
{
|
||||
result = 0;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user