Skip to content

Commit

Permalink
Merge pull request #578 from AlonTalmi/SourceGeneratorAddParametersSu…
Browse files Browse the repository at this point in the history
…pport

 Fix withParameter not working (With code generation)
  • Loading branch information
hadashiA authored Nov 26, 2023
2 parents 08e7862 + c794aff commit 388ebd4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions VContainer.SourceGenerator/VContainerSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,16 +218,16 @@ static bool TryEmitInjectMethod(

foreach (var fieldSymbol in typeMeta.InjectFields)
{
var fieldTypeName =
fieldSymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
codeWriter.AppendLine($"__x.{fieldSymbol.Name} = resolver.Resolve<{fieldTypeName}>();");
var fieldTypeName = fieldSymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);

codeWriter.AppendLine($"__x.{fieldSymbol.Name} = ({fieldTypeName})resolver.ResolveOrParameter(typeof({fieldTypeName}), \"{fieldSymbol.Name}\", parameters);");
}

foreach (var propSymbol in typeMeta.InjectProperties)
{
var propTypeName =
propSymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);
codeWriter.AppendLine($"__x.{propSymbol.Name} = resolver.Resolve<{propTypeName}>();");
var propTypeName = propSymbol.Type.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat);

codeWriter.AppendLine($"__x.{propSymbol.Name} = ({propTypeName})resolver.ResolveOrParameter(typeof({propTypeName}), \"{propSymbol.Name}\", parameters);");
}

foreach (var methodSymbol in typeMeta.InjectMethods)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public static ReflectionInjector Build(Type type)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void Inject(object instance, IObjectResolver resolver, IReadOnlyList<IInjectParameter> parameters)
{
InjectFields(instance, resolver);
InjectProperties(instance, resolver);
InjectFields(instance, resolver, parameters);
InjectProperties(instance, resolver, parameters);
InjectMethods(instance, resolver, parameters);
}

Expand Down Expand Up @@ -56,26 +56,26 @@ public object CreateInstance(IObjectResolver resolver, IReadOnlyList<IInjectPara
}
}

void InjectFields(object obj, IObjectResolver resolver)
void InjectFields(object obj, IObjectResolver resolver, IReadOnlyList<IInjectParameter> parameters)
{
if (injectTypeInfo.InjectFields == null)
return;

foreach (var x in injectTypeInfo.InjectFields)
{
var fieldValue = resolver.Resolve(x.FieldType);
var fieldValue = resolver.ResolveOrParameter(x.FieldType, x.Name, parameters);
x.SetValue(obj, fieldValue);
}
}

void InjectProperties(object obj, IObjectResolver resolver)
void InjectProperties(object obj, IObjectResolver resolver, IReadOnlyList<IInjectParameter> parameters)
{
if (injectTypeInfo.InjectProperties == null)
return;

foreach (var x in injectTypeInfo.InjectProperties)
{
var propValue = resolver.Resolve(x.PropertyType);
var propValue = resolver.ResolveOrParameter(x.PropertyType, x.Name, parameters);
x.SetValue(obj, propValue);
}
}
Expand Down

1 comment on commit 388ebd4

@vercel
Copy link

@vercel vercel bot commented on 388ebd4 Nov 26, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.