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

Commit 363f849

Browse files
committed
impl MapAbsolutePath for NetStandard
1 parent 5e03137 commit 363f849

File tree

3 files changed

+47
-28
lines changed

3 files changed

+47
-28
lines changed

src/ServiceStack.Text/PathUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static string MapAbsolutePath(this string relativePath)
5050
/// <remarks>Assumes static content is in the parent folder of the /bin/ directory</remarks>
5151
public static string MapHostAbsolutePath(this string relativePath)
5252
{
53-
var mapPath = MapAbsolutePath(relativePath, string.Format("{0}..", PclExport.Instance.DirSep));
53+
var mapPath = MapAbsolutePath(relativePath, $"{PclExport.Instance.DirSep}..");
5454
return mapPath;
5555
}
5656

src/ServiceStack.Text/PclExport.Net40.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,12 +223,12 @@ public override Type FindType(string typeName, string assemblyName)
223223
{
224224
var binPath = AssemblyUtils.GetAssemblyBinPath(Assembly.GetExecutingAssembly());
225225
Assembly assembly = null;
226-
var assemblyDllPath = binPath + string.Format("{0}.{1}", assemblyName, "dll");
226+
var assemblyDllPath = binPath + $"{assemblyName}.dll";
227227
if (File.Exists(assemblyDllPath))
228228
{
229229
assembly = AssemblyUtils.LoadAssembly(assemblyDllPath);
230230
}
231-
var assemblyExePath = binPath + string.Format("{0}.{1}", assemblyName, "exe");
231+
var assemblyExePath = binPath + $"{assemblyName}.exe";
232232
if (File.Exists(assemblyExePath))
233233
{
234234
assembly = AssemblyUtils.LoadAssembly(assemblyExePath);

src/ServiceStack.Text/PclExport.NetStandard.cs

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,30 +24,30 @@ public class NetStandardPclExport : PclExport
2424

2525
static string[] allDateTimeFormats = new string[]
2626
{
27-
"yyyy-MM-ddTHH:mm:ss.FFFFFFFzzzzzz",
28-
"yyyy-MM-ddTHH:mm:ss.FFFFFFF",
29-
"yyyy-MM-ddTHH:mm:ss.FFFFFFFZ",
30-
"HH:mm:ss.FFFFFFF",
31-
"HH:mm:ss.FFFFFFFZ",
32-
"HH:mm:ss.FFFFFFFzzzzzz",
33-
"yyyy-MM-dd",
34-
"yyyy-MM-ddZ",
35-
"yyyy-MM-ddzzzzzz",
36-
"yyyy-MM",
37-
"yyyy-MMZ",
38-
"yyyy-MMzzzzzz",
39-
"yyyy",
40-
"yyyyZ",
41-
"yyyyzzzzzz",
42-
"--MM-dd",
43-
"--MM-ddZ",
44-
"--MM-ddzzzzzz",
45-
"---dd",
46-
"---ddZ",
47-
"---ddzzzzzz",
48-
"--MM--",
49-
"--MM--Z",
50-
"--MM--zzzzzz",
27+
"yyyy-MM-ddTHH:mm:ss.FFFFFFFzzzzzz",
28+
"yyyy-MM-ddTHH:mm:ss.FFFFFFF",
29+
"yyyy-MM-ddTHH:mm:ss.FFFFFFFZ",
30+
"HH:mm:ss.FFFFFFF",
31+
"HH:mm:ss.FFFFFFFZ",
32+
"HH:mm:ss.FFFFFFFzzzzzz",
33+
"yyyy-MM-dd",
34+
"yyyy-MM-ddZ",
35+
"yyyy-MM-ddzzzzzz",
36+
"yyyy-MM",
37+
"yyyy-MMZ",
38+
"yyyy-MMzzzzzz",
39+
"yyyy",
40+
"yyyyZ",
41+
"yyyyzzzzzz",
42+
"--MM-dd",
43+
"--MM-ddZ",
44+
"--MM-ddzzzzzz",
45+
"---dd",
46+
"---ddZ",
47+
"---ddzzzzzz",
48+
"--MM--",
49+
"--MM--Z",
50+
"--MM--zzzzzz",
5151
};
5252

5353
public NetStandardPclExport()
@@ -176,6 +176,26 @@ public static StringCollection ToStringCollection(List<string> items)
176176
}
177177
#endif
178178

179+
public string BinPath = null;
180+
181+
public override string MapAbsolutePath(string relativePath, string appendPartialPathModifier)
182+
{
183+
if (BinPath == null)
184+
{
185+
var dll = typeof(PclExport).GetAssembly();
186+
var pi = dll.GetType().GetProperty("CodeBase");
187+
var codeBase = pi?.GetProperty(dll).ToString();
188+
if (codeBase == null)
189+
throw new Exception("NetStandardPclExport.BinPath must be initialized");
190+
191+
BinPath = Path.GetDirectoryName(codeBase.Replace("file:///", ""));
192+
}
193+
194+
return relativePath.StartsWith("~")
195+
? relativePath.Replace("~", BinPath)
196+
: relativePath;
197+
}
198+
179199
public override Type UseType(Type type)
180200
{
181201
if (type.IsInterface() || type.IsAbstract())
@@ -185,7 +205,6 @@ public override Type UseType(Type type)
185205
return type;
186206
}
187207

188-
189208
public override ParseStringDelegate GetJsReaderParseMethod<TSerializer>(Type type)
190209
{
191210
if (type.AssignableFrom(typeof(System.Dynamic.IDynamicMetaObjectProvider)) ||

0 commit comments

Comments
 (0)