Esempio n. 1
0
        private void AddSourceIfNotEmpty(string className, ISourceTextBuffer sourceBuffer)
        {
            var hintName   = $"{className}.g.cs";
            var sourceText = sourceBuffer.ToString();

            if (!string.IsNullOrWhiteSpace(sourceText))
            {
                ExecutionContext.AddSource(hintName, sourceText);
            }
        }
Esempio n. 2
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}();");
        }
Esempio n. 3
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();
        }
Esempio n. 4
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();
        }
Esempio n. 5
0
 public unsafe DocumentText(ISourceTextBuffer textProvider)
 {
     if(textProvider == null) { Debug.Assert(false); return; }
     this.TextProvider = textProvider;
     this.AsciiStringPtr = textProvider.Buffer;
     this.Length = textProvider.Length;
 }