Skip to content

Commit f95050f

Browse files
committed
Add portable class library targeting dotnet.
1 parent 88a192a commit f95050f

File tree

14 files changed

+292
-10
lines changed

14 files changed

+292
-10
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
src/CommandLine/bin/*
22
src/CommandLine/obj
3+
src/CommandLine.dotnet/bin/*
4+
src/CommandLine.dotnet/obj
35
demo/ReadText.Demo/bin/*
46
demo/ReadText.Demo/obj
57
tests/CommandLine.Tests/bin/*

CommandLine.sln

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
Microsoft Visual Studio Solution File, Format Version 12.00
33
# Visual Studio 14
4-
VisualStudioVersion = 14.0.23107.0
4+
VisualStudioVersion = 14.0.24606.1
55
MinimumVisualStudioVersion = 10.0.40219.1
66
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine", "src\CommandLine\CommandLine.csproj", "{E1BD3C65-49C3-49E7-BABA-C60980CB3F20}"
77
EndProject
@@ -23,6 +23,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
2323
EndProject
2424
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine.Tests", "tests\CommandLine.Tests\CommandLine.Tests.csproj", "{0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E}"
2525
EndProject
26+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommandLine.dotnet", "src\CommandLine.dotnet\CommandLine.dotnet.csproj", "{1E72E75F-888A-400E-865C-44251B8013E1}"
27+
EndProject
2628
Global
2729
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2830
Debug|Any CPU = Debug|Any CPU
@@ -37,6 +39,10 @@ Global
3739
{0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E}.Debug|Any CPU.Build.0 = Debug|Any CPU
3840
{0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E}.Release|Any CPU.ActiveCfg = Release|Any CPU
3941
{0A15C4D2-B3E9-43AB-8155-1B39F7AC8A5E}.Release|Any CPU.Build.0 = Release|Any CPU
42+
{1E72E75F-888A-400E-865C-44251B8013E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
43+
{1E72E75F-888A-400E-865C-44251B8013E1}.Debug|Any CPU.Build.0 = Debug|Any CPU
44+
{1E72E75F-888A-400E-865C-44251B8013E1}.Release|Any CPU.ActiveCfg = Release|Any CPU
45+
{1E72E75F-888A-400E-865C-44251B8013E1}.Release|Any CPU.Build.0 = Release|Any CPU
4046
EndGlobalSection
4147
GlobalSection(SolutionProperties) = preSolution
4248
HideSolutionNode = FALSE
Lines changed: 163 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<MinimumVisualStudioVersion>14.0</MinimumVisualStudioVersion>
6+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
7+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
8+
<ProjectGuid>{1E72E75F-888A-400E-865C-44251B8013E1}</ProjectGuid>
9+
<OutputType>Library</OutputType>
10+
<AppDesignerFolder>Properties</AppDesignerFolder>
11+
<RootNamespace>CommandLine</RootNamespace>
12+
<AssemblyName>CommandLine</AssemblyName>
13+
<DefaultLanguage>en-US</DefaultLanguage>
14+
<FileAlignment>512</FileAlignment>
15+
<ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
16+
<TargetFrameworkProfile>
17+
</TargetFrameworkProfile>
18+
<TargetFrameworkVersion>v5.0</TargetFrameworkVersion>
19+
</PropertyGroup>
20+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
21+
<DebugSymbols>true</DebugSymbols>
22+
<DebugType>full</DebugType>
23+
<Optimize>false</Optimize>
24+
<OutputPath>bin\portable-dotnet\Debug\</OutputPath>
25+
<DefineConstants>TRACE;DEBUG;CSX_EITHER_INTERNAL; CSX_REM_EITHER_BEYOND_2; CSX_ENUM_INTERNAL; ERRH_INTERNAL; ERRH_DISABLE_INLINE_METHODS; CSX_MAYBE_INTERNAL; CSX_REM_EITHER_FUNC;PLATFORM_DOTNET</DefineConstants>
26+
<ErrorReport>prompt</ErrorReport>
27+
<WarningLevel>4</WarningLevel>
28+
</PropertyGroup>
29+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
30+
<DebugType>pdbonly</DebugType>
31+
<Optimize>true</Optimize>
32+
<OutputPath>bin\portable-dotnet\Release\</OutputPath>
33+
<DefineConstants>TRACE;CSX_EITHER_INTERNAL; CSX_REM_EITHER_BEYOND_2; CSX_ENUM_INTERNAL; ERRH_INTERNAL; ERRH_DISABLE_INLINE_METHODS; CSX_MAYBE_INTERNAL; CSX_REM_EITHER_FUNC;PLATFORM_DOTNET</DefineConstants>
34+
<ErrorReport>prompt</ErrorReport>
35+
<WarningLevel>4</WarningLevel>
36+
</PropertyGroup>
37+
<ItemGroup>
38+
<!-- A reference to the entire .NET Framework is automatically included -->
39+
<None Include="project.json" />
40+
</ItemGroup>
41+
<PropertyGroup>
42+
<SignAssembly>true</SignAssembly>
43+
</PropertyGroup>
44+
<PropertyGroup>
45+
<AssemblyOriginatorKeyFile>..\..\CommandLine.snk</AssemblyOriginatorKeyFile>
46+
</PropertyGroup>
47+
<ItemGroup>
48+
<Compile Include="..\..\paket-files\gsscoder\railwaysharp\src\RailwaySharp\ErrorHandling.cs">
49+
<Paket>True</Paket>
50+
<Link>Infrastructure/ErrorHandling.cs</Link>
51+
</Compile>
52+
<Compile Include="..\..\paket-files\gsscoder\CSharpx\src\CSharpx\EnumerableExtensions.cs">
53+
<Paket>True</Paket>
54+
<Link>Infrastructure/EnumerableExtensions.cs</Link>
55+
</Compile>
56+
<Compile Include="..\..\paket-files\gsscoder\CSharpx\src\CSharpx\Maybe.cs">
57+
<Paket>True</Paket>
58+
<Link>Infrastructure/Maybe.cs</Link>
59+
</Compile>
60+
</ItemGroup>
61+
<ItemGroup>
62+
<Compile Include="..\SharedAssemblyInfo.cs">
63+
<Link>Properties\SharedAssemblyInfo.cs</Link>
64+
</Compile>
65+
<Compile Include="..\CommandLine\BaseAttribute.cs" />
66+
<Compile Include="..\CommandLine\Core\ArgumentsExtensions.cs" />
67+
<Compile Include="..\CommandLine\Core\KeyValuePairHelper.cs" />
68+
<Compile Include="..\CommandLine\Core\PreprocessorGuards.cs" />
69+
<Compile Include="..\CommandLine\Core\TypeDescriptor.cs" />
70+
<Compile Include="..\CommandLine\Core\Scalar.cs" />
71+
<Compile Include="..\CommandLine\Core\Sequence.cs" />
72+
<Compile Include="..\CommandLine\Core\Switch.cs" />
73+
<Compile Include="..\CommandLine\ErrorExtensions.cs" />
74+
<Compile Include="..\CommandLine\Infrastructure\EnumerableExtensions`1.cs" />
75+
<Compile Include="..\CommandLine\Core\InstanceChooser.cs" />
76+
<Compile Include="..\CommandLine\Core\Tokenizer.cs">
77+
<SubType>Code</SubType>
78+
</Compile>
79+
<Compile Include="..\CommandLine\Core\Verb.cs" />
80+
<Compile Include="..\CommandLine\Infrastructure\ExceptionExtensions.cs" />
81+
<Compile Include="..\CommandLine\Infrastructure\FSharpOptionHelper.cs" />
82+
<Compile Include="..\CommandLine\Infrastructure\PopsicleSetter.cs" />
83+
<Compile Include="..\CommandLine\Infrastructure\ReflectionHelper.cs" />
84+
<Compile Include="..\CommandLine\Infrastructure\ResultExtensions.cs" />
85+
<Compile Include="..\CommandLine\Infrastructure\StringExtensions.cs" />
86+
<Compile Include="..\CommandLine\NameInfo.cs" />
87+
<Compile Include="..\CommandLine\NullInstance.cs" />
88+
<Compile Include="..\CommandLine\Core\OptionMapper.cs" />
89+
<Compile Include="..\CommandLine\Core\SpecificationPropertyRules.cs" />
90+
<Compile Include="..\CommandLine\Core\SpecificationGuards.cs" />
91+
<Compile Include="..\CommandLine\Core\TypeLookup.cs" />
92+
<Compile Include="..\CommandLine\Core\ValueMapper.cs">
93+
<SubType>Code</SubType>
94+
</Compile>
95+
<Compile Include="..\CommandLine\Core\SpecificationPropertyExtensions.cs" />
96+
<Compile Include="..\CommandLine\Core\SpecificationExtensions.cs" />
97+
<Compile Include="..\CommandLine\Core\NameLookup.cs" />
98+
<Compile Include="..\CommandLine\Core\SpecificationProperty.cs">
99+
<SubType>Code</SubType>
100+
</Compile>
101+
<Compile Include="..\CommandLine\Core\ReflectionExtensions.cs" />
102+
<Compile Include="..\CommandLine\Core\TokenPartitioner.cs" />
103+
<Compile Include="..\CommandLine\Core\TypeConverter.cs" />
104+
<Compile Include="..\CommandLine\Core\ValueSpecification.cs" />
105+
<Compile Include="..\CommandLine\Core\InstanceBuilder.cs" />
106+
<Compile Include="..\CommandLine\Core\OptionSpecification.cs" />
107+
<Compile Include="..\CommandLine\Core\Specification.cs" />
108+
<Compile Include="..\CommandLine\Core\Token.cs" />
109+
<Compile Include="..\CommandLine\Error.cs" />
110+
<Compile Include="..\CommandLine\OptionAttribute.cs" />
111+
<Compile Include="..\CommandLine\Parser.cs" />
112+
<Compile Include="..\CommandLine\ParserExtensions.cs" />
113+
<Compile Include="..\CommandLine\ParserResult.cs" />
114+
<Compile Include="..\CommandLine\ParserResultExtensions.cs" />
115+
<Compile Include="..\CommandLine\ParserSettings.cs" />
116+
<Compile Include="..\CommandLine\Properties\AssemblyInfo.cs" />
117+
<Compile Include="..\CommandLine\Core\NameExtensions.cs" />
118+
<Compile Include="..\CommandLine\Text\AssemblyLicenseAttribute.cs">
119+
<SubType>Code</SubType>
120+
</Compile>
121+
<Compile Include="..\CommandLine\Text\AssemblyUsageAttribute.cs">
122+
<SubType>Code</SubType>
123+
</Compile>
124+
<Compile Include="..\CommandLine\Text\CopyrightInfo.cs">
125+
<SubType>Code</SubType>
126+
</Compile>
127+
<Compile Include="..\CommandLine\Text\Example.cs" />
128+
<Compile Include="..\CommandLine\Text\HeadingInfo.cs">
129+
<SubType>Code</SubType>
130+
</Compile>
131+
<Compile Include="..\CommandLine\Text\HelpText.cs" />
132+
<Compile Include="..\CommandLine\Text\MultiLineTextAttribute.cs">
133+
<SubType>Code</SubType>
134+
</Compile>
135+
<Compile Include="..\CommandLine\Text\SentenceBuilder.cs" />
136+
<Compile Include="..\CommandLine\Infrastructure\StringBuilderExtensions.cs" />
137+
<Compile Include="..\CommandLine\Text\UsageAttribute.cs" />
138+
<Compile Include="..\CommandLine\UnParserExtensions.cs" />
139+
<Compile Include="..\CommandLine\ValueAttribute.cs" />
140+
<Compile Include="..\CommandLine\VerbAttribute.cs" />
141+
</ItemGroup>
142+
<ItemGroup>
143+
<Reference Include="FSharp.Core">
144+
<HintPath>..\..\packages\FSharp.Core\lib\portable-net45+netcore45+wpa81+wp8\FSharp.Core.dll</HintPath>
145+
<Private>True</Private>
146+
<Paket>True</Paket>
147+
</Reference>
148+
</ItemGroup>
149+
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
150+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
151+
Other similar extension points exist, see Microsoft.Common.targets.
152+
<Target Name="AfterBuild">
153+
</Target>
154+
-->
155+
<Target Name="BeforeBuild" DependsOnTargets="PaketInstall">
156+
</Target>
157+
<Target Name="BootstrapPaket" Condition="!Exists('$(SolutionDir).paket/paket.bootstrapper.exe)')">
158+
<Exec Command="$(SolutionDir).paket/paket.bootstrapper.exe" />
159+
</Target>
160+
<Target Name="PaketInstall" DependsOnTargets="BootstrapPaket" Condition="!Exists('$(SolutionDir)paket-files')">
161+
<Exec Command="$(SolutionDir).paket/paket install" />
162+
</Target>
163+
</Project>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"supports": {
3+
"net46.app": {},
4+
"dnxcore50.app": {}
5+
},
6+
"dependencies": {
7+
"Microsoft.NETCore": "5.0.0",
8+
"Microsoft.NETCore.Portable.Compatibility": "1.0.0",
9+
"System.Collections.Specialized": "4.0.0",
10+
"System.Diagnostics.Tracing": "4.0.20",
11+
"System.Linq": "4.0.0",
12+
"System.Linq.Expressions": "4.0.10",
13+
"Microsoft.CSharp": "4.0.0",
14+
"System.Xml.XDocument": "4.0.10",
15+
"System.Data.Common": "4.0.0",
16+
"System.Console": "4.0.0-beta-23409",
17+
"System.Reflection.Extensions": "4.0.1-beta-23409",
18+
"System.Reflection.Primitives": "4.0.1-beta-23409",
19+
"System.Reflection.TypeExtensions": "4.0.1-beta-23409"
20+
},
21+
"frameworks": {
22+
"dotnet": {
23+
"imports": "portable-net452"
24+
}
25+
}
26+
}

src/CommandLine/Core/InstanceBuilder.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
using System.Collections.Generic;
55
using System.Globalization;
66
using System.Linq;
7+
#if PLATFORM_DOTNET
8+
using System.Reflection;
9+
#endif
710
using CommandLine.Infrastructure;
811
using CSharpx;
912
using RailwaySharp.ErrorHandling;

src/CommandLine/Core/ReflectionExtensions.cs

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ private static IEnumerable<Type> FlattenHierarchy(this Type type)
5858
{
5959
yield return @interface;
6060
}
61-
foreach (var @interface in FlattenHierarchy(type.BaseType))
61+
foreach (var @interface in FlattenHierarchy(type.GetTypeInfo().BaseType))
6262
{
6363
yield return @interface;
6464
}
@@ -97,16 +97,24 @@ public static T SetProperties<T>(
9797

9898
private static T SetValue<T>(this PropertyInfo property, T instance, object value)
9999
{
100-
Action<Exception> fail = inner => { throw new ApplicationException("Cannot set value to target instance.", inner); };
100+
Action<Exception> fail = inner => {
101+
#if !PLATFORM_DOTNET
102+
throw new ApplicationException("Cannot set value to target instance.", inner);
103+
#else
104+
throw new Exception("Cannot set value to target instance.", inner);
105+
#endif
106+
};
101107

102108
try
103109
{
104110
property.SetValue(instance, value, null);
105111
}
112+
#if !PLATFORM_DOTNET
106113
catch (TargetException e)
107114
{
108115
fail(e);
109116
}
117+
#endif
110118
catch (TargetParameterCountException e)
111119
{
112120
fail(e);
@@ -153,7 +161,7 @@ public static object CreateDefaultForImmutable(this Type type)
153161
{
154162
return string.Empty;
155163
}
156-
if (type.IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
164+
if (type.GetTypeInfo().IsGenericType && type.GetGenericTypeDefinition() == typeof(IEnumerable<>))
157165
{
158166
return type.GetGenericArguments()[0].CreateEmptyArray();
159167
}
@@ -179,39 +187,56 @@ public static TypeInfo ToTypeInfo(this Type type)
179187

180188
public static object StaticMethod(this Type type, string name, params object[] args)
181189
{
190+
#if !PLATFORM_DOTNET
182191
return type.InvokeMember(
183192
name,
184193
BindingFlags.InvokeMethod | BindingFlags.Public | BindingFlags.Static,
185194
null,
186195
null,
187196
args);
197+
#else
198+
var methodInfo = type.GetMethod(name, BindingFlags.Public | BindingFlags.Static);
199+
return methodInfo.Invoke(null, null);
200+
#endif
201+
202+
188203
}
189204

190205
public static object StaticProperty(this Type type, string name)
191206
{
207+
#if !PLATFORM_DOTNET
192208
return type.InvokeMember(
193209
name,
194210
BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Static,
195211
null,
196212
null,
197213
new object[] { });
214+
#else
215+
var propertyInfo = type.GetProperty(name, BindingFlags.Public | BindingFlags.Static);
216+
return propertyInfo.GetGetMethod().Invoke(null, null);
217+
#endif
198218
}
199219

200220
public static object InstanceProperty(this Type type, string name, object target)
201221
{
222+
#if !PLATFORM_DOTNET
202223
return type.InvokeMember(
203224
name,
204225
BindingFlags.GetProperty | BindingFlags.Public | BindingFlags.Instance,
205226
null,
206227
target,
207228
new object[] { });
229+
#else
230+
var propertyInfo = type.GetProperty(name, BindingFlags.Public | BindingFlags.Instance);
231+
return propertyInfo.GetGetMethod().Invoke(target, null);
232+
#endif
208233
}
209234

210235
public static bool IsPrimitiveEx(this Type type)
211236
{
212237
return
213-
(type.IsValueType && type != typeof(Guid))
214-
|| type.IsPrimitive
238+
(type.GetTypeInfo().IsValueType && type != typeof(Guid))
239+
|| type.GetTypeInfo().IsPrimitive
215240
|| new [] {
216241
typeof(string)
217242
,typeof(decimal)
@@ -221,5 +246,25 @@ public static bool IsPrimitiveEx(this Type type)
221246
}.Contains(type)
222247
|| Convert.GetTypeCode(type) != TypeCode.Object;
223248
}
249+
250+
251+
#if !PLATFORM_DOTNET
252+
public static Type GetTypeInfo(this Type type)
253+
{
254+
return type;
255+
}
256+
#endif
257+
258+
#if PLATFORM_DOTNET
259+
public static Attribute[] GetCustomAttributes(this Type type, Type attributeType, bool inherit)
260+
{
261+
return type.GetTypeInfo().GetCustomAttributes(attributeType, inherit).ToArray();
262+
}
263+
264+
public static Attribute[] GetCustomAttributes(this Assembly assembly, Type attributeType, bool inherit)
265+
{
266+
return assembly.GetCustomAttributes(attributeType).ToArray();
267+
}
268+
#endif
224269
}
225270
}

src/CommandLine/Core/Specification.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public static Specification FromProperty(PropertyInfo property)
108108
if (oa.Count() == 1)
109109
{
110110
var spec = OptionSpecification.FromAttribute(oa.Single(), property.PropertyType,
111-
property.PropertyType.IsEnum
111+
property.PropertyType.GetTypeInfo().IsEnum
112112
? Enum.GetNames(property.PropertyType)
113113
: Enumerable.Empty<string>());
114114
if (spec.ShortName.Length == 0 && spec.LongName.Length == 0)
@@ -122,7 +122,7 @@ public static Specification FromProperty(PropertyInfo property)
122122
if (va.Count() == 1)
123123
{
124124
return ValueSpecification.FromAttribute(va.Single(), property.PropertyType,
125-
property.PropertyType.IsEnum
125+
property.PropertyType.GetTypeInfo().IsEnum
126126
? Enum.GetNames(property.PropertyType)
127127
: Enumerable.Empty<string>());
128128
}

src/CommandLine/Core/SpecificationExtensions.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ public static IEnumerable<Specification> ThrowingValidate(this IEnumerable<Speci
4747
{
4848
if (specifications.Any(spec => guard.Item1(spec)))
4949
{
50+
#if !PLATFORM_DOTNET
5051
throw new ApplicationException(guard.Item2);
52+
#else
53+
throw new Exception(guard.Item2);
54+
#endif
5155
}
5256
}
5357

0 commit comments

Comments
 (0)