trampster / JsonSrcGen

Json library that uses .NET 5 Source Generators
MIT License
148 stars 4 forks source link

Compile error if Json type is out of namespace. #58

Closed stjeong closed 3 years ago

stjeong commented 3 years ago

For example,

using System;
using JsonSrcGen;

/*
namespace ConsoleApp1
{
*/
    [Json]
    public class MyType
    {
        [JsonName("my_name")]
        public string MyProperty { get; set; }

        [JsonIgnore]
        public string IgnoredProperty { get; set; }
    }
// }

with above code, lots of compilation error occurred like these,

Error CS0501 '<invalid-global-code>.<invalid-global-code>(value, builder)' must declare a body because it is not marked abstract, extern, or partial
Error CS0501 'JsonConverter.ToJson(global)' must declare a body because it is not marked abstract, extern, or partial
Error CS0116 A namespace cannot directly contain members such as fields or methods
Error CS1520 Method must have a return type
...[omitted for brevity]...
trampster commented 3 years ago

Thanks for your bug report.

I have been able to reproduce the issue. Doesn't look like it should be to hard to fix.

trampster commented 3 years ago

I've committed a fix. Will be included in the next 1.1.0 alpha release.