Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #430 from moh-hassan/net40-net45
add support for net40 and net45
- Loading branch information
Showing
9 changed files
with
203 additions
and
57 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<Project> | ||
<PropertyGroup> | ||
<NoWarn>CS1591;CS0219;8002;NU5125</NoWarn> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="$(TargetFramework.StartsWith('net4'))"> | ||
<DefineConstants>$(DefineConstants);NETFRAMEWORK</DefineConstants> | ||
</PropertyGroup> | ||
</Project> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> | ||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> | ||
<ProductVersion>12.0.0</ProductVersion> | ||
<SchemaVersion>2.0</SchemaVersion> | ||
<ProjectGuid>{F9D3B288-1A73-4C91-8ED7-11ED1704B817}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<RootNamespace>ReadText.Demo</RootNamespace> | ||
<AssemblyName>ReadText.Demo</AssemblyName> | ||
<TargetFrameworks>net40;net45;net461;netcoreapp2.1;netcoreapp2.0</TargetFrameworks> | ||
<GenerateAssemblyInfo>false</GenerateAssemblyInfo> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> | ||
<DebugSymbols>true</DebugSymbols> | ||
<DebugType>full</DebugType> | ||
<Optimize>false</Optimize> | ||
<OutputPath>bin\Debug</OutputPath> | ||
<DefineConstants>DEBUG;</DefineConstants> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Externalconsole>true</Externalconsole> | ||
</PropertyGroup> | ||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> | ||
<DebugType>full</DebugType> | ||
<Optimize>true</Optimize> | ||
<OutputPath>bin\Release</OutputPath> | ||
<ErrorReport>prompt</ErrorReport> | ||
<WarningLevel>4</WarningLevel> | ||
<Externalconsole>true</Externalconsole> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Reference Include="CommandLine, Version=2.0.275.0, Culture=neutral, PublicKeyToken=de6f01bd326f8c32, processorArchitecture=MSIL"> | ||
<HintPath>packages\CommandLineParser.2.1.1-beta\lib\net40\CommandLine.dll</HintPath> | ||
</Reference> | ||
<Reference Include="System" /> | ||
<Reference Include="System.Core" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<Compile Include="..\..\src\SharedAssemblyInfo.cs"> | ||
<Link>Properties\SharedAssemblyInfo.cs</Link> | ||
</Compile> | ||
<Compile Include="Program.cs" /> | ||
<Compile Include="Properties\AssemblyInfo.cs" /> | ||
<Compile Include="Options.cs" /> | ||
</ItemGroup> | ||
<ItemGroup> | ||
<None Include="packages.config"> | ||
<SubType>Designer</SubType> | ||
</None> | ||
<ProjectReference Include="..\..\src\CommandLine\CommandLine.csproj" /> | ||
</ItemGroup> | ||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> | ||
</Project> |
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace CommandLine | ||
{ | ||
#if NET40 | ||
|
||
internal static class IntrospectionExtensions | ||
{ | ||
public static Type GetTypeInfo(this Type type) | ||
{ | ||
return type; | ||
} | ||
} | ||
#endif | ||
} | ||
|
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
using CommandLine.Text; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using Xunit; | ||
|
||
namespace CommandLine.Tests.Unit | ||
{ | ||
//Reference: PR# 392 | ||
public class Issue389Tests | ||
{ | ||
|
||
private const int ERROR_SUCCESS = 0; | ||
|
||
// Test method (xUnit) which fails | ||
[Fact] | ||
public void CallMain_GiveHelpArgument_ExpectSuccess() | ||
{ | ||
var result = Program.__Main(new[] { "--help" }); | ||
|
||
Assert.Equal(ERROR_SUCCESS, result); | ||
} | ||
|
||
// main program | ||
internal class Program | ||
{ | ||
|
||
|
||
internal static int __Main(string[] args) | ||
{ | ||
bool hasError = false; | ||
bool helpOrVersionRequested = false; | ||
|
||
ParserResult<Options> parsedOptions = Parser.Default.ParseArguments<Options>(args) | ||
.WithNotParsed(errors => { | ||
helpOrVersionRequested = errors.Any( | ||
x => x.Tag == ErrorType.HelpRequestedError | ||
|| x.Tag == ErrorType.VersionRequestedError); | ||
hasError = true; | ||
}); | ||
|
||
if(helpOrVersionRequested) | ||
{ | ||
return ERROR_SUCCESS; | ||
} | ||
|
||
// Execute as a normal call | ||
// ... | ||
return ERROR_SUCCESS; | ||
} | ||
|
||
} | ||
|
||
// Options | ||
internal class Options | ||
{ | ||
|
||
[Option('c', "connectionString", Required = true, HelpText = "Texts.ExplainConnection")] | ||
public string ConnectionString { get; set; } | ||
|
||
[Option('j', "jobId", Required = true, HelpText = "Texts.ExplainJob")] | ||
public int JobId { get; set; } | ||
|
||
[Usage(ApplicationAlias = "Importer.exe")] | ||
public static IEnumerable<Example> Examples | ||
{ | ||
get => new[] { | ||
new Example("Texts.ExplainExampleExecution", new Options() { | ||
ConnectionString="Server=MyServer;Database=MyDatabase", | ||
JobId = 5 | ||
}), | ||
}; | ||
} | ||
|
||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using Xunit; | ||
|
||
namespace CommandLine.Tests.Unit | ||
{ | ||
|
||
//MailAndSmsWarningSenderTests | ||
public class Issue424Tests | ||
{ | ||
private MailAndSmsWarningSender _sut; | ||
|
||
public Issue424Tests() | ||
{ | ||
_sut = new MailAndSmsWarningSender(); | ||
} | ||
|
||
[Fact] | ||
public void SendSmsOnWarning() | ||
{ | ||
//Arrange | ||
void Action() => _sut.ParseArgumentsAndRun( | ||
new[] { "--task", "MailAndSmsWarningSender", "--test", "hejtest" }); | ||
// Act & Assert | ||
Assert.Throws<NotImplementedException>((Action)Action); | ||
} | ||
} | ||
|
||
public class MailAndSmsWarningSender | ||
{ | ||
internal class Options | ||
{ | ||
[Option("task")] | ||
public string Task { get; set; } | ||
} | ||
|
||
public void ParseArgumentsAndRun(string[] args) | ||
{ | ||
Parser.Default.ParseArguments<Options>(args) | ||
.WithParsed(ExecuteTaskWithOptions) | ||
.WithNotParsed(HandleParseError); | ||
} | ||
|
||
private void HandleParseError(IEnumerable<Error> errs) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
|
||
private void ExecuteTaskWithOptions(Options opts) | ||
{ | ||
Console.WriteLine("Executing"); | ||
} | ||
|
||
} | ||
} |