Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit 65a5400

Browse files
committed
Add PCL API's for getting File/Directory names and fallack ReferenceAssembyPath to use latest v4 release
1 parent ebb6689 commit 65a5400

File tree

5 files changed

+57
-14
lines changed

5 files changed

+57
-14
lines changed

src/ServiceStack.Text/Env.cs

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -97,22 +97,17 @@ public static string ReferenceAssembyPath
9797
referenceAssembyPath = netFxReferenceBasePath + @"v4.0\";
9898
else
9999
{
100-
var dir = new DirectoryInfo(netFxReferenceBasePath);
101-
if (dir.Exists)
100+
var v4Dirs = PclExport.Instance.GetDirectoryNames(netFxReferenceBasePath, "v4*");
101+
if (v4Dirs.Length > 0)
102102
{
103-
var fxDirs = dir.GetDirectories();
104-
foreach (var fxDir in fxDirs)
105-
{
106-
if (fxDir.Name.StartsWith("v4"))
107-
{
108-
return referenceAssembyPath = netFxReferenceBasePath + fxDir.Name + @"\";
109-
}
110-
}
103+
referenceAssembyPath = v4Dirs[v4Dirs.Length - 1]; //latest v4
104+
}
105+
else
106+
{
107+
throw new FileNotFoundException(
108+
"Could not infer .NET Reference Assemblies path, e.g '{0}'.\n".Fmt(netFxReferenceBasePath + @"v4.0\") +
109+
"Provide path manually 'Env.ReferenceAssembyPath'.");
111110
}
112-
113-
throw new FileNotFoundException(
114-
"Could not infer .NET Reference Assemblies path, e.g '{0}'.\n".Fmt(netFxReferenceBasePath + @"v4.0\") +
115-
"Provide path manually 'Env.ReferenceAssembyPath'.");
116111
}
117112
}
118113
#endif

src/ServiceStack.Text/PclExport.Net40.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ public override void CreateDirectory(string dirPath)
9595
Directory.CreateDirectory(dirPath);
9696
}
9797

98+
public override string[] GetFileNames(string dirPath, string searchPattern = null)
99+
{
100+
if (!Directory.Exists(dirPath))
101+
return new string[0];
102+
103+
return searchPattern != null
104+
? Directory.GetFiles(dirPath, searchPattern)
105+
: Directory.GetFiles(dirPath);
106+
}
107+
108+
public override string[] GetDirectoryNames(string dirPath, string searchPattern = null)
109+
{
110+
if (!Directory.Exists(dirPath))
111+
return new string[0];
112+
113+
return searchPattern != null
114+
? Directory.GetDirectories(dirPath, searchPattern)
115+
: Directory.GetDirectories(dirPath);
116+
}
117+
98118
public const string AppSettingsKey = "servicestack:license";
99119
public override void RegisterLicenseFromConfig()
100120
{

src/ServiceStack.Text/PclExport.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,16 @@ public virtual string GetEnvironmentVariable(string name)
164164
return null;
165165
}
166166

167+
public virtual string[] GetFileNames(string dirPath, string searchPattern = null)
168+
{
169+
return new string[0];
170+
}
171+
172+
public virtual string[] GetDirectoryNames(string dirPath, string searchPattern = null)
173+
{
174+
return new string[0];
175+
}
176+
167177
public virtual void WriteLine(string line)
168178
{
169179
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using NUnit.Framework;
2+
3+
namespace ServiceStack.Text.Tests
4+
{
5+
[TestFixture]
6+
public class PclApiTests
7+
{
8+
[Test, Explicit]
9+
public void Can_scan_reference_assemblies()
10+
{
11+
var refDir = @"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\";
12+
13+
PclExport.Instance.GetDirectoryNames(refDir).PrintDump();
14+
PclExport.Instance.GetDirectoryNames(refDir, "v4*").PrintDump();
15+
}
16+
}
17+
}

tests/ServiceStack.Text.Tests/ServiceStack.Text.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
<Compile Include="JsonTests\JsonEnumTests.cs" />
183183
<Compile Include="JsonTests\InvalidJsonTests.cs" />
184184
<Compile Include="JsonTests\TypeInfoTests.cs" />
185+
<Compile Include="PclApiTests.cs" />
185186
<Compile Include="SerializationDelegatePerformanceTests.cs" />
186187
<Compile Include="SerializationHookTests.cs" />
187188
<Compile Include="StaticAccessorTests.cs" />

0 commit comments

Comments
 (0)