Skip to content

Commit

Permalink
Final updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Leonard Sperry committed Nov 27, 2021
1 parent 814f0bc commit 524db5e
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CsvProcessor/CsvProcessor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="5.0.0" />
</ItemGroup>

<ItemGroup>
<None Update="FakeData.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
2 changes: 1 addition & 1 deletion CsvProcessor/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ static void Main(string[] args)
{
//ThreadPool.SetMaxThreads(100, 100);
FileProcessor processor = new FileProcessor(new FakeWidgetLogic(), new FakeWidgetProvider());
processor.ProcessFileWithSemaphoreFixed(@"S:\Code\TaoOfCode\CsvProcessor\FakeData.txt").Wait();
processor.ProcessFileWithSemaphoreFixed(@".\FakeData.txt").Wait();
}

static void initial(string[] args)
Expand Down
File renamed without changes.
5 changes: 3 additions & 2 deletions Samples/SOLID/LSP/SomeBusinessService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ namespace Samples.SOLID.LSP
{
abstract class SomeBusinessServiceBase
{
private List<SomeBusinessObject> _objects;
protected abstract void LoadData();
protected List<SomeBusinessObject> _objects;

public abstract void LoadData();

public virtual void Render()
{
Expand Down
69 changes: 69 additions & 0 deletions Samples/SOLID/OCP/InvoiceService.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Samples.SOLID.OCP
{
enum LineItemType
{
Product, Service, Tax
}

class LineItemValidator
{
public bool IsValid(LineItem lineItem)
{
switch (lineItem.LineItemType)
{
case LineItemType.Product:
return ValidateProduct(lineItem);
case LineItemType.Service:
return ValidateService(lineItem);
case LineItemType.Tax:
return ValidateTax(lineItem);
default:
throw new Exception("unrecognized type");
}
}

private bool ValidateTax(LineItem lineItem)
{
return lineItem.Discount == 0;
}

private bool ValidateService(LineItem lineItem)
{
return lineItem.Description != null;
}

private bool ValidateProduct(LineItem lineItem)
{
return lineItem.Amount >= 0;
}
}

abstract class LineItem
{
public LineItemType LineItemType { get; set; }
public decimal Amount { get; set; }
public string Description { get; set; }
public decimal Discount { get; set; }
}

class ExtendableLineItemValidator
{
List<Func<LineItem, bool>> _validations =
new List<Func<LineItem, bool>>();

void AddValidation(Func<LineItem, bool> validation)
{
_validations.Add(validation);
}

bool Validate(LineItem lineItem)
{
return _validations.All(v => v(lineItem));
}
}
}
5 changes: 4 additions & 1 deletion Samples/WhenThouYields/Linq/LinqExamples.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@ object CountExample(IEnumerable<object> someCollection)
{
if (someCollection.Count() > 1)
{
//iterate the collection
foreach (var item in someCollection)
{
// do work
}
}

return new {
Expand Down

0 comments on commit 524db5e

Please sign in to comment.