Describe the solution you'd like
I did a review of the code to see what kind of improvements I could make. Here's a random list of all of them I found. Some of them are very minor, some may help with performance.
DONE - TypeReferenceModel Caching
TypeReferenceModel can be cached for a generator run. For example, these two methods will generate two instances of a TypeReferenceModel for the string, even though they're exactly the same:
public interface IOne
{
void Work(string value);
}
public interface ITwo
{
void Work(string value);
}
Therefore, make the ctor private, and have a static Create() method that will use a Dictionary<?, TypeReferenceModel>. Hopefully that will reduce the amount of TRMs made. Probably use ITypeSymbol for the dictionary key.
DONE - TypeReferenceModel IsPointer() calls
Within TypeReferenceModel, type.IsPointer() is called twice. For the second time, just use the IsPointer property.
Naming Clean-Up
Naming is hard. I have multiple ways to get "names":
ITypeSymbolExtensions.GetFullyQualifiedName()
ITypeSymbolExtensions.GetName()
TypeReferenceModel.BuildName()
Not sure what I can do here, but it would be nice if I could do some consolidation.
DONE - Removing Dead Code
Looks like a number of types and type members are no longer used, and can (probably) be removed.
ConstructorModel
EventModel
ParameterModel
PropertyModel
TypeReferenceModel
Kind
PointerArgParameterType
PointerArgProjectedEvaluationDelegateName
PointerArgProjectedName
IDictionaryOfTKeyTValueExtensions
INamespaceSymbolExtensions
SyntaxNodeExtensions
MockedType
DONE - Remove .ToImmutableArray()
Looks like I can get rid of that call and just use collection expressions with a spread.
Also, CreateBuilder and .Builder.
DONE - Code Suggestion Improvements
The following classes have minor code suggestion improvements:
MockableConstructorDiscovery
TypeArgumentsNamingContext
VariablesNamingContext
IndentedTextWriterExtensions
Expectations
DONE - Miscellaneous Minor Changes
- In
TypeMockModel, setting this.ExpectationsIsSealed can be simplified.
- Property exception code generation is off. It works, but the indentation is a little weird. Look at
PropertyGeneratorTests.GenerateWithNewDefinitionAsync() for an example.
MockAdornmentsBuilder, line 20, raw string literal is a bit off.
IParameterSymbolExtensions.RequiresForcedNullableAnnotation(), minor indention change.
Describe alternatives you've considered
Keep the code as/is.
Describe the solution you'd like
I did a review of the code to see what kind of improvements I could make. Here's a random list of all of them I found. Some of them are very minor, some may help with performance.
DONE -
TypeReferenceModelCachingTypeReferenceModelcan be cached for a generator run. For example, these two methods will generate two instances of aTypeReferenceModelfor thestring, even though they're exactly the same:Therefore, make the ctor
private, and have a staticCreate()method that will use aDictionary<?, TypeReferenceModel>. Hopefully that will reduce the amount of TRMs made. Probably useITypeSymbolfor the dictionary key.DONE -
TypeReferenceModelIsPointer()callsWithin
TypeReferenceModel,type.IsPointer()is called twice. For the second time, just use theIsPointerproperty.Naming Clean-Up
Naming is hard. I have multiple ways to get "names":
ITypeSymbolExtensions.GetFullyQualifiedName()ITypeSymbolExtensions.GetName()TypeReferenceModel.BuildName()Not sure what I can do here, but it would be nice if I could do some consolidation.
DONE - Removing Dead Code
Looks like a number of types and type members are no longer used, and can (probably) be removed.
ConstructorModelMockTypeEventModelMockTypeParameterModelMockTypePropertyModelAllowNullTypeReferenceModelKindPointerArgParameterTypePointerArgProjectedEvaluationDelegateNamePointerArgProjectedNameIDictionaryOfTKeyTValueExtensionsINamespaceSymbolExtensionsSyntaxNodeExtensionsMockedTypeDONE - Remove
.ToImmutableArray()Looks like I can get rid of that call and just use collection expressions with a spread.
Also,
CreateBuilderand.Builder.DONE - Code Suggestion Improvements
The following classes have minor code suggestion improvements:
MockableConstructorDiscoveryTypeArgumentsNamingContextVariablesNamingContextIndentedTextWriterExtensionsExpectationsDONE - Miscellaneous Minor Changes
TypeMockModel, settingthis.ExpectationsIsSealedcan be simplified.PropertyGeneratorTests.GenerateWithNewDefinitionAsync()for an example.MockAdornmentsBuilder, line 20, raw string literal is a bit off.IParameterSymbolExtensions.RequiresForcedNullableAnnotation(), minor indention change.Describe alternatives you've considered
Keep the code as/is.