This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cinst wixtoolset -y | |
cinst firefox -y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Project Sdk="Microsoft.NET.Sdk" ToolsVersion="15.0"> | |
<PropertyGroup> | |
<OutputType>Exe</OutputType> | |
<TargetFramework>netcoreapp1.0</TargetFramework> | |
</PropertyGroup> | |
<ItemGroup> | |
<Compile Include="**\*.cs" /> | |
<EmbeddedResource Include="**\*.resx" /> | |
</ItemGroup> | |
<ItemGroup> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class IntegerParser | |
{ | |
private const int MinDigit = '0'; | |
private const int MaxDigit = '9'; | |
public static bool TryParse(object number, out int result) | |
{ | |
if (number is int) | |
{ | |
result = (int)number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
foreach (var number in new object[] { 123, "2017", "-1", "1a2b3c", '5' }) | |
{ | |
try | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool TryParse(object number, out int result) | |
{ | |
switch (number) | |
{ | |
case int i: | |
result = i; | |
return true; | |
case string s: | |
return ParseString(s, out result); | |
default: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static bool TryParse(object number, out int result) | |
{ | |
switch (number) | |
{ | |
case int i: | |
result = i; | |
return true; | |
case string s: | |
bool ParseString(string str, out int res) | |
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
try | |
{ | |
if (IntegerParser.TryParse(number, out int result)) | |
{ | |
Console.WriteLine($"Parsed {number.GetType()} {number}, got {result}"); | |
} | |
else | |
{ | |
Console.WriteLine($"Could not parse {number.GetType()} {number}"); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ParsingResult | |
{ | |
public bool IsSuccessful { get; set; } | |
public int Result { get; set; } | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static ParsingResult TryParse(object number) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static (bool success, int result) TryParse(object number) | |
{ | |
switch (number) | |
{ | |
case int i: | |
return (true, i); | |
case string s: | |
(bool isParsed, int value) ParseString(string str) | |
{ | |
var res = 0; |
OlderNewer