-
Notifications
You must be signed in to change notification settings - Fork 202
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
Support replacing methods #4547
base: main
Are you sure you want to change the base?
Support replacing methods #4547
Conversation
API change check API changes are not detected in this pull request. |
b4b7d7c
to
c207660
Compare
c207660
to
d118450
Compare
@@ -4,7 +4,7 @@ | |||
|
|||
namespace Sample.Models | |||
{ | |||
public partial class MockInputModel | |||
public partial class Model |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was running into build errors on my local due to this file path being too long. There's probably another overall fix we can do for that, but for now I'm shortening the filename.
{ | ||
public static partial class SampleNamespaceModelFactory | ||
{ | ||
public static MockInputModel MockInputModel(string prop1 = default, bool? optionalBool = default) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add a test case where we have a nullable struct, where the struct is generated by the library?
} | ||
|
||
string[] typeArguments = [.. namedTypeSymbol.TypeArguments.Select(GetFullyQualifiedName)]; | ||
return $"{nullableTypeName}`{namedTypeSymbol.TypeArguments.Length}[{string.Join(", ", typeArguments)}]"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the CSharpType we create from a symbol match the behavior for PropertyProvider.Type? I thought when creating CSharpType from the output types for a nullable, the CSharpType underlying Type would not be Nullable.
@@ -286,14 +285,11 @@ private CSharpType GetCSharpType(ITypeSymbol typeSymbol) | |||
Type? type = System.Type.GetType(fullyQualifiedName); | |||
if (type is null) | |||
{ | |||
if (typeSymbol.TypeKind == TypeKind.Error) | |||
throw new InvalidOperationException($"Unable to convert ITypeSymbol: {fullyQualifiedName} to a CSharpType in {Name}"); | |||
|
|||
return ConstructCSharpTypeFromSymbol(typeSymbol, fullyQualifiedName, namedTypeSymbol); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we now will fall back to constructing from the symbol, can we remove the if block that checks if the name starts with the RootNamespace?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind, I don't think we want to do this as it will then attempt to look up generated types using GetType which would actually succeed if a custom partial class is added. But this would give us the wrong info for various properties of CSharpType.
This PR adds support for replacing generated methods with custom code. It also fixes several issues with constructing nullable types from custom code.
fixes: #4472