Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add global:: to use of OneOf.OneOf in generated code #175

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions OneOf.SourceGenerator.AnalyzerTests/AnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ namespace Foo
{
partial class StringOrNumber
{
public StringOrNumber(OneOf.OneOf<string, int, uint> _) : base(_) { }
public StringOrNumber(global::OneOf.OneOf<string, int, uint> _) : base(_) { }

public static implicit operator StringOrNumber(string _) => new StringOrNumber(_);
public static explicit operator string(StringOrNumber _) => _.AsT0;
Expand Down Expand Up @@ -85,7 +85,7 @@ namespace Foo
{
partial class StringOrNumber
{
public StringOrNumber(OneOf.OneOf<string, int, uint> _) : base(_) { }
public StringOrNumber(global::OneOf.OneOf<string, int, uint> _) : base(_) { }

public static implicit operator StringOrNumber(string _) => new StringOrNumber(_);
public static explicit operator string(StringOrNumber _) => _.AsT0;
Expand Down Expand Up @@ -121,7 +121,7 @@ namespace Foo
{
partial class StringOrNumber
{
public StringOrNumber(OneOf.OneOf<string, int, uint> _) : base(_) { }
public StringOrNumber(global::OneOf.OneOf<string, int, uint> _) : base(_) { }

public static implicit operator StringOrNumber(string _) => new StringOrNumber(_);
public static explicit operator string(StringOrNumber _) => _.AsT0;
Expand Down Expand Up @@ -245,7 +245,7 @@ namespace Foo
{
partial class FooBar
{
public FooBar(OneOf.OneOf<global::Foo.Bar.Class1, global::Bar.Class2> _) : base(_) { }
public FooBar(global::OneOf.OneOf<global::Foo.Bar.Class1, global::Bar.Class2> _) : base(_) { }

public static implicit operator FooBar(global::Foo.Bar.Class1 _) => new FooBar(_);
public static explicit operator global::Foo.Bar.Class1(FooBar _) => _.AsT0;
Expand Down
20 changes: 20 additions & 0 deletions OneOf.SourceGenerator.Tests/SourceGeneratorTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using OneOf;
using Xunit;

namespace OneOf.SourceGenerator.Tests
Expand Down Expand Up @@ -129,6 +130,13 @@ public void GenerateOneOf_Works_With_Open_And_Closed_Generics()
OpenGenericWithClosed<MyClass2> openWithClosed2 = new MyClass();
Assert.True(openWithClosed2.IsT1);
}

[Fact]
public void GenerateOneOf_Works_WithTypesFromOneOfNameSpace()
{
DifferentLibrary.OneOf.JustLibraryClass justLibraryClass = new DifferentLibrary.OneOf.LibraryClass();
Assert.True(justLibraryClass.IsT0);
}
}

[GenerateOneOf]
Expand Down Expand Up @@ -184,3 +192,15 @@ public class OneOf

}
}

namespace DifferentLibrary.OneOf
{
public class LibraryClass
{
}

[GenerateOneOf]
public partial class JustLibraryClass : OneOfBase<LibraryClass>
{
}
}
2 changes: 1 addition & 1 deletion OneOf.SourceGenerator/OneOfGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ partial class {classNameWithGenericTypes}");

source.Append($@"
{{
public {classSymbol.Name}(OneOf.OneOf<{oneOfGenericPart}> _) : base(_) {{ }}
public {classSymbol.Name}(global::OneOf.OneOf<{oneOfGenericPart}> _) : base(_) {{ }}
");

foreach (var (param, arg) in paramArgPairs)
Expand Down