Skip to content

Commit 72d670d

Browse files
committed
#3 replace : with _ in compiler-generated file path
1 parent 0d87ace commit 72d670d

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<LangVersion>9.0</LangVersion>
44
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
55
<Nullable>enable</Nullable>
6-
<Version>0.8.1</Version>
6+
<Version>0.8.2</Version>
77
</PropertyGroup>
88
</Project>

JsonByExampleGenerator.Generator/JsonGenerator.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,8 @@ private string GetSourceFileName(string path)
204204
.Replace(Path.GetFullPath("."), string.Empty)
205205
.Replace("/", "_")
206206
.Replace("\\", "_")
207-
.Replace(".", "_");
207+
.Replace(".", "_")
208+
.Replace(":", "_");
208209

209210
return $"{fullPath.Trim('_')}.gen.cs";
210211
}

JsonByExampleGenerator.Tests/SerializationTests.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,18 @@ public void ShouldSerializeAndDeserializeFromFile(string rootTypeName, string js
6363
Path.GetFileName(jsonFilePath));
6464
}
6565

66-
private void DeserializeSerializeAndAssert(string rootTypeName, string jsonAsString, string fileName)
66+
[Fact]
67+
public void ShouldSerializeAndDeserializeFromFileWithAbsolutePath()
68+
{
69+
const string relativePath = "RealWorldExamples/jsonOrgExample1.json";
70+
DeserializeSerializeAndAssert(
71+
"JsonOrgExample1",
72+
EmbeddedResource.GetContent(relativePath, System.Reflection.Assembly.GetExecutingAssembly()),
73+
Path.Combine("C:\\temp", Path.GetFileName(relativePath)),
74+
"C.Temp.");
75+
}
76+
77+
private void DeserializeSerializeAndAssert(string rootTypeName, string jsonAsString, string fileName, string prefixPath = "")
6778
{
6879
string source = $@"using System;
6980
using System.IO;
@@ -80,9 +91,8 @@ public static string RunTest()
8091
streamWriter.Write(@""{jsonAsString.Replace("\"", "\"\"")}"");
8192
streamWriter.Flush();
8293
readStream.Position = 0;
83-
84-
var ser = new DataContractJsonSerializer(typeof(TestImplementation.Json.{rootTypeName}.{rootTypeName}));
85-
var rootType = (TestImplementation.Json.{rootTypeName}.{rootTypeName}) ser.ReadObject(readStream);
94+
var ser = new DataContractJsonSerializer(typeof(TestImplementation.Json.{prefixPath}{rootTypeName}.{rootTypeName}));
95+
var rootType = (TestImplementation.Json.{prefixPath}{rootTypeName}.{rootTypeName}) ser.ReadObject(readStream);
8696
8797
var writeStream = new MemoryStream();
8898
ser.WriteObject(writeStream, rootType);

0 commit comments

Comments
 (0)