private static string GenerateConstructorParameters(
        IReadOnlyCollection <ISymbol> eligibleMembers,
        IReadOnlyCollection <ISymbol> baseEligibleMembers)
    {
        StringBuilder  stringBuilder = new StringBuilder();
        List <ISymbol> members       = new List <ISymbol>(eligibleMembers.Count + baseEligibleMembers.Count);

        members.AddRange(eligibleMembers);
        members.AddRange(baseEligibleMembers);
        members = members.OrderBy(o => o.Name).ToList();

        foreach (ISymbol member in members)
        {
            if (member is IFieldSymbol fieldSymbol)
            {
                stringBuilder.Append(
                    $@"{'\n'}{"\t\t\t"}{fieldSymbol.Type} autoInjected{AutoInjectHelper.FormatMemberName(fieldSymbol.Name)},");
            }

            if (member is IPropertySymbol propertySymbol)
            {
                stringBuilder.Append(
                    $@"{'\n'}{"\t\t\t"}{propertySymbol.Type} autoInjected{AutoInjectHelper.FormatMemberName(propertySymbol.Name)},");
            }
        }

        stringBuilder.Length--;

        return(stringBuilder.ToString());
    }
Пример #2
0
    private static string GenerateProperty(ITypeSymbol @type, string name)
    {
        return($@"
{"\t\t"}[Inject]
{"\t\t"}[EditorBrowsable(EditorBrowsableState.Never)]
{"\t\t"}private {@type} ____{AutoInjectHelper.FormatMemberName(name)} {{ get => {name}; set => {name} = value; }}");
    }
    private static string AssignedInjectedParametersToMembers(IReadOnlyCollection <ISymbol> eligibleMembers)
    {
        StringBuilder stringBuilder = new StringBuilder();

        foreach (ISymbol symbol in eligibleMembers)
        {
            stringBuilder.Append($@"{symbol.Name} = autoInjected{AutoInjectHelper.FormatMemberName(symbol.Name)};");
        }

        return(stringBuilder.ToString());
    }
    private static string PassParametersToBaseClass(IReadOnlyCollection <ISymbol> baseEligibleMembers)
    {
        if (baseEligibleMembers.Any() is false)
        {
            return("");
        }

        StringBuilder baseConstructor = new StringBuilder();

        baseConstructor.Append(": base(");

        foreach (ISymbol symbol in baseEligibleMembers)
        {
            baseConstructor.Append($@"{'\n'}{"\t\t\t\t\t\t"}autoInjected{AutoInjectHelper.FormatMemberName(symbol.Name)},");
        }

        baseConstructor.Length--;

        baseConstructor.Append(')');

        return(baseConstructor.ToString());
    }