This commit is contained in:
Kirill 2024-11-17 13:31:27 +04:00
parent 9c27b69e17
commit 78e2098513
13 changed files with 26 additions and 66 deletions

View File

@ -0,0 +1,25 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components
{
public partial class testComponent : Component
{
public testComponent()
{
InitializeComponent();
}
public testComponent(IContainer container)
{
container.Add(this);
InitializeComponent();
}
}
}

View File

@ -4,7 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls
namespace MyUserControls.VisualComponents
{
public class ValueOutOfRangeException : Exception
{

View File

@ -1,65 +0,0 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyUserControls.Components
{
public partial class testComponent : Component
{
public testComponent()
{
InitializeComponent();
_fileName = string.Empty;
}
public testComponent(IContainer container)
{
container.Add(this);
InitializeComponent();
_fileName = string.Empty;
}
private string _fileName;
public string FileName
{
set
{
if (string.IsNullOrEmpty(value))
{
return;
}
if (!value.EndsWith(".txt"))
{
throw new ArgumentException("No txt file");
}
_fileName = value;
}
}
public bool SaveToFile(string[] texts)
{
CheckFileExsists();
using var writer = new StreamWriter(_fileName, true);
foreach (var text in texts)
{
writer.WriteLine(text);
}
writer.Flush();
return true;
}
private void CheckFileExsists()
{
if (string.IsNullOrEmpty(_fileName))
{
throw new ArgumentNullException(_fileName);
}
if (!File.Exists(_fileName))
{
throw new FileNotFoundException(_fileName);
}
}
}
}