Skip to content

Commit

Permalink
generate safe path on multiple if
Browse files Browse the repository at this point in the history
  • Loading branch information
neuecc committed Mar 4, 2019
1 parent 5cff4a9 commit ba43428
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/MessagePackCompiler/MessagePackCompiler.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="MicroBatchFramework" Version="0.3.1-beta3" />
<PackageReference Include="MicroBatchFramework" Version="0.4.0-beta4" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp" Version="3.0.0-beta3-final" />
<PackageReference Include="System.CodeDom" Version="4.5.0" />
</ItemGroup>
Expand Down
9 changes: 7 additions & 2 deletions src/MessagePackCompiler/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ static async Task Main(string[] args)
}
else
{
var fname = Path.GetFileNameWithoutExtension(output) + "." + multioutSymbol + ".cs";
var fname = Path.GetFileNameWithoutExtension(output) + "." + MultiSymbolToSafeFilePath(multioutSymbol) + ".cs";
var text = $"#if {multioutSymbol}" + Environment.NewLine + sb.ToString() + Environment.NewLine + "#endif";
await OutputAsync(Path.Combine(Path.GetDirectoryName(output), fname), text, Context.CancellationToken);
}
Expand Down Expand Up @@ -192,7 +192,7 @@ static Task OutputToDirAsync(string dir, string ns, string name, string multiple
else
{
text = $"#if {multipleOutSymbol}" + Environment.NewLine + text + Environment.NewLine + "#endif";
return OutputAsync(Path.Combine(dir, multipleOutSymbol, $"{ns}_{name}".Replace(".", "_").Replace("global::", "") + ".cs"), text, cancellationToken);
return OutputAsync(Path.Combine(dir, MultiSymbolToSafeFilePath(multipleOutSymbol), $"{ns}_{name}".Replace(".", "_").Replace("global::", "") + ".cs"), text, cancellationToken);
}
}

Expand All @@ -211,5 +211,10 @@ static Task OutputAsync(string path, string text, CancellationToken cancellation

return System.IO.File.WriteAllTextAsync(path, text, Encoding.UTF8, cancellationToken);
}

static string MultiSymbolToSafeFilePath(string symbol)
{
return symbol.Replace("!", "NOT_").Replace("(", "").Replace(")", "").Replace("||", "_OR_").Replace("&&", "_AND_");
}
}
}

0 comments on commit ba43428

Please sign in to comment.