Exemplo n.º 1
0
        private void WriteConstructor(ISourceTextBuffer buffer, INamedTypeSymbol typeSymbol, IEnumerable <IFieldSymbol> ownFields, IEnumerable <IFieldSymbol> inheritedFields)
        {
            var name = _symbolParser.GetConstructorName(typeSymbol);

            buffer.WriteLine($"public {name}(");
            buffer.Indent();

            WriteParameterList(buffer, inheritedFields.Concat(ownFields));

            buffer.WriteLine($")");
            buffer.Dedent();

            if (inheritedFields.Any())
            {
                WriteBaseInitCall(buffer, inheritedFields);
            }

            buffer.BeginBlock();
            WriteBindingList(buffer, ownFields);
            ResolvePostControllerMethodCall(buffer, typeSymbol);
            buffer.EndBlock();
        }
Exemplo n.º 2
0
        public void Execute(ISourceTextBuffer buffer, INamedTypeSymbol typeSymbol)
        {
            var ownFieldsToInject       = GetOwnFieldsToInject(typeSymbol);
            var inheritedFieldsToInject = GetInheritedFieldsToInject(typeSymbol);

            if (!ownFieldsToInject.Any() && !inheritedFieldsToInject.Any())
            {
                return;
            }

            var classNamespace = _symbolParser.GetNamespaceName(typeSymbol);
            var className      = _symbolParser.GetTypeName(typeSymbol);

            buffer.WriteLine($"namespace {classNamespace}");
            buffer.BeginBlock();

            buffer.WriteLine($"public partial class {className}");
            buffer.BeginBlock();
            WriteConstructor(buffer, typeSymbol, ownFieldsToInject, inheritedFieldsToInject);
            buffer.EndBlock();

            buffer.EndBlock();
        }
Exemplo n.º 3
0
        private void ResolvePostControllerMethodCall(ISourceTextBuffer buffer, INamedTypeSymbol typeSymbol)
        {
            var postControllerMethod = GetPostControllerMethod(typeSymbol);

            if (postControllerMethod == null)
            {
                return;
            }

            if (_symbolParser.IsOverrideMember(postControllerMethod))
            {
                throw new Exception($"The original '{_config.PostConstructorMethodName}' method should run after the constructor of the class where it's defined. Do not override it.");
            }

            buffer.WriteLine($"{_config.PostConstructorMethodName}();");
        }