chore(dotnet): treat file as a reserved word (#5960)

Avoid collision with System.IO.File and unify handling reserved file names and enum values.
This commit is contained in:
Darío Kondratiuk 2021-03-29 05:22:06 -03:00 committed by GitHub
parent 0943af2806
commit bc6dc1d108
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -40,6 +40,13 @@ let documentation;
/** @type {Map<string, string>} */
let classNameMap;
/** @type {Map<string, string>} */
const customTypeNames = new Map([
['domcontentloaded', 'DOMContentLoaded'],
['networkidle', 'NetworkIdle'],
['File', 'FilePayload'],
]);
{
const typesDir = process.argv[2] || '../generate_types/csharp/';
let checkAndMakeDir = (path) => {
@ -179,17 +186,13 @@ let classNameMap;
enumTypes.forEach((values, name) =>
innerRenderElement('enum', name, null, (out) => {
const knownEnumValues = new Map([
['domcontentloaded', 'DOMContentLoaded'],
['networkidle', 'NetworkIdle']
]);
out.push('\tUndefined = 0,');
values.forEach((v, i) => {
// strip out the quotes
v = v.replace(/[\"]/g, ``)
let escapedName = v.replace(/[-]/g, ' ')
.split(' ')
.map(word => knownEnumValues.get(word) || word[0].toUpperCase() + word.substring(1)).join('');
.map(word => customTypeNames.get(word) || word[0].toUpperCase() + word.substring(1)).join('');
out.push(`\t[EnumMember(Value = "${v}")]`);
out.push(`\t${escapedName},`);
@ -341,6 +344,8 @@ function generateNameDefault(member, name, t, parent) {
if (attemptedName.endsWith('s')
&& !["properties", "httpcredentials"].includes(attemptedName.toLowerCase()))
attemptedName = attemptedName.substring(0, attemptedName.length - 1);
if (customTypeNames.get(attemptedName))
attemptedName = customTypeNames.get(attemptedName);
let probableType = additionalTypes.get(attemptedName);
if ((probableType && typesDiffer(t, probableType))
|| (["Value"].includes(attemptedName))) {