View AsyncPizze.cs
using System; | |
using System.Threading; | |
using System.Threading.Tasks; | |
namespace AsyncTest | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ |
View SafeAccessArrayByIndexWithOptionals_Swift_3_1.swift
extension Collection where Indices.Iterator.Element == Index { | |
subscript (safe index: Index) -> Generator.Element? { | |
return indices.contains(index) ? self[index] : nil | |
} | |
} | |
class ArrayLookup { | |
private let array = ["Hello", "World"] | |
View OpenAppSettings.swift
guard let settingsURL = URL.init(string: UIApplicationOpenSettingsURLString) else { return } | |
guard UIApplication.shared.canOpenURL(settingsURL) else { return } | |
UIApplication.shared.open(settingsURL, completionHandler: nil ) |
View StaticList.swift
class List<T> { | |
private let listItems: [T] | |
init() { | |
self.listItems = [T]() | |
} | |
init(listItems: [T]) { | |
self.listItems = listItems | |
} |
View ImmutableList.swift
class ImmutableList<T> { | |
private let listItems: [T] | |
init() { | |
self.listItems = [T]() | |
} | |
init(listItems: [T]) { | |
self.listItems = listItems | |
} |
View SingleResponsibilityPrinciple_Application.cs
var sensorValid = | |
new Valid.Sensor("TemSensor 2", new List<double> { 12.4D, 77.2D, 88.1D }); | |
var reportGenerator = | |
new Valid.SensorReportGenerator( | |
new FileSystem(), | |
new PlainTextSensorReportGenerator(sensorValid) | |
); | |
reportGenerator.GenerateAndStoreReport("Report_2.txt"); |
View SingleResponsibilityPrinciple_RefactoredTest.cs
[TestFixture] | |
public class Valid | |
{ | |
[Test] | |
public void TestReportGeneration() | |
{ | |
var sensorName = "TempSensor 1"; | |
var sensor = new Sensor(sensorName, new List<double>() { 1.0D }); | |
var expectedContent = |
View SingleResponsibilityPrinciple_Test.cs
[TestFixture] | |
public class Valid | |
{ | |
[Test] | |
public void TestReportGeneration() | |
{ | |
var sensorName = "TempSensor 1"; | |
var fileName = "FileName.txt"; | |
var sensor = new Sensor(sensorName, new List<double>() { 1.0D }); |
View SingleResponsibilityPrinciple_Valid.cs
public class Sensor | |
{ | |
public string Name { get; } | |
public List<double> MeasuredValues { get; } | |
public double AverageValue | |
=> MeasuredValues.Average(); | |
public double MinimumValue | |
=> MeasuredValues.Min(); | |
public double MaximumValue | |
=> MeasuredValues.Max(); |
NewerOlder