-
Notifications
You must be signed in to change notification settings - Fork 132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Square brackets added to nullable string #331
Comments
I've run into the same issue, but have yet to find a workaround. |
@grey280 My workaround for now is to disable Typewriter and edit the .ts files manually. But that's not sustainable in the long run of course. |
@frhagn is this something you think you'll fix eventually? |
For me this workaroud works:
It would be nice if this project comes alive somehow. |
Here's my variant of the workaround: // special case: nullable value types (i.e. String?) register as Enumerable (Typewriter bug), need to be handled
bool hasNullableAttribute = p.Type.Attributes.Any(x => x.Name.ToLower() == "nullable");
bool endsWithBrackets = p.Type.Name.ToLower().EndsWith("[]");
bool isEnumerable = p.Type.FullName.StartsWith("System.Collections");
if (hasNullableAttribute && endsWithBrackets && !isEnumerable){
return $"{p.Type.Name.Substring(0, p.Type.Name.Length - 2)} | null";
}
return $"{p.Type.Name} | null"; |
@grey280 @SamuelKupferschmid Any ideas on how to make this approach work for this case? public Dictionary<string, string?> Nodes { get; set; } |
@johnknoop There'd be some very manual checks in that case, I suspect - I've been tinkering with trying to make something to recursively handle generics, but so far I keep running up against the disconnect between a |
@grey280 I got it working: string ProduceDictionaryType(Type type) {
bool endsWithBrackets = type.TypeArguments.Last().Name.ToLower().EndsWith("[]");
bool isEnumerable = type.TypeArguments.Last().FullName.StartsWith("System.Collections");
bool isNullableString = endsWithBrackets && !isEnumerable;
var suffix = isNullableString ? " | null | undefined" : "";
var valueType = isNullableString ?
$"{type.TypeArguments.Last().Name.Substring(0, type.TypeArguments.Last().Name.Length - 2)}"
: type.TypeArguments.Last().Name;
return $"{{ [key: {type.TypeArguments.First()}]: {valueType}{suffix}; }}";
} |
Now the last thing I need in order to be able to start using TypeWriter again, is nullable reference types that aren't strings. |
fixed in unoffical release https://github.com/AdaskoTheBeAsT/Typewriter |
I'm experiencing problems after declaring some strings as nullable, using the new nullable ref types in C# 8.
For any C#
string?
, the property.Type.Name will bestring[]
.Any idea how to get around this?
The text was updated successfully, but these errors were encountered: