From eede7937a60aaecf9570a732b4d95e487c688d6a Mon Sep 17 00:00:00 2001 From: Meir Blachman Date: Wed, 30 Apr 2025 16:36:01 +0300 Subject: [PATCH 1/4] add more tests for source generator --- .../OrleansSourceGeneratorTests.cs | 164 ++++++++++++++++- ...tBasicClassWithAnnotatedFields.verified.cs | 160 ++++++++++++++++ ...ateMethodSerializersAnnotation.verified.cs | 174 ++++++++++++++++++ ...thGenerateSerializerAnnotation.verified.cs | 152 +++++++++++++++ ...hInterfaceConstructorParameter.verified.cs | 135 ++++++++++++++ ...tClassWithNoPublicConstructors.verified.cs | 126 +++++++++++++ ...hOptionalConstructorParameters.verified.cs | 145 +++++++++++++++ ...thOrleansConstructorAnnotation.verified.cs | 21 +++ ...ClassWithConstructorParameters.verified.cs | 173 ++++++++++++++--- 9 files changed, 1219 insertions(+), 31 deletions(-) create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithOrleansConstructorAnnotation.verified.cs diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index e49d21f94bc..a3b0f3340d5 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -24,7 +24,7 @@ public class DemoData }"); [Fact] - public Task TestBasicClassWithFields() => AssertSuccessfulSourceGeneration( + public Task TestBasicClassWithAnnotatedFields() => AssertSuccessfulSourceGeneration( @"using Orleans; namespace TestProject; @@ -38,6 +38,7 @@ public class DemoDataWithFields [Id(1)] private readonly string _stringValue; + [GeneratedActivatorConstructor] public DemoDataWithFields(int intValue, string stringValue) { _intValue = intValue; @@ -303,7 +304,6 @@ public class CyclicClass public string Value { get; set; } }"); - [Fact] public Task TestAlias() => AssertSuccessfulSourceGeneration( @"using Orleans; @@ -388,6 +388,164 @@ public class RootType public MyServiceConsumer Consumer { get; set; } }"); + [Fact] + public Task TestGenericClassWithConstructorParameters() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +namespace TestProject; + +[GenerateSerializer] +public class GenericWithCtor +{ + [Id(0)] + private readonly T _value; + [Id(1)] + private readonly int _id; + + public GenericWithCtor(T value, int id) + { + _value = value; + _id = id; + } + + public T Value => _value; + public int Id => _id; +} + +[GenerateSerializer] +public class UsesGenericWithCtor +{ + [Id(0)] + public GenericWithCtor StringGen { get; set; } +}"); + + [Fact] + public Task TestClassWithNoPublicConstructors() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +namespace TestProject; + +[GenerateSerializer] +public class NoPublicCtor +{ + [OrleansConstructor] + private NoPublicCtor() { } + + [Id(0)] + public int Value { get; set; } +}"); + + [Fact] + public Task TestClassWithOptionalConstructorParameters() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +namespace TestProject; + +[GenerateSerializer] +public class OptionalCtorParams +{ + [Id(0)] + private readonly int _x; + [Id(1)] + private readonly string _y; + + public OptionalCtorParams(int x = 42, string y = ""default"") + { + _x = x; + _y = y; + } + + public int X => _x; + public string Y => _y; +}"); + + [Fact] + public Task TestClassWithInterfaceConstructorParameter() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +namespace TestProject; + +public interface IMyInterface { } + +[GenerateSerializer] +public class InterfaceCtorParam +{ + [Id(0)] + private readonly IMyInterface _iface; + + public InterfaceCtorParam(IMyInterface iface) + { + _iface = iface; + } + + public IMyInterface Iface => _iface; +}"); + + [Fact] + public Task TestClassesWithOrleansConstructorAnnotation() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +namespace TestProject; + +public class ClassWithOrleansConstructor +{ + [Id(0)] + public int Value { get; set; } + + [Id(1)] + public string Name { get; set; } = string.Empty; + + [OrleansConstructor] + public ClassWithOrleansConstructor(int value, string name) + { + Value = value; + Name = name; + } + + public ClassWithOrleansConstructor() { } +}"); + + [Fact] + public Task TestClassWithGenerateMethodSerializersAnnotation() => AssertSuccessfulSourceGeneration( +@"using Orleans; +using Orleans.Runtime; +using System.Threading.Tasks; + +[GenerateMethodSerializers(typeof(GrainReference))] +public interface IMyGrain : IGrainWithIntegerKey +{ + Task SayHello(string name); +}"); + + [Fact] + public Task TestClassWithGenerateSerializerAnnotation() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +namespace TestProject; + +[GenerateSerializer] +public enum MyCustomEnum +{ + None, + One, + Two, + Three +} + +[GenerateSerializer(GenerateFieldIds = GenerateFieldIds.PublicProperties), Immutable] +public class ClassWithImplicitFieldIds +{ + public string StringValue { get; } + public MyCustomEnum EnumValue { get; } + + [OrleansConstructor] + public ClassWithImplicitFieldIds(string stringValue, MyCustomEnum enumValue) + { + StringValue = stringValue; + EnumValue = enumValue; + } +}"); + [Fact] public Task TestBasicGrain() => AssertSuccessfulSourceGeneration( @"using Orleans; @@ -532,7 +690,7 @@ public class RefAsmType var root = (CSharpSyntaxNode)compilation.SyntaxTrees[0].GetRoot(); var newRoot = ((CompilationUnitSyntax)root).AddAttributeLists(assemblyAttr); var newTree = compilation.SyntaxTrees[0].WithRootAndOptions(newRoot, compilation.SyntaxTrees[0].Options); - + // leave only syntaxTree with the ReferenceAssemblyAttribute compilation = compilation.RemoveSyntaxTrees(compilation.SyntaxTrees[0]).AddSyntaxTrees(newTree); diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs new file mode 100644 index 00000000000..f17b06e34ab --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithAnnotatedFields.verified.cs @@ -0,0 +1,160 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_DemoDataWithFields : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoDataWithFields); + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + private static readonly global::System.Func getField0 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.DemoDataWithFields), "_intValue"); + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.DemoDataWithFields), "_intValue"); + private static readonly global::System.Func getField1 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.DemoDataWithFields), "_stringValue"); + private static readonly global::System.Action setField1 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.DemoDataWithFields), "_stringValue"); + public Codec_DemoDataWithFields(global::Orleans.Serialization.Activators.IActivator _activator) + { + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.DemoDataWithFields instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 0U, getField0(instance)); + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 1U, getField1(instance)); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.DemoDataWithFields instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + setField0(instance, global::Orleans.Serialization.Codecs.Int32Codec.ReadValue(ref reader, header)); + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + } + + if (id == 1U) + { + setField1(instance, global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header)); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.DemoDataWithFields @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.DemoDataWithFields)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.DemoDataWithFields ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = _activator.Create(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_DemoDataWithFields : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + private static readonly global::System.Func getField0 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.DemoDataWithFields), "_intValue"); + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.DemoDataWithFields), "_intValue"); + private static readonly global::System.Func getField1 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.DemoDataWithFields), "_stringValue"); + private static readonly global::System.Action setField1 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.DemoDataWithFields), "_stringValue"); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.DemoDataWithFields DeepCopy(global::TestProject.DemoDataWithFields original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.DemoDataWithFields existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.DemoDataWithFields)) + return context.DeepCopy(original); + var result = _activator.Create(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_DemoDataWithFields(global::Orleans.Serialization.Activators.IActivator _activator) + { + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.DemoDataWithFields input, global::TestProject.DemoDataWithFields output, global::Orleans.Serialization.Cloning.CopyContext context) + { + setField0(output, getField0(input)); + setField1(output, getField1(input)); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_DemoDataWithFields : global::Orleans.Serialization.Activators.IActivator + { + private readonly int _arg0; + private readonly string _arg1; + public Activator_DemoDataWithFields(int arg0, string arg1) + { + _arg0 = OrleansGeneratedCodeHelper.UnwrapService(this, arg0); + _arg1 = OrleansGeneratedCodeHelper.UnwrapService(this, arg1); + } + + public global::TestProject.DemoDataWithFields Create() => new global::TestProject.DemoDataWithFields(_arg0, _arg1); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_DemoDataWithFields)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_DemoDataWithFields)); + config.Activators.Add(typeof(OrleansCodeGen.TestProject.Activator_DemoDataWithFields)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs new file mode 100644 index 00000000000..8d810b5a7e6 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateMethodSerializersAnnotation.verified.cs @@ -0,0 +1,174 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::IMyGrain), "6D39E404")] + public sealed class Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Runtime.TaskRequest + { + public string arg0; + global::IMyGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::IMyGrain), "SayHello", null, new[] { typeof(string) }); + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "SayHello"; + public override string GetInterfaceName() => "IMyGrain"; + public override string GetActivityName() => "IMyGrain/SayHello"; + public override global::System.Type GetInterfaceType() => typeof(global::IMyGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IMyGrain : global::Orleans.Runtime.GrainReference, global::IMyGrain + { + public Proxy_IMyGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::IMyGrain.SayHello(string arg0) + { + var request = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_Invokable_IMyGrain_GrainReference_6D39E404 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 DeepCopy(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404(); + result.arg0 = original.arg0; + return result; + } + } +} + +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.Codec_Invokable_IMyGrain_GrainReference_6D39E404)); + config.Copiers.Add(typeof(OrleansCodeGen.Copier_Invokable_IMyGrain_GrainReference_6D39E404)); + config.InterfaceProxies.Add(typeof(OrleansCodeGen.Proxy_IMyGrain)); + config.Interfaces.Add(typeof(global::IMyGrain)); + var n1 = config.CompoundTypeAliases.Add("inv"); + var n2 = n1.Add(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.Add(typeof(global::IMyGrain)); + n3.Add("6D39E404", typeof(OrleansCodeGen.Invokable_IMyGrain_GrainReference_6D39E404)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs new file mode 100644 index 00000000000..dee4b708bfc --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithGenerateSerializerAnnotation.verified.cs @@ -0,0 +1,152 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_MyCustomEnum : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.MyCustomEnum); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.MyCustomEnum @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, fieldIdDelta, expectedType, (int)@value, _codecFieldType); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.MyCustomEnum ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + return (global::TestProject.MyCustomEnum)global::Orleans.Serialization.Codecs.Int32Codec.ReadValue(ref reader, field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_ClassWithImplicitFieldIds : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.ClassWithImplicitFieldIds); + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + private readonly global::System.Type _type0 = typeof(global::TestProject.MyCustomEnum); + private readonly OrleansCodeGen.TestProject.Codec_MyCustomEnum _codec0; + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.ClassWithImplicitFieldIds), "k__BackingField"); + private static readonly global::System.Action setField1 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.ClassWithImplicitFieldIds), "k__BackingField"); + public Codec_ClassWithImplicitFieldIds(global::Orleans.Serialization.Activators.IActivator _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + { + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + _codec0 = OrleansGeneratedCodeHelper.GetService(this, codecProvider); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.ClassWithImplicitFieldIds instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _codec0.WriteField(ref writer, 19816600U, _type0, instance.EnumValue); + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 1774218397U, instance.StringValue); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.ClassWithImplicitFieldIds instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 19816600U) + { + setField0(instance, _codec0.ReadValue(ref reader, header)); + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + } + + if (id == 1794034997U) + { + setField1(instance, global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header)); + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id++; + } + + reader.ConsumeUnknownField(ref header); + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.ClassWithImplicitFieldIds @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.ClassWithImplicitFieldIds)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.ClassWithImplicitFieldIds ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = _activator.Create(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_ClassWithImplicitFieldIds : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.ClassWithImplicitFieldIds), "k__BackingField"); + private static readonly global::System.Action setField1 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.ClassWithImplicitFieldIds), "k__BackingField"); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.ClassWithImplicitFieldIds DeepCopy(global::TestProject.ClassWithImplicitFieldIds original, global::Orleans.Serialization.Cloning.CopyContext context) + { + return original is null || original.GetType() == typeof(global::TestProject.ClassWithImplicitFieldIds) ? original : context.DeepCopy(original); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.ClassWithImplicitFieldIds input, global::TestProject.ClassWithImplicitFieldIds output, global::Orleans.Serialization.Cloning.CopyContext context) + { + setField0(output, input.EnumValue); + setField1(output, input.StringValue); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_MyCustomEnum)); + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_ClassWithImplicitFieldIds)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_ClassWithImplicitFieldIds)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs new file mode 100644 index 00000000000..077a87dad11 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithInterfaceConstructorParameter.verified.cs @@ -0,0 +1,135 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_InterfaceCtorParam : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.InterfaceCtorParam); + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + private readonly global::System.Type _type0 = typeof(global::TestProject.IMyInterface); + private readonly global::Orleans.Serialization.Codecs.IFieldCodec _codec0; + private static readonly global::System.Func getField0 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.InterfaceCtorParam), "_iface"); + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.InterfaceCtorParam), "_iface"); + public Codec_InterfaceCtorParam(global::Orleans.Serialization.Activators.IActivator _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + { + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + _codec0 = OrleansGeneratedCodeHelper.GetService>(this, codecProvider); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.InterfaceCtorParam instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _codec0.WriteField(ref writer, 0U, _type0, getField0(instance)); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.InterfaceCtorParam instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + setField0(instance, _codec0.ReadValue(ref reader, header)); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.InterfaceCtorParam @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.InterfaceCtorParam)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.InterfaceCtorParam ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = _activator.Create(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_InterfaceCtorParam : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + private readonly global::Orleans.Serialization.Cloning.IDeepCopier _copier0; + private static readonly global::System.Func getField0 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.InterfaceCtorParam), "_iface"); + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.InterfaceCtorParam), "_iface"); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.InterfaceCtorParam DeepCopy(global::TestProject.InterfaceCtorParam original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.InterfaceCtorParam existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.InterfaceCtorParam)) + return context.DeepCopy(original); + var result = _activator.Create(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_InterfaceCtorParam(global::Orleans.Serialization.Activators.IActivator _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + { + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + _copier0 = OrleansGeneratedCodeHelper.GetService>(this, codecProvider); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.InterfaceCtorParam input, global::TestProject.InterfaceCtorParam output, global::Orleans.Serialization.Cloning.CopyContext context) + { + setField0(output, _copier0.DeepCopy(getField0(input), context)); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_InterfaceCtorParam)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_InterfaceCtorParam)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs new file mode 100644 index 00000000000..ea8701df9fd --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithNoPublicConstructors.verified.cs @@ -0,0 +1,126 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_NoPublicCtor : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.NoPublicCtor); + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + public Codec_NoPublicCtor(global::Orleans.Serialization.Activators.IActivator _activator) + { + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.NoPublicCtor instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 0U, instance.Value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.NoPublicCtor instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.Value = global::Orleans.Serialization.Codecs.Int32Codec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.NoPublicCtor @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.NoPublicCtor)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.NoPublicCtor ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = _activator.Create(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_NoPublicCtor : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.NoPublicCtor DeepCopy(global::TestProject.NoPublicCtor original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.NoPublicCtor existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.NoPublicCtor)) + return context.DeepCopy(original); + var result = _activator.Create(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_NoPublicCtor(global::Orleans.Serialization.Activators.IActivator _activator) + { + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.NoPublicCtor input, global::TestProject.NoPublicCtor output, global::Orleans.Serialization.Cloning.CopyContext context) + { + output.Value = input.Value; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_NoPublicCtor)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_NoPublicCtor)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs new file mode 100644 index 00000000000..8a274da7cfe --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithOptionalConstructorParameters.verified.cs @@ -0,0 +1,145 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_OptionalCtorParams : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.OptionalCtorParams); + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + private static readonly global::System.Func getField0 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.OptionalCtorParams), "_x"); + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.OptionalCtorParams), "_x"); + private static readonly global::System.Func getField1 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.OptionalCtorParams), "_y"); + private static readonly global::System.Action setField1 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.OptionalCtorParams), "_y"); + public Codec_OptionalCtorParams(global::Orleans.Serialization.Activators.IActivator _activator) + { + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.OptionalCtorParams instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 0U, getField0(instance)); + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 1U, getField1(instance)); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.OptionalCtorParams instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + setField0(instance, global::Orleans.Serialization.Codecs.Int32Codec.ReadValue(ref reader, header)); + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + } + + if (id == 1U) + { + setField1(instance, global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header)); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.OptionalCtorParams @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.OptionalCtorParams)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.OptionalCtorParams ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = _activator.Create(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_OptionalCtorParams : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + private static readonly global::System.Func getField0 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.OptionalCtorParams), "_x"); + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.OptionalCtorParams), "_x"); + private static readonly global::System.Func getField1 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.OptionalCtorParams), "_y"); + private static readonly global::System.Action setField1 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.OptionalCtorParams), "_y"); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.OptionalCtorParams DeepCopy(global::TestProject.OptionalCtorParams original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.OptionalCtorParams existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.OptionalCtorParams)) + return context.DeepCopy(original); + var result = _activator.Create(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_OptionalCtorParams(global::Orleans.Serialization.Activators.IActivator _activator) + { + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.OptionalCtorParams input, global::TestProject.OptionalCtorParams output, global::Orleans.Serialization.Cloning.CopyContext context) + { + setField0(output, getField0(input)); + setField1(output, getField1(input)); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_OptionalCtorParams)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_OptionalCtorParams)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithOrleansConstructorAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithOrleansConstructorAnnotation.verified.cs new file mode 100644 index 00000000000..a5e225a645e --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassesWithOrleansConstructorAnnotation.verified.cs @@ -0,0 +1,21 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.verified.cs index b49105f13f5..d7d1ae17b05 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGenericClassWithConstructorParameters.verified.cs @@ -11,30 +11,32 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_GenericDemoDataWithCtorParams : global::Orleans.Serialization.Codecs.IFieldCodec>, global::Orleans.Serialization.Serializers.IBaseCodec> + public sealed class Codec_GenericWithCtor : global::Orleans.Serialization.Codecs.IFieldCodec>, global::Orleans.Serialization.Serializers.IBaseCodec> { - private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GenericDemoDataWithCtorParams); - private readonly global::Orleans.Serialization.Activators.IActivator> _activator; + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.GenericWithCtor); + private readonly global::Orleans.Serialization.Activators.IActivator> _activator; private readonly global::System.Type _type0 = typeof(T); private readonly global::Orleans.Serialization.Codecs.IFieldCodec _codec0; - private static readonly global::System.Action, int> setField0 = (global::System.Action, int>)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.GenericDemoDataWithCtorParams), "k__BackingField"); - private static readonly global::System.Action, T> setField1 = (global::System.Action, T>)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.GenericDemoDataWithCtorParams), "k__BackingField"); - public Codec_GenericDemoDataWithCtorParams(global::Orleans.Serialization.Activators.IActivator> _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + private static readonly global::System.Func, int> getField0 = (global::System.Func, int>)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.GenericWithCtor), "_id"); + private static readonly global::System.Action, int> setField0 = (global::System.Action, int>)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.GenericWithCtor), "_id"); + private static readonly global::System.Func, T> getField1 = (global::System.Func, T>)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.GenericWithCtor), "_value"); + private static readonly global::System.Action, T> setField1 = (global::System.Action, T>)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.GenericWithCtor), "_value"); + public Codec_GenericWithCtor(global::Orleans.Serialization.Activators.IActivator> _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); _codec0 = OrleansGeneratedCodeHelper.GetService>(this, codecProvider); } [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GenericDemoDataWithCtorParams instance) + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.GenericWithCtor instance) where TBufferWriter : global::System.Buffers.IBufferWriter { - _codec0.WriteField(ref writer, 0U, _type0, instance.Value); - global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 1U, instance.IntValue); + _codec0.WriteField(ref writer, 0U, _type0, getField1(instance)); + global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 1U, getField0(instance)); } [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GenericDemoDataWithCtorParams instance) + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.GenericWithCtor instance) { uint id = 0U; global::Orleans.Serialization.WireProtocol.Field header = default; @@ -65,10 +67,10 @@ public void Deserialize(ref global::Orleans.Serialization.Buffers. } [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GenericDemoDataWithCtorParams @value) + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.GenericWithCtor @value) where TBufferWriter : global::System.Buffers.IBufferWriter { - if (@value is null || @value.GetType() == typeof(global::TestProject.GenericDemoDataWithCtorParams)) + if (@value is null || @value.GetType() == typeof(global::TestProject.GenericWithCtor)) { if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) return; @@ -81,10 +83,10 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.GenericDemoDataWithCtorParams ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + public global::TestProject.GenericWithCtor ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) { if (field.IsReference) - return ReferenceCodec.ReadReference, TReaderInput>(ref reader, field); + return ReferenceCodec.ReadReference, TReaderInput>(ref reader, field); field.EnsureWireTypeTagDelimited(); global::System.Type valueType = field.FieldType; if (valueType is null || valueType == _codecFieldType) @@ -95,23 +97,25 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. return result; } - return reader.DeserializeUnexpectedType>(ref field); + return reader.DeserializeUnexpectedType>(ref field); } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_GenericDemoDataWithCtorParams : global::Orleans.Serialization.Cloning.IDeepCopier>, global::Orleans.Serialization.Cloning.IBaseCopier> + public sealed class Copier_GenericWithCtor : global::Orleans.Serialization.Cloning.IDeepCopier>, global::Orleans.Serialization.Cloning.IBaseCopier> { - private readonly global::Orleans.Serialization.Activators.IActivator> _activator; + private readonly global::Orleans.Serialization.Activators.IActivator> _activator; private readonly global::Orleans.Serialization.Cloning.IDeepCopier _copier0; - private static readonly global::System.Action, int> setField0 = (global::System.Action, int>)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.GenericDemoDataWithCtorParams), "k__BackingField"); - private static readonly global::System.Action, T> setField1 = (global::System.Action, T>)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.GenericDemoDataWithCtorParams), "k__BackingField"); + private static readonly global::System.Func, int> getField0 = (global::System.Func, int>)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.GenericWithCtor), "_id"); + private static readonly global::System.Action, int> setField0 = (global::System.Action, int>)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.GenericWithCtor), "_id"); + private static readonly global::System.Func, T> getField1 = (global::System.Func, T>)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::TestProject.GenericWithCtor), "_value"); + private static readonly global::System.Action, T> setField1 = (global::System.Action, T>)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.GenericWithCtor), "_value"); [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public global::TestProject.GenericDemoDataWithCtorParams DeepCopy(global::TestProject.GenericDemoDataWithCtorParams original, global::Orleans.Serialization.Cloning.CopyContext context) + public global::TestProject.GenericWithCtor DeepCopy(global::TestProject.GenericWithCtor original, global::Orleans.Serialization.Cloning.CopyContext context) { - if (context.TryGetCopy(original, out global::TestProject.GenericDemoDataWithCtorParams existing)) + if (context.TryGetCopy(original, out global::TestProject.GenericWithCtor existing)) return existing; - if (original.GetType() != typeof(global::TestProject.GenericDemoDataWithCtorParams)) + if (original.GetType() != typeof(global::TestProject.GenericWithCtor)) return context.DeepCopy(original); var result = _activator.Create(); context.RecordCopy(original, result); @@ -119,27 +123,140 @@ public sealed class Copier_GenericDemoDataWithCtorParams : global::Orleans.Se return result; } - public Copier_GenericDemoDataWithCtorParams(global::Orleans.Serialization.Activators.IActivator> _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + public Copier_GenericWithCtor(global::Orleans.Serialization.Activators.IActivator> _activator, global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); _copier0 = OrleansGeneratedCodeHelper.GetService>(this, codecProvider); } [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void DeepCopy(global::TestProject.GenericDemoDataWithCtorParams input, global::TestProject.GenericDemoDataWithCtorParams output, global::Orleans.Serialization.Cloning.CopyContext context) + public void DeepCopy(global::TestProject.GenericWithCtor input, global::TestProject.GenericWithCtor output, global::Orleans.Serialization.Cloning.CopyContext context) { - setField1(output, _copier0.DeepCopy(input.Value, context)); - setField0(output, input.IntValue); + setField1(output, _copier0.DeepCopy(getField1(input), context)); + setField0(output, getField0(input)); } } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_UsesGenericWithCtor : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.UsesGenericWithCtor); + private readonly global::System.Type _type0 = typeof(global::TestProject.GenericWithCtor); + private readonly OrleansCodeGen.TestProject.Codec_GenericWithCtor _codec0; + public Codec_UsesGenericWithCtor(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + { + _codec0 = OrleansGeneratedCodeHelper.GetService>(this, codecProvider); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.UsesGenericWithCtor instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _codec0.WriteField(ref writer, 0U, _type0, instance.StringGen); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.UsesGenericWithCtor instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.StringGen = _codec0.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.UsesGenericWithCtor @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.UsesGenericWithCtor)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.UsesGenericWithCtor ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.UsesGenericWithCtor(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_UsesGenericWithCtor : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly OrleansCodeGen.TestProject.Copier_GenericWithCtor _copier0; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.UsesGenericWithCtor DeepCopy(global::TestProject.UsesGenericWithCtor original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.UsesGenericWithCtor existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.UsesGenericWithCtor)) + return context.DeepCopy(original); + var result = new global::TestProject.UsesGenericWithCtor(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_UsesGenericWithCtor(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + { + _copier0 = OrleansGeneratedCodeHelper.GetService>(this, codecProvider); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.UsesGenericWithCtor input, global::TestProject.UsesGenericWithCtor output, global::Orleans.Serialization.Cloning.CopyContext context) + { + output.StringGen = _copier0.DeepCopy(input.StringGen, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_UsesGenericWithCtor : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.UsesGenericWithCtor Create() => new global::TestProject.UsesGenericWithCtor(); + } + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase { protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { - config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_GenericDemoDataWithCtorParams<>)); - config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_GenericDemoDataWithCtorParams<>)); + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_GenericWithCtor<>)); + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_UsesGenericWithCtor)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_GenericWithCtor<>)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_UsesGenericWithCtor)); + config.Activators.Add(typeof(OrleansCodeGen.TestProject.Activator_UsesGenericWithCtor)); } } } From 3165e3e790bee2129353645c163b4ccb6ecd55f3 Mon Sep 17 00:00:00 2001 From: Meir Blachman Date: Wed, 30 Apr 2025 17:20:17 +0300 Subject: [PATCH 2/4] add more tests for source generator --- .../OrleansSourceGeneratorTests.cs | 67 +++++- ...ssWithDifferentAccessModifiers.verified.cs | 221 ++++++++++++++++++ ....TestBasicClassWithInheritance.verified.cs | 186 +++++++++++++++ ...BasicClassWithInitOnlyProperty.verified.cs | 123 ++++++++++ ...TestBasicClassWithoutNamespace.verified.cs | 127 ++++++++++ ...TestClassWithFieldAndNoSetters.verified.cs | 149 ++++++++++++ ...torTests.TestGrainComplexGrain.verified.cs | 76 +++--- 7 files changed, 921 insertions(+), 28 deletions(-) create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInitOnlyProperty.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithFieldAndNoSetters.verified.cs diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index a3b0f3340d5..c865843fc08 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -18,6 +18,37 @@ namespace TestProject; [GenerateSerializer] public class DemoData +{ + [Id(0)] + public string Value { get; set; } = string.Empty; +}"); + + [Fact] + public Task TestBasicClassWithoutNamespace() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +[GenerateSerializer] +public class DemoData +{ + [Id(0)] + public string Value { get; set; } = string.Empty; +}"); + + [Fact] + public Task TestBasicClassWithDifferentAccessModifiers() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +namespace TestProject; + +[GenerateSerializer] +public class PublicDemoData +{ + [Id(0)] + public string Value { get; set; } = string.Empty; +} + +[GenerateSerializer] +internal class InternalDemoData { [Id(0)] public string Value { get; set; } = string.Empty; @@ -50,6 +81,37 @@ public DemoDataWithFields(int intValue, string stringValue) public string StringValue => _stringValue; }"); + [Fact] + public Task TestBasicClassWithInheritance() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +namespace TestProject; + +[GenerateSerializer] +public abstract class BaseData +{ + [Id(0)] + public string BaseValue { get; set; } = string.Empty; + + protected BaseData(string value) + { + BaseValue = value; + } +} + +[GenerateSerializer] +public class DerivedData : BaseData +{ + [Id(1)] + public string DerivedValue { get; set; } = string.Empty; + + [OrleansConstructor] + public DerivedData(string baseValue, string derivedValue) : base(baseValue) + { + DerivedValue = derivedValue; + } +}"); + [Fact] public Task TestBasicStruct() => AssertSuccessfulSourceGeneration( @"using Orleans; @@ -630,6 +692,7 @@ public Task> GetIntegerAndStringKey() [Fact] public Task TestGrainComplexGrain() => AssertSuccessfulSourceGeneration( @"using Orleans; +using System.Threading; using System.Threading.Tasks; namespace TestProject; @@ -646,13 +709,13 @@ public class ComplexData public interface IComplexGrain : IGrainWithIntegerKey { - Task ProcessData(int inputInt, string inputString, ComplexData data); + Task ProcessData(int inputInt, string inputString, ComplexData data, CancellationToken ctx); } [GenerateSerializer] public class ComplexGrain : Grain, IComplexGrain { - public Task ProcessData(int inputInt, string inputString, ComplexData data) + public Task ProcessData(int inputInt, string inputString, ComplexData data, CancellationToken ctx) { var result = new ComplexData { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs new file mode 100644 index 00000000000..6eb56bbdd09 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithDifferentAccessModifiers.verified.cs @@ -0,0 +1,221 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_PublicDemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.PublicDemoData); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.PublicDemoData instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.Value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.PublicDemoData instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.PublicDemoData @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.PublicDemoData)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.PublicDemoData ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.PublicDemoData(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_PublicDemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.PublicDemoData DeepCopy(global::TestProject.PublicDemoData original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.PublicDemoData existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.PublicDemoData)) + return context.DeepCopy(original); + var result = new global::TestProject.PublicDemoData(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.PublicDemoData input, global::TestProject.PublicDemoData output, global::Orleans.Serialization.Cloning.CopyContext context) + { + output.Value = input.Value; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_PublicDemoData : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.PublicDemoData Create() => new global::TestProject.PublicDemoData(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Codec_InternalDemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.InternalDemoData); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.InternalDemoData instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.Value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.InternalDemoData instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.InternalDemoData @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.InternalDemoData)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.InternalDemoData ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.InternalDemoData(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Copier_InternalDemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.InternalDemoData DeepCopy(global::TestProject.InternalDemoData original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.InternalDemoData existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.InternalDemoData)) + return context.DeepCopy(original); + var result = new global::TestProject.InternalDemoData(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.InternalDemoData input, global::TestProject.InternalDemoData output, global::Orleans.Serialization.Cloning.CopyContext context) + { + output.Value = input.Value; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_InternalDemoData : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.InternalDemoData Create() => new global::TestProject.InternalDemoData(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_PublicDemoData)); + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_InternalDemoData)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_PublicDemoData)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_InternalDemoData)); + config.Activators.Add(typeof(OrleansCodeGen.TestProject.Activator_PublicDemoData)); + config.Activators.Add(typeof(OrleansCodeGen.TestProject.Activator_InternalDemoData)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs new file mode 100644 index 00000000000..7e7a8baeade --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInheritance.verified.cs @@ -0,0 +1,186 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_BaseData : global::Orleans.Serialization.Serializers.AbstractTypeSerializer + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public override void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.BaseData instance) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.BaseValue); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public override void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.BaseData instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.BaseValue = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_BaseData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.BaseData DeepCopy(global::TestProject.BaseData original, global::Orleans.Serialization.Cloning.CopyContext context) + { + return context.DeepCopy(original); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.BaseData input, global::TestProject.BaseData output, global::Orleans.Serialization.Cloning.CopyContext context) + { + output.BaseValue = input.BaseValue; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_DerivedData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DerivedData); + private readonly OrleansCodeGen.TestProject.Codec_BaseData _baseTypeSerializer; + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + public Codec_DerivedData(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider, global::Orleans.Serialization.Activators.IActivator _activator) + { + _baseTypeSerializer = OrleansGeneratedCodeHelper.GetService(this, codecProvider); + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.DerivedData instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 1U, instance.DerivedValue); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.DerivedData instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 1U) + { + instance.DerivedValue = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id++; + } + + reader.ConsumeUnknownField(ref header); + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.DerivedData @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.DerivedData)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.DerivedData ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = _activator.Create(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_DerivedData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly OrleansCodeGen.TestProject.Copier_BaseData _baseTypeCopier; + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.DerivedData DeepCopy(global::TestProject.DerivedData original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.DerivedData existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.DerivedData)) + return context.DeepCopy(original); + var result = _activator.Create(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_DerivedData(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider, global::Orleans.Serialization.Activators.IActivator _activator) + { + _baseTypeCopier = OrleansGeneratedCodeHelper.GetService(this, codecProvider); + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.DerivedData input, global::TestProject.DerivedData output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + output.DerivedValue = input.DerivedValue; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_BaseData)); + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_DerivedData)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_BaseData)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_DerivedData)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInitOnlyProperty.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInitOnlyProperty.verified.cs new file mode 100644 index 00000000000..28401d9d332 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithInitOnlyProperty.verified.cs @@ -0,0 +1,123 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_DemoDataWithInitOnly : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoDataWithInitOnly); + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.DemoDataWithInitOnly), "k__BackingField"); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.DemoDataWithInitOnly instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.Value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.DemoDataWithInitOnly instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + setField0(instance, global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header)); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.DemoDataWithInitOnly @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.DemoDataWithInitOnly)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.DemoDataWithInitOnly ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.DemoDataWithInitOnly(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_DemoDataWithInitOnly : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::TestProject.DemoDataWithInitOnly), "k__BackingField"); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.DemoDataWithInitOnly DeepCopy(global::TestProject.DemoDataWithInitOnly original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.DemoDataWithInitOnly existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.DemoDataWithInitOnly)) + return context.DeepCopy(original); + var result = new global::TestProject.DemoDataWithInitOnly(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.DemoDataWithInitOnly input, global::TestProject.DemoDataWithInitOnly output, global::Orleans.Serialization.Cloning.CopyContext context) + { + setField0(output, input.Value); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_DemoDataWithInitOnly : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.DemoDataWithInitOnly Create() => new global::TestProject.DemoDataWithInitOnly(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_DemoDataWithInitOnly)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_DemoDataWithInitOnly)); + config.Activators.Add(typeof(OrleansCodeGen.TestProject.Activator_DemoDataWithInitOnly)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs new file mode 100644 index 00000000000..af989153c15 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestBasicClassWithoutNamespace.verified.cs @@ -0,0 +1,127 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_DemoData : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::DemoData); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::DemoData instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.Value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::DemoData instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::DemoData @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::DemoData)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::DemoData ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::DemoData(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_DemoData : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::DemoData DeepCopy(global::DemoData original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::DemoData existing)) + return existing; + if (original.GetType() != typeof(global::DemoData)) + return context.DeepCopy(original); + var result = new global::DemoData(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::DemoData input, global::DemoData output, global::Orleans.Serialization.Cloning.CopyContext context) + { + output.Value = input.Value; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_DemoData : global::Orleans.Serialization.Activators.IActivator + { + public global::DemoData Create() => new global::DemoData(); + } +} + +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.Codec_DemoData)); + config.Copiers.Add(typeof(OrleansCodeGen.Copier_DemoData)); + config.Activators.Add(typeof(OrleansCodeGen.Activator_DemoData)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithFieldAndNoSetters.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithFieldAndNoSetters.verified.cs new file mode 100644 index 00000000000..5a178a42dc5 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestClassWithFieldAndNoSetters.verified.cs @@ -0,0 +1,149 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_ExternalType : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::ExternalType); + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + private static readonly global::System.Func getField0 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::ExternalType), "Amount"); + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::ExternalType), "Amount"); + public Codec_ExternalType(global::Orleans.Serialization.Activators.IActivator _activator) + { + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::ExternalType instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 0U, getField0(instance)); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::ExternalType instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + setField0(instance, global::Orleans.Serialization.Codecs.Int32Codec.ReadValue(ref reader, header)); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::ExternalType @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::ExternalType)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::ExternalType ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = _activator.Create(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_ExternalType : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Activators.IActivator _activator; + private static readonly global::System.Func getField0 = (global::System.Func)global::Orleans.Serialization.Utilities.FieldAccessor.GetGetter(typeof(global::ExternalType), "Amount"); + private static readonly global::System.Action setField0 = (global::System.Action)global::Orleans.Serialization.Utilities.FieldAccessor.GetReferenceSetter(typeof(global::ExternalType), "Amount"); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::ExternalType DeepCopy(global::ExternalType original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::ExternalType existing)) + return existing; + if (original.GetType() != typeof(global::ExternalType)) + return context.DeepCopy(original); + var result = _activator.Create(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_ExternalType(global::Orleans.Serialization.Activators.IActivator _activator) + { + this._activator = OrleansGeneratedCodeHelper.UnwrapService(this, _activator); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::ExternalType input, global::ExternalType output, global::Orleans.Serialization.Cloning.CopyContext context) + { + setField0(output, getField0(input)); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_ExternalType : global::Orleans.Serialization.Activators.IActivator + { + private readonly int _arg0; + public Activator_ExternalType(int arg0) + { + _arg0 = OrleansGeneratedCodeHelper.UnwrapService(this, arg0); + } + + public global::ExternalType Create() => new global::ExternalType(_arg0); + } +} + +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.Codec_ExternalType)); + config.Copiers.Add(typeof(OrleansCodeGen.Copier_ExternalType)); + config.Activators.Add(typeof(OrleansCodeGen.Activator_ExternalType)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs index b9c8f979e49..7ba9a30bb7e 100644 --- a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainComplexGrain.verified.cs @@ -11,28 +11,39 @@ namespace OrleansCodeGen.TestProject using global::Orleans.Serialization.GeneratedCodeHelpers; [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IComplexGrain), "6BAEB032")] - public sealed class Invokable_IComplexGrain_GrainReference_6BAEB032 : global::Orleans.Runtime.TaskRequest + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IComplexGrain), "67FE5808")] + public sealed class Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Runtime.TaskRequest { public int arg0; public string arg1; public global::TestProject.ComplexData arg2; + public global::System.Threading.CancellationToken arg3; global::TestProject.IComplexGrain _target; - private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IComplexGrain), "ProcessData", null, new[] { typeof(int), typeof(string), typeof(global::TestProject.ComplexData) }); - public override int GetArgumentCount() => 3; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IComplexGrain), "ProcessData", null, new[] { typeof(int), typeof(string), typeof(global::TestProject.ComplexData), typeof(global::System.Threading.CancellationToken) }); + global::System.Threading.CancellationTokenSource _cts; + public override int GetArgumentCount() => 4; public override string GetMethodName() => "ProcessData"; public override string GetInterfaceName() => "TestProject.IComplexGrain"; public override string GetActivityName() => "IComplexGrain/ProcessData"; public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IComplexGrain); public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; - public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = holder.GetTarget(); + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) + { + _target = holder.GetTarget(); + _cts = new(); + arg3 = _cts.Token; + } + public override object GetTarget() => _target; public override void Dispose() { arg0 = default; arg1 = default; arg2 = default; + arg3 = default; _target = default; + _cts?.Dispose(); + _cts = default; } public override object GetArgument(int index) @@ -45,8 +56,10 @@ public override object GetArgument(int index) return arg1; case 2: return arg2; + case 3: + return arg3; default: - return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 2); + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 3); } } @@ -63,13 +76,22 @@ public override void SetArgument(int index, object value) case 2: arg2 = (global::TestProject.ComplexData)value; return; + case 3: + arg3 = (global::System.Threading.CancellationToken)value; + return; default: - OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 2); + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 3); return; } } - protected override global::System.Threading.Tasks.Task InvokeInner() => _target.ProcessData(arg0, arg1, arg2); + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.ProcessData(arg0, arg1, arg2, arg3); + public override global::System.Threading.CancellationToken GetCancellationToken() => arg3; + public override bool TryCancel() + { + _cts?.Cancel(false); + return true; + } } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] @@ -81,13 +103,14 @@ public Proxy_IComplexGrain(global::Orleans.Runtime.GrainReferenceShared arg0, gl _copier0 = OrleansGeneratedCodeHelper.GetService(this, CodecProvider); } - global::System.Threading.Tasks.Task global::TestProject.IComplexGrain.ProcessData(int arg0, string arg1, global::TestProject.ComplexData arg2) + global::System.Threading.Tasks.Task global::TestProject.IComplexGrain.ProcessData(int arg0, string arg1, global::TestProject.ComplexData arg2, global::System.Threading.CancellationToken arg3) { - var request = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB032(); + var request = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); request.arg0 = arg0; request.arg1 = arg1; using var copyContext = base.CopyContextPool.GetContext(); request.arg2 = _copier0.DeepCopy(arg2, copyContext); + request.arg3 = arg3; return base.InvokeAsync(request).AsTask(); } } @@ -201,18 +224,18 @@ internal sealed class Activator_ComplexData : global::Orleans.Serialization.Acti } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Codec_Invokable_IComplexGrain_GrainReference_6BAEB032 : global::Orleans.Serialization.Codecs.IFieldCodec + public sealed class Codec_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Codecs.IFieldCodec { - private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB032); + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808); private readonly global::System.Type _type0 = typeof(global::TestProject.ComplexData); private readonly OrleansCodeGen.TestProject.Codec_ComplexData _codec0; - public Codec_Invokable_IComplexGrain_GrainReference_6BAEB032(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + public Codec_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { _codec0 = OrleansGeneratedCodeHelper.GetService(this, codecProvider); } [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB032 instance) + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 instance) where TBufferWriter : global::System.Buffers.IBufferWriter { global::Orleans.Serialization.Codecs.Int32Codec.WriteField(ref writer, 0U, instance.arg0); @@ -221,7 +244,7 @@ public void Serialize(ref global::Orleans.Serialization.Buffers.W } [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB032 instance) + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 instance) { uint id = 0U; global::Orleans.Serialization.WireProtocol.Field header = default; @@ -261,7 +284,7 @@ public void Deserialize(ref global::Orleans.Serialization.Buffers. } [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB032 @value) + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 @value) where TBufferWriter : global::System.Buffers.IBufferWriter { if (@value is null) @@ -277,12 +300,12 @@ public void WriteField(ref global::Orleans.Serialization.Buffers. } [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB032 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) { if (field.IsReference) - return ReferenceCodec.ReadReference(ref reader, field); + return ReferenceCodec.ReadReference(ref reader, field); field.EnsureWireTypeTagDelimited(); - var result = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB032(); + var result = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); ReferenceCodec.MarkValueField(reader.Session); Deserialize(ref reader, result); return result; @@ -290,22 +313,23 @@ public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB03 } [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] - public sealed class Copier_Invokable_IComplexGrain_GrainReference_6BAEB032 : global::Orleans.Serialization.Cloning.IDeepCopier + public sealed class Copier_Invokable_IComplexGrain_GrainReference_67FE5808 : global::Orleans.Serialization.Cloning.IDeepCopier { private readonly OrleansCodeGen.TestProject.Copier_ComplexData _copier0; [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] - public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB032 DeepCopy(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB032 original, global::Orleans.Serialization.Cloning.CopyContext context) + public OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 DeepCopy(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808 original, global::Orleans.Serialization.Cloning.CopyContext context) { if (original is null) return null; - var result = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB032(); + var result = new OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808(); result.arg0 = original.arg0; result.arg1 = original.arg1; result.arg2 = _copier0.DeepCopy(original.arg2, context); + result.arg3 = original.arg3; return result; } - public Copier_Invokable_IComplexGrain_GrainReference_6BAEB032(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) + public Copier_Invokable_IComplexGrain_GrainReference_67FE5808(global::Orleans.Serialization.Serializers.ICodecProvider codecProvider) { _copier0 = OrleansGeneratedCodeHelper.GetService(this, codecProvider); } @@ -412,10 +436,10 @@ internal sealed class Metadata_TestProject : global::Orleans.Serialization.Confi protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) { config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_ComplexData)); - config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IComplexGrain_GrainReference_6BAEB032)); + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IComplexGrain_GrainReference_67FE5808)); config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_ComplexGrain)); config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_ComplexData)); - config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IComplexGrain_GrainReference_6BAEB032)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IComplexGrain_GrainReference_67FE5808)); config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_ComplexGrain)); config.InterfaceProxies.Add(typeof(OrleansCodeGen.TestProject.Proxy_IComplexGrain)); config.Interfaces.Add(typeof(global::TestProject.IComplexGrain)); @@ -425,7 +449,7 @@ protected override void ConfigureInner(global::Orleans.Serialization.Configurati var n1 = config.CompoundTypeAliases.Add("inv"); var n2 = n1.Add(typeof(global::Orleans.Runtime.GrainReference)); var n3 = n2.Add(typeof(global::TestProject.IComplexGrain)); - n3.Add("6BAEB032", typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_6BAEB032)); + n3.Add("67FE5808", typeof(OrleansCodeGen.TestProject.Invokable_IComplexGrain_GrainReference_67FE5808)); } } } From d5b10e3c3da761bfc7b9a3cb75765e2674e2b531 Mon Sep 17 00:00:00 2001 From: Meir Blachman Date: Fri, 2 May 2025 15:02:55 +0300 Subject: [PATCH 3/4] tests(code-generator): add tests for grain interfaces and method annotations --- .../OrleansSourceGeneratorTests.cs | 106 ++++++ ...AnnotatedWithInvokableBaseType.verified.cs | 272 +++++++++++++++ ...odAnnotatedWithResponseTimeout.verified.cs | 171 ++++++++++ ...estGrainWithMultipleInterfaces.verified.cs | 314 ++++++++++++++++++ 4 files changed, 863 insertions(+) create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index c865843fc08..b1218f16347 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -726,6 +726,112 @@ public Task ProcessData(int inputInt, string inputString, ComplexDa } }"); + [Fact] + public Task TestGrainWithMultipleInterfaces() => AssertSuccessfulSourceGeneration( +@"using Orleans; +using System.Threading.Tasks; + +namespace TestProject; + +public interface IGrainA : IGrainWithIntegerKey +{ + Task MethodA(string input); +} + +public interface IGrainB : IGrainWithIntegerKey +{ + Task MethodB(string input); +} + +public class RealGrain : Grain, IGrainA, IGrainB +{ + public Task MethodA(string input) + { + return Task.FromResult($""GrainA: {input}!""); + } + + public Task MethodB(string input) + { + return Task.FromResult($""GrainB: {input}!""); + } +}"); + + [Fact] + public Task TestGrainMethodAnnotatedWithResponseTimeout() => AssertSuccessfulSourceGeneration( +@"using Orleans; +using System.Threading.Tasks; + +namespace TestProject; + +public interface IResponseTimeoutGrain : IGrainWithIntegerKey +{ + [ResponseTimeout(""00:00:10"")] + Task LongRunningMethod(string input); +} + +public class ResponseTimeoutGrain : Grain, IResponseTimeoutGrain +{ + public Task LongRunningMethod(string input) + { + // Simulate a long-running operation + return Task.FromResult($""ResponseTimeoutGrain: {input}!""); + } +}"); + + [Fact] + public Task TestGrainMethodAnnotatedWithInvokableBaseType() => AssertSuccessfulSourceGeneration( +@"using Orleans; +using Orleans.Runtime; +using Orleans.Serialization.Invocation; + +using System; +using System.Threading.Tasks; +using System.Reflection; + +namespace TestProject; + +[InvokableCustomInitializer(nameof(LoggerRequest.SetLoggingOptions))] +[InvokableBaseType(typeof(GrainReference), typeof(Task), typeof(LoggerRequest))] +[AttributeUsage(AttributeTargets.Method)] +public sealed class LoggingRcpAttribute : Attribute +{ + public LoggingRcpAttribute(string options) + { + } +} + +public class LoggerRequest : RequestBase +{ + public override void Dispose() => throw new NotImplementedException(); + public override string GetActivityName() => throw new NotImplementedException(); + public override string GetInterfaceName() => throw new NotImplementedException(); + public override Type GetInterfaceType() => throw new NotImplementedException(); + public override MethodInfo GetMethod() => throw new NotImplementedException(); + public override string GetMethodName() => throw new NotImplementedException(); + public override void SetTarget(ITargetHolder holder) => throw new NotImplementedException(); + public override object GetTarget() => throw new NotImplementedException(); + public override ValueTask Invoke() => throw new NotImplementedException(); + + public void SetLoggingOptions(string options) + { + } +} + +public interface IHelloGrain : IGrainWithIntegerKey +{ + [LoggingRcp(""Hello"")] + Task SayHello(string greeting); +} + +[GenerateSerializer] +public class HelloGrain : Grain, IHelloGrain +{ + public Task SayHello(string greeting) + { + return Task.FromResult($""Hello, {greeting}!""); + } +}"); + [Fact] public async Task EmitsWarningForGenerateSerializerInReferenceAssembly() { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs new file mode 100644 index 00000000000..de6af1cf222 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithInvokableBaseType.verified.cs @@ -0,0 +1,272 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IHelloGrain), "5336307F")] + public sealed class Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Runtime.TaskRequest + { + public string arg0; + global::TestProject.IHelloGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IHelloGrain), "SayHello", null, new[] { typeof(string) }); + public Invokable_IHelloGrain_GrainReference_5336307F() : base() + { + SetLoggingOptions("Hello"); + } + + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "SayHello"; + public override string GetInterfaceName() => "TestProject.IHelloGrain"; + public override string GetActivityName() => "IHelloGrain/SayHello"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IHelloGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.SayHello(arg0); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IHelloGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IHelloGrain + { + public Proxy_IHelloGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IHelloGrain.SayHello(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_Invokable_IHelloGrain_GrainReference_5336307F : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F DeepCopy(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_HelloGrain : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.HelloGrain); + private readonly global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer; + public Codec_HelloGrain(global::Orleans.Serialization.Serializers.IBaseCodec _baseTypeSerializer) + { + this._baseTypeSerializer = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeSerializer); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.HelloGrain instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + _baseTypeSerializer.Serialize(ref writer, instance); + writer.WriteEndBase(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.HelloGrain instance) + { + _baseTypeSerializer.Deserialize(ref reader, instance); + reader.ConsumeEndBaseOrEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.HelloGrain @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.HelloGrain)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.HelloGrain ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.HelloGrain(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_HelloGrain : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + private readonly global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier; + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.HelloGrain DeepCopy(global::TestProject.HelloGrain original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.HelloGrain existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.HelloGrain)) + return context.DeepCopy(original); + var result = new global::TestProject.HelloGrain(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + public Copier_HelloGrain(global::Orleans.Serialization.Cloning.IBaseCopier _baseTypeCopier) + { + this._baseTypeCopier = OrleansGeneratedCodeHelper.UnwrapService(this, _baseTypeCopier); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.HelloGrain input, global::TestProject.HelloGrain output, global::Orleans.Serialization.Cloning.CopyContext context) + { + _baseTypeCopier.DeepCopy(input, output, context); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_HelloGrain : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.HelloGrain Create() => new global::TestProject.HelloGrain(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IHelloGrain_GrainReference_5336307F)); + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_HelloGrain)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IHelloGrain_GrainReference_5336307F)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_HelloGrain)); + config.InterfaceProxies.Add(typeof(OrleansCodeGen.TestProject.Proxy_IHelloGrain)); + config.Interfaces.Add(typeof(global::TestProject.IHelloGrain)); + config.InterfaceImplementations.Add(typeof(global::TestProject.HelloGrain)); + config.Activators.Add(typeof(OrleansCodeGen.TestProject.Activator_HelloGrain)); + var n1 = config.CompoundTypeAliases.Add("inv"); + var n2 = n1.Add(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.Add(typeof(global::TestProject.IHelloGrain)); + n3.Add("5336307F", typeof(OrleansCodeGen.TestProject.Invokable_IHelloGrain_GrainReference_5336307F)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs new file mode 100644 index 00000000000..3f9d839316b --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainMethodAnnotatedWithResponseTimeout.verified.cs @@ -0,0 +1,171 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IResponseTimeoutGrain), "6BE752C8")] + public sealed class Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Runtime.TaskRequest + { + public string arg0; + global::TestProject.IResponseTimeoutGrain _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IResponseTimeoutGrain), "LongRunningMethod", null, new[] { typeof(string) }); + private static readonly global::System.TimeSpan _responseTimeoutValue = global::System.TimeSpan.FromTicks(100000000L); + public override global::System.TimeSpan? GetDefaultResponseTimeout() => _responseTimeoutValue; + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "LongRunningMethod"; + public override string GetInterfaceName() => "TestProject.IResponseTimeoutGrain"; + public override string GetActivityName() => "IResponseTimeoutGrain/LongRunningMethod"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IResponseTimeoutGrain); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.LongRunningMethod(arg0); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IResponseTimeoutGrain : global::Orleans.Runtime.GrainReference, global::TestProject.IResponseTimeoutGrain + { + public Proxy_IResponseTimeoutGrain(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IResponseTimeoutGrain.LongRunningMethod(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 DeepCopy(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + config.InterfaceProxies.Add(typeof(OrleansCodeGen.TestProject.Proxy_IResponseTimeoutGrain)); + config.Interfaces.Add(typeof(global::TestProject.IResponseTimeoutGrain)); + config.InterfaceImplementations.Add(typeof(global::TestProject.ResponseTimeoutGrain)); + var n1 = config.CompoundTypeAliases.Add("inv"); + var n2 = n1.Add(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.Add(typeof(global::TestProject.IResponseTimeoutGrain)); + n3.Add("6BE752C8", typeof(OrleansCodeGen.TestProject.Invokable_IResponseTimeoutGrain_GrainReference_6BE752C8)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs new file mode 100644 index 00000000000..ba71676ecc1 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestGrainWithMultipleInterfaces.verified.cs @@ -0,0 +1,314 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainA), "11405B98")] + public sealed class Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Runtime.TaskRequest + { + public string arg0; + global::TestProject.IGrainA _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IGrainA), "MethodA", null, new[] { typeof(string) }); + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "MethodA"; + public override string GetInterfaceName() => "TestProject.IGrainA"; + public override string GetActivityName() => "IGrainA/MethodA"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IGrainA); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodA(arg0); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IGrainA : global::Orleans.Runtime.GrainReference, global::TestProject.IGrainA + { + public Proxy_IGrainA(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IGrainA.MethodA(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + [global::Orleans.CompoundTypeAliasAttribute("inv", typeof(global::Orleans.Runtime.GrainReference), typeof(global::TestProject.IGrainB), "6B5D7809")] + public sealed class Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Runtime.TaskRequest + { + public string arg0; + global::TestProject.IGrainB _target; + private static readonly global::System.Reflection.MethodInfo MethodBackingField = OrleansGeneratedCodeHelper.GetMethodInfoOrDefault(typeof(global::TestProject.IGrainB), "MethodB", null, new[] { typeof(string) }); + public override int GetArgumentCount() => 1; + public override string GetMethodName() => "MethodB"; + public override string GetInterfaceName() => "TestProject.IGrainB"; + public override string GetActivityName() => "IGrainB/MethodB"; + public override global::System.Type GetInterfaceType() => typeof(global::TestProject.IGrainB); + public override global::System.Reflection.MethodInfo GetMethod() => MethodBackingField; + public override void SetTarget(global::Orleans.Serialization.Invocation.ITargetHolder holder) => _target = holder.GetTarget(); + public override object GetTarget() => _target; + public override void Dispose() + { + arg0 = default; + _target = default; + } + + public override object GetArgument(int index) + { + switch (index) + { + case 0: + return arg0; + default: + return OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + } + } + + public override void SetArgument(int index, object value) + { + switch (index) + { + case 0: + arg0 = (string)value; + return; + default: + OrleansGeneratedCodeHelper.InvokableThrowArgumentOutOfRange(index, 0); + return; + } + } + + protected override global::System.Threading.Tasks.Task InvokeInner() => _target.MethodB(arg0); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Proxy_IGrainB : global::Orleans.Runtime.GrainReference, global::TestProject.IGrainB + { + public Proxy_IGrainB(global::Orleans.Runtime.GrainReferenceShared arg0, global::Orleans.Runtime.IdSpan arg1) : base(arg0, arg1) + { + } + + global::System.Threading.Tasks.Task global::TestProject.IGrainB.MethodB(string arg0) + { + var request = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); + request.arg0 = arg0; + return base.InvokeAsync(request).AsTask(); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_Invokable_IGrainA_GrainReference_11405B98 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 DeepCopy(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Codecs.IFieldCodec + { + private readonly global::System.Type _codecFieldType = typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.arg0); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.arg0 = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + var result = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_Invokable_IGrainB_GrainReference_6B5D7809 : global::Orleans.Serialization.Cloning.IDeepCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 DeepCopy(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809 original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + var result = new OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809(); + result.arg0 = original.arg0; + return result; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainA_GrainReference_11405B98)); + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_Invokable_IGrainB_GrainReference_6B5D7809)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainA_GrainReference_11405B98)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_Invokable_IGrainB_GrainReference_6B5D7809)); + config.InterfaceProxies.Add(typeof(OrleansCodeGen.TestProject.Proxy_IGrainA)); + config.InterfaceProxies.Add(typeof(OrleansCodeGen.TestProject.Proxy_IGrainB)); + config.Interfaces.Add(typeof(global::TestProject.IGrainA)); + config.Interfaces.Add(typeof(global::TestProject.IGrainB)); + config.InterfaceImplementations.Add(typeof(global::TestProject.RealGrain)); + var n1 = config.CompoundTypeAliases.Add("inv"); + var n2 = n1.Add(typeof(global::Orleans.Runtime.GrainReference)); + var n3 = n2.Add(typeof(global::TestProject.IGrainA)); + n3.Add("11405B98", typeof(OrleansCodeGen.TestProject.Invokable_IGrainA_GrainReference_11405B98)); + var n5 = n2.Add(typeof(global::TestProject.IGrainB)); + n5.Add("6B5D7809", typeof(OrleansCodeGen.TestProject.Invokable_IGrainB_GrainReference_6B5D7809)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 From 76daef7ad9ce136f683078e4d4e4eb4344f3d842 Mon Sep 17 00:00:00 2001 From: Meir Blachman Date: Fri, 2 May 2025 15:22:02 +0300 Subject: [PATCH 4/4] tests(code-generator): add tests for new serializer and activator annotations --- .../OrleansSourceGeneratorTests.cs | 69 ++++++++-- ...tDefaultMemberValuesAnnotation.verified.cs | 126 ++++++++++++++++++ ...erializerTransparentAnnotation.verified.cs | 21 +++ ...ressReferenceTrackingAttribute.verified.cs | 125 +++++++++++++++++ ...TestWithUseActivatorAnnotation.verified.cs | 22 +++ 5 files changed, 350 insertions(+), 13 deletions(-) create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSerializerTransparentAnnotation.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs create mode 100644 test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithUseActivatorAnnotation.verified.cs diff --git a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs index b1218f16347..b588e0050aa 100644 --- a/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs +++ b/test/Orleans.CodeGenerator.Tests/OrleansSourceGeneratorTests.cs @@ -782,11 +782,9 @@ public Task LongRunningMethod(string input) public Task TestGrainMethodAnnotatedWithInvokableBaseType() => AssertSuccessfulSourceGeneration( @"using Orleans; using Orleans.Runtime; -using Orleans.Serialization.Invocation; using System; using System.Threading.Tasks; -using System.Reflection; namespace TestProject; @@ -800,18 +798,8 @@ public LoggingRcpAttribute(string options) } } -public class LoggerRequest : RequestBase +public abstract class LoggerRequest : RequestBase { - public override void Dispose() => throw new NotImplementedException(); - public override string GetActivityName() => throw new NotImplementedException(); - public override string GetInterfaceName() => throw new NotImplementedException(); - public override Type GetInterfaceType() => throw new NotImplementedException(); - public override MethodInfo GetMethod() => throw new NotImplementedException(); - public override string GetMethodName() => throw new NotImplementedException(); - public override void SetTarget(ITargetHolder holder) => throw new NotImplementedException(); - public override object GetTarget() => throw new NotImplementedException(); - public override ValueTask Invoke() => throw new NotImplementedException(); - public void SetLoggingOptions(string options) { } @@ -832,6 +820,61 @@ public Task SayHello(string greeting) } }"); + [Fact] + public Task TestWithUseActivatorAnnotation() => AssertSuccessfulSourceGeneration( +@"using Orleans; +using Orleans.Serialization.Activators; + +namespace TestProject; + +[UseActivator] +public class DemoClass +{ +} + +[RegisterActivator] +internal sealed class DemoClassActivator : IActivator +{ + public DemoClass Create() => new DemoClass(); +}"); + + [Fact] + public Task TestWithSerializerTransparentAnnotation() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +namespace TestProject; + +[SerializerTransparent] +public abstract class DemoTransparentClass +{ +}"); + + [Fact] + public Task TestWithSuppressReferenceTrackingAttribute() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +namespace TestProject; + +[GenerateSerializer, SuppressReferenceTracking] +public class DemoClass +{ + [Id(0)] + public string Value { get; set; } = string.Empty; +}"); + + [Fact] + public Task TestWithOmitDefaultMemberValuesAnnotation() => AssertSuccessfulSourceGeneration( +@"using Orleans; + +namespace TestProject; + +[GenerateSerializer, OmitDefaultMemberValues] +public class DemoClass +{ + [Id(0)] + public string Value { get; set; } +}"); + [Fact] public async Task EmitsWarningForGenerateSerializerInReferenceAssembly() { diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs new file mode 100644 index 00000000000..e8d39a2ad2d --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithOmitDefaultMemberValuesAnnotation.verified.cs @@ -0,0 +1,126 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_DemoClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoClass); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.DemoClass instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + uint previousFieldId = 0U; + if (instance.Value is object) + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U - previousFieldId, instance.Value); + previousFieldId = 0U; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.DemoClass instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.DemoClass @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.DemoClass)) + { + if (ReferenceCodec.TryWriteReferenceField(ref writer, fieldIdDelta, expectedType, @value)) + return; + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.DemoClass ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.DemoClass(); + ReferenceCodec.RecordObject(reader.Session, result); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_DemoClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.DemoClass DeepCopy(global::TestProject.DemoClass original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (context.TryGetCopy(original, out global::TestProject.DemoClass existing)) + return existing; + if (original.GetType() != typeof(global::TestProject.DemoClass)) + return context.DeepCopy(original); + var result = new global::TestProject.DemoClass(); + context.RecordCopy(original, result); + DeepCopy(original, result, context); + return result; + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.DemoClass input, global::TestProject.DemoClass output, global::Orleans.Serialization.Cloning.CopyContext context) + { + output.Value = input.Value; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_DemoClass : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.DemoClass Create() => new global::TestProject.DemoClass(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_DemoClass)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_DemoClass)); + config.Activators.Add(typeof(OrleansCodeGen.TestProject.Activator_DemoClass)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSerializerTransparentAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSerializerTransparentAnnotation.verified.cs new file mode 100644 index 00000000000..a5e225a645e --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSerializerTransparentAnnotation.verified.cs @@ -0,0 +1,21 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs new file mode 100644 index 00000000000..614c3567d34 --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithSuppressReferenceTrackingAttribute.verified.cs @@ -0,0 +1,125 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Codec_DemoClass : global::Orleans.Serialization.Codecs.IFieldCodec, global::Orleans.Serialization.Serializers.IBaseCodec + { + private readonly global::System.Type _codecFieldType = typeof(global::TestProject.DemoClass); + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Serialize(ref global::Orleans.Serialization.Buffers.Writer writer, global::TestProject.DemoClass instance) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + global::Orleans.Serialization.Codecs.StringCodec.WriteField(ref writer, 0U, instance.Value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void Deserialize(ref global::Orleans.Serialization.Buffers.Reader reader, global::TestProject.DemoClass instance) + { + uint id = 0U; + global::Orleans.Serialization.WireProtocol.Field header = default; + while (true) + { + reader.ReadFieldHeader(ref header); + if (header.IsEndBaseOrEndObject) + break; + id += header.FieldIdDelta; + if (id == 0U) + { + instance.Value = global::Orleans.Serialization.Codecs.StringCodec.ReadValue(ref reader, header); + reader.ReadFieldHeader(ref header); + } + + reader.ConsumeEndBaseOrEndObject(ref header); + break; + } + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void WriteField(ref global::Orleans.Serialization.Buffers.Writer writer, uint fieldIdDelta, global::System.Type expectedType, global::TestProject.DemoClass @value) + where TBufferWriter : global::System.Buffers.IBufferWriter + { + if (@value is null || @value.GetType() == typeof(global::TestProject.DemoClass)) + { + if (@value is null) + { + ReferenceCodec.WriteNullReference(ref writer, fieldIdDelta); + return; + } + + ReferenceCodec.MarkValueField(writer.Session); + writer.WriteStartObject(fieldIdDelta, expectedType, _codecFieldType); + Serialize(ref writer, @value); + writer.WriteEndObject(); + } + else + writer.SerializeUnexpectedType(fieldIdDelta, expectedType, @value); + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.DemoClass ReadValue(ref global::Orleans.Serialization.Buffers.Reader reader, global::Orleans.Serialization.WireProtocol.Field field) + { + if (field.IsReference) + return ReferenceCodec.ReadReference(ref reader, field); + field.EnsureWireTypeTagDelimited(); + global::System.Type valueType = field.FieldType; + if (valueType is null || valueType == _codecFieldType) + { + var result = new global::TestProject.DemoClass(); + ReferenceCodec.MarkValueField(reader.Session); + Deserialize(ref reader, result); + return result; + } + + return reader.DeserializeUnexpectedType(ref field); + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + public sealed class Copier_DemoClass : global::Orleans.Serialization.Cloning.IDeepCopier, global::Orleans.Serialization.Cloning.IBaseCopier + { + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public global::TestProject.DemoClass DeepCopy(global::TestProject.DemoClass original, global::Orleans.Serialization.Cloning.CopyContext context) + { + if (original is null) + return null; + if (original.GetType() != typeof(global::TestProject.DemoClass)) + return context.DeepCopy(original); + var result = new global::TestProject.DemoClass(); + DeepCopy(original, result, context); + return result; + } + + [global::System.Runtime.CompilerServices.MethodImplAttribute(global::System.Runtime.CompilerServices.MethodImplOptions.AggressiveInlining)] + public void DeepCopy(global::TestProject.DemoClass input, global::TestProject.DemoClass output, global::Orleans.Serialization.Cloning.CopyContext context) + { + output.Value = input.Value; + } + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Activator_DemoClass : global::Orleans.Serialization.Activators.IActivator + { + public global::TestProject.DemoClass Create() => new global::TestProject.DemoClass(); + } + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Serializers.Add(typeof(OrleansCodeGen.TestProject.Codec_DemoClass)); + config.Copiers.Add(typeof(OrleansCodeGen.TestProject.Copier_DemoClass)); + config.Activators.Add(typeof(OrleansCodeGen.TestProject.Activator_DemoClass)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041 diff --git a/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithUseActivatorAnnotation.verified.cs b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithUseActivatorAnnotation.verified.cs new file mode 100644 index 00000000000..6df452ad43a --- /dev/null +++ b/test/Orleans.CodeGenerator.Tests/snapshots/OrleansSourceGeneratorTests.TestWithUseActivatorAnnotation.verified.cs @@ -0,0 +1,22 @@ +#pragma warning disable CS1591, RS0016, RS0041 +[assembly: global::Orleans.ApplicationPartAttribute("TestProject")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core.Abstractions")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Serialization")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Core")] +[assembly: global::Orleans.ApplicationPartAttribute("Orleans.Runtime")] +[assembly: global::Orleans.Serialization.Configuration.TypeManifestProviderAttribute(typeof(OrleansCodeGen.TestProject.Metadata_TestProject))] +namespace OrleansCodeGen.TestProject +{ + using global::Orleans.Serialization.Codecs; + using global::Orleans.Serialization.GeneratedCodeHelpers; + + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("OrleansCodeGen", "9.0.0.0"), global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Never), global::System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute] + internal sealed class Metadata_TestProject : global::Orleans.Serialization.Configuration.TypeManifestProviderBase + { + protected override void ConfigureInner(global::Orleans.Serialization.Configuration.TypeManifestOptions config) + { + config.Activators.Add(typeof(global::TestProject.DemoClassActivator)); + } + } +} +#pragma warning restore CS1591, RS0016, RS0041