Skip to content

Commit

Permalink
Adding global to attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
Laszlo Deak committed Feb 7, 2023
1 parent 9233bfd commit 420cff9
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 51 deletions.
4 changes: 2 additions & 2 deletions ProtobufSourceGenerator.Tests/AnalyzerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class SomeEntity
[ProtoBuf.ProtoContract]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
public SomeEntity Id { get; set; }
}";
var test = new AnalyzeCS() { TestCode = code };
Expand All @@ -76,7 +76,7 @@ public class SomeEntity
[ProtoBuf.ProtoContract]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
public SomeEntity Id { get; set; }
}";
var test = new AnalyzeCS() { TestCode = code };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ public partial class Entity
var generated = @"// <auto-generated/>
#nullable enable
namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";
var test = new VerifyCS.Test
Expand Down Expand Up @@ -62,10 +62,10 @@ public record SomeEntity
var generated = @"// <auto-generated/>
#nullable enable
namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";
var test = new VerifyCS.Test
Expand Down Expand Up @@ -101,10 +101,10 @@ public class SomeEntity
var generated = @"// <auto-generated/>
#nullable enable
namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";

Expand Down Expand Up @@ -142,10 +142,10 @@ public partial class SomeEntity
var generatedEntity = @"// <auto-generated/>
#nullable enable
namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";

Expand All @@ -154,10 +154,10 @@ public partial class Entity
namespace Test;
public partial class Entity
{
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial class SomeEntity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}
}";
Expand All @@ -182,7 +182,7 @@ public partial class SomeEntity
public async Task WithGeneratingInner_NonGeneratingParentClass()
{
var code = @"namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public class Entity
{
[ProtoBuf.ProtoContract]
Expand Down Expand Up @@ -246,10 +246,10 @@ public partial class Entity
var generated = @"// <auto-generated/>
#nullable enable
namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private string? ProtoId { get => Id; set => Id = value; }
}";

Expand Down Expand Up @@ -282,10 +282,10 @@ public partial class Entity
var generated = @"// <auto-generated/>
#nullable enable
namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private System.Collections.Generic.List<string?> ProtoId { get => Id; set => Id = value; }
}";

Expand Down Expand Up @@ -318,10 +318,10 @@ public partial class Entity
var generated = @"// <auto-generated/>
#nullable enable
namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private System.Collections.Generic.List<int?>? ProtoId { get => Id; set => Id = value; }
}";

Expand Down Expand Up @@ -354,10 +354,10 @@ public partial class Entity
var generated = @"// <auto-generated/>
#nullable enable
namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int? ProtoId { get => Id; set => Id = value; }
}";

Expand All @@ -384,7 +384,7 @@ public async Task ProtoMemberProperty_DoesNotGetGenerated()
[ProtoBuf.ProtoContract]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
public int Id { get; set; }
}";

Expand Down Expand Up @@ -434,7 +434,7 @@ public async Task ProtoMemberNumberedProperty_DoesNotGetGenerated()
[ProtoBuf.ProtoContract]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
public int Id { get; set; }
public string Value { get; set; }
Expand All @@ -443,10 +443,10 @@ public partial class Entity
var generated = @"// <auto-generated/>
#nullable enable
namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial class Entity
{
[ProtoBuf.ProtoMember(2)]
[global::ProtoBuf.ProtoMember(2)]
private string ProtoValue { get => Value; set => Value = value; }
}";

Expand Down Expand Up @@ -478,10 +478,10 @@ public partial record Entity
var generated = @"// <auto-generated/>
#nullable enable
namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial record class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";
var test = new VerifyCS.Test
Expand Down Expand Up @@ -512,10 +512,10 @@ public partial struct Entity
var generated = @"// <auto-generated/>
#nullable enable
namespace Test;
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial struct Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";
var test = new VerifyCS.Test
Expand Down Expand Up @@ -543,10 +543,10 @@ public partial class Entity

var generated = @"// <auto-generated/>
#nullable enable
[System.Runtime.CompilerServices.CompilerGeneratedAttribute]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";
var test = new VerifyCS.Test
Expand Down
28 changes: 14 additions & 14 deletions ProtobufSourceGenerator.Tests/ProtoGeneratorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public partial class Entity
namespace Test;
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";
var test = new VerifyCS.Test
Expand Down Expand Up @@ -60,7 +60,7 @@ public record SomeEntity
namespace Test;
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";
var test = new VerifyCS.Test
Expand Down Expand Up @@ -97,7 +97,7 @@ public class SomeEntity
namespace Test;
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";

Expand Down Expand Up @@ -136,7 +136,7 @@ public partial class SomeEntity
namespace Test;
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";

Expand All @@ -146,7 +146,7 @@ public partial class Entity
{
public partial class SomeEntity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}
}";
Expand Down Expand Up @@ -236,7 +236,7 @@ public partial class Entity
namespace Test;
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private string? ProtoId { get => Id; set => Id = value; }
}";

Expand Down Expand Up @@ -270,7 +270,7 @@ public partial class Entity
namespace Test;
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private System.Collections.Generic.List<string?> ProtoId { get => Id; set => Id = value; }
}";

Expand Down Expand Up @@ -304,7 +304,7 @@ public partial class Entity
namespace Test;
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private System.Collections.Generic.List<int?>? ProtoId { get => Id; set => Id = value; }
}";

Expand Down Expand Up @@ -338,7 +338,7 @@ public partial class Entity
namespace Test;
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int? ProtoId { get => Id; set => Id = value; }
}";

Expand All @@ -365,7 +365,7 @@ public async Task ProtoMemberProperty_DoesNotGetGenerated()
[ProtoBuf.ProtoContract]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
public int Id { get; set; }
}";

Expand Down Expand Up @@ -415,7 +415,7 @@ public async Task ProtoMemberNumberedProperty_DoesNotGetGenerated()
[ProtoBuf.ProtoContract]
public partial class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
public int Id { get; set; }
public string Value { get; set; }
Expand All @@ -425,7 +425,7 @@ public partial class Entity
namespace Test;
public partial class Entity
{
[ProtoBuf.ProtoMember(2)]
[global::ProtoBuf.ProtoMember(2)]
private string ProtoValue { get => Value; set => Value = value; }
}";

Expand Down Expand Up @@ -458,7 +458,7 @@ public partial record Entity
namespace Test;
public partial record class Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";
var test = new VerifyCS.Test
Expand Down Expand Up @@ -490,7 +490,7 @@ public partial struct Entity
namespace Test;
public partial struct Entity
{
[ProtoBuf.ProtoMember(1)]
[global::ProtoBuf.ProtoMember(1)]
private int ProtoId { get => Id; set => Id = value; }
}";
var test = new VerifyCS.Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public string CreateClass(ProtoClassDataModel classModel)
SyntaxFactory.AttributeList(
SyntaxFactory.SingletonSeparatedList(
SyntaxFactory.Attribute(
SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("ProtoBuf"), SyntaxFactory.IdentifierName("ProtoMember")))
SyntaxFactory.QualifiedName(SyntaxFactory.AliasQualifiedName(
SyntaxFactory.IdentifierName(SyntaxFactory.Token(SyntaxKind.GlobalKeyword)), SyntaxFactory.IdentifierName("ProtoBuf")), SyntaxFactory.IdentifierName("ProtoMember")))
.WithArgumentList(
SyntaxFactory.AttributeArgumentList(
SyntaxFactory.SingletonSeparatedList(
Expand All @@ -54,7 +55,8 @@ public string CreateClass(ProtoClassDataModel classModel)
typeSyntax = typeSyntax.WithAttributeLists(SyntaxFactory.SingletonList(
SyntaxFactory.AttributeList(SyntaxFactory.SingletonSeparatedList(
SyntaxFactory.Attribute(
SyntaxFactory.QualifiedName(SyntaxFactory.QualifiedName(SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("System"), SyntaxFactory.IdentifierName("Runtime")), SyntaxFactory.IdentifierName("CompilerServices")), SyntaxFactory.IdentifierName("CompilerGeneratedAttribute")))))));
SyntaxFactory.QualifiedName(SyntaxFactory.QualifiedName(SyntaxFactory.QualifiedName(SyntaxFactory.AliasQualifiedName(
SyntaxFactory.IdentifierName(SyntaxFactory.Token(SyntaxKind.GlobalKeyword)), SyntaxFactory.IdentifierName("System")), SyntaxFactory.IdentifierName("Runtime")), SyntaxFactory.IdentifierName("CompilerServices")), SyntaxFactory.IdentifierName("CompilerGeneratedAttribute")))))));

// For all parent types, we wrap the inner type
while (classModel.Parent is { } parentClass)
Expand Down
4 changes: 2 additions & 2 deletions ProtobufSourceGenerator/ProtoClassGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ private string CreateClass(IEnumerable<PropertyShadowInfo> propertyShadows)
var protoMemberAttribute = SyntaxFactory.SingletonList(
SyntaxFactory.AttributeList(
SyntaxFactory.SingletonSeparatedList(
SyntaxFactory.Attribute(
SyntaxFactory.QualifiedName(SyntaxFactory.IdentifierName("ProtoBuf"), SyntaxFactory.IdentifierName("ProtoMember")))
SyntaxFactory.Attribute(SyntaxFactory.QualifiedName(SyntaxFactory.AliasQualifiedName(
SyntaxFactory.IdentifierName(SyntaxFactory.Token(SyntaxKind.GlobalKeyword)), SyntaxFactory.IdentifierName("ProtoBuf")), SyntaxFactory.IdentifierName("ProtoMember")))
.WithArgumentList(
SyntaxFactory.AttributeArgumentList(
SyntaxFactory.SingletonSeparatedList(
Expand Down
4 changes: 2 additions & 2 deletions SampleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using SampleApp;

using var ms = new MemoryStream();
Serializer.Serialize(ms, new InitEntity() { Id = 1 });
Serializer.Serialize(ms, new Entity() { Id = 1 });
ms.Seek(0, SeekOrigin.Begin);
var entity = Serializer.Deserialize<InitEntity>(ms);
var entity = Serializer.Deserialize<Entity>(ms);
Console.WriteLine(entity.Id);

0 comments on commit 420cff9

Please sign in to comment.