CSharpCompilerSettingsForUnity icon indicating copy to clipboard operation
CSharpCompilerSettingsForUnity copied to clipboard

Support C# 9 Source Generators

Open shwuhk opened this issue 3 years ago • 5 comments

Thanks for building this great project. I tried this project and it works great with C# 9 syntax. However, I cannot make it work with C# 9 Source Generators. May I know if this support? I am using Unity 2020.3.

shwuhk avatar Apr 06 '21 19:04 shwuhk

I have the same question.

shtse8 avatar Apr 11 '21 06:04 shtse8

@mob-sakai any comments here?

hellozyemlya avatar Jun 28 '21 11:06 hellozyemlya

@shwuhk @shtse8 @hellozyemlya Sorry for my late reply. I'm working on this feature. It will be released soon!

mob-sakai avatar Dec 14 '21 07:12 mob-sakai

@shwuhk @shtse8 @hellozyemlya v1.5.0 supports source generator packages 👍

UnitGenerator example:

image

#if CUSTOM_COMPILE // This directive is required for Unity 2021.1 or later.
using NUnit.Framework;

namespace SourceGenerator
{
    public class Unit
    {
        [Test]
        public void UnitToString()
        {
            var userId = new UserId(1234);
            Assert.AreEqual("UserId(1234)", userId.ToString());
        }

        [Test]
        public void AsPrimitive()
        {
            var userId = new UserId(1234);
            Assert.AreEqual(1234, userId.AsPrimitive());
        }
    }

    [UnitGenerator.UnitOf(typeof(int))]
    public readonly partial struct UserId { }
}
#endif

mob-sakai avatar Dec 22 '21 21:12 mob-sakai

Feature looks great testing it now. Do I understand correctly that source genrator has to be in NuGet? Is it possible to add custom generators by adding dll to the project?

slimshader avatar Mar 15 '22 20:03 slimshader