From 1ed2ee87144b0eb108f02947b99dec6d6cb540d9 Mon Sep 17 00:00:00 2001 From: walterlv Date: Fri, 10 Feb 2023 19:07:45 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=20ulong=20=E4=BB=A3=E6=9B=BF?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2=EF=BC=8C=E8=8A=82=E7=9C=81=E4=B8=80?= =?UTF-8?q?=E7=82=B9=20IPC=20=E4=BC=A0=E8=BE=93=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Compiling/Members/IpcPublicMethodInfo.cs | 28 ++--- .../Members/IpcPublicPropertyInfo.cs | 10 +- .../Compiling/Members/MemberIdGenerator.cs | 5 +- .../GeneratedProxies/GeneratedIpcJoint.cs | 102 +++++++++--------- .../GeneratedProxies/GeneratedIpcProxy.cs | 16 +-- .../Models/GeneratedProxyMemberInvokeModel.cs | 2 +- .../GeneratedProxies/PublicIpcJointManager.cs | 2 +- .../Utils/IpcProxyInvokingHelper.cs | 2 +- 8 files changed, 82 insertions(+), 85 deletions(-) diff --git a/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/IpcPublicMethodInfo.cs b/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/IpcPublicMethodInfo.cs index 0f8d623..685e914 100644 --- a/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/IpcPublicMethodInfo.cs +++ b/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/IpcPublicMethodInfo.cs @@ -84,7 +84,7 @@ public MemberDeclarationSourceTextBuilder GenerateProxyMember(SourceTextBuilder Task {methodContainingTypeName}.{_contractMethod.Name}({parameters}) {{ - return CallMethodAsync(""{methodId}"", new Garm[] {{ {arguments} }}, {namedValues}); + return CallMethodAsync({methodId}, new Garm[] {{ {arguments} }}, {namedValues}); }} ", @@ -93,7 +93,7 @@ public MemberDeclarationSourceTextBuilder GenerateProxyMember(SourceTextBuilder Task<{returnTypeName}> {methodContainingTypeName}.{_contractMethod.Name}({parameters}) {{ - return CallMethodAsync<{returnTypeName}>(""{methodId}"", new Garm[] {{ {arguments} }}, {namedValues}); + return CallMethodAsync<{returnTypeName}>({methodId}, new Garm[] {{ {arguments} }}, {namedValues}); }} ", @@ -102,19 +102,19 @@ public MemberDeclarationSourceTextBuilder GenerateProxyMember(SourceTextBuilder ? @$" void {methodContainingTypeName}.{_contractMethod.Name}({parameters}) {{ - CallMethod(""{methodId}"", new Garm[] {{ {arguments} }}, {namedValues}).Wait(); + CallMethod({methodId}, new Garm[] {{ {arguments} }}, {namedValues}).Wait(); }}" : @$" void {methodContainingTypeName}.{_contractMethod.Name}({parameters}) {{ - _ = CallMethod(""{methodId}"", new Garm[] {{ {arguments} }}, {namedValues}); + _ = CallMethod({methodId}, new Garm[] {{ {arguments} }}, {namedValues}); }}", // 同步 T 方法。 (false, _) => $@" {returnTypeName} {methodContainingTypeName}.{_contractMethod.Name}({parameters}) {{ - return CallMethod<{returnTypeName}>(""{methodId}"", new Garm[] {{ {arguments} }}, {namedValues}).Result; + return CallMethod<{returnTypeName}>({methodId}, new Garm[] {{ {arguments} }}, {namedValues}).Result; }} ", } @@ -150,7 +150,7 @@ public MemberDeclarationSourceTextBuilder GenerateShapeMember(SourceTextBuilder /// 方法源代码。 public string GenerateJointMatch(SourceTextBuilder builder, string real) { - var memberId = MemberIdGenerator.GenerateMethodId(_contractMethod); + var methodId = MemberIdGenerator.GenerateMethodId(_contractMethod); var containingTypeName = builder.SimplifyNameByAddUsing(_contractMethod.ContainingType); var parameterTypes = GenerateMethodParameterTypes(builder, _contractMethod.Parameters); var arguments = GenerateMethodArguments(_contractMethod.Parameters); @@ -164,8 +164,8 @@ public string GenerateJointMatch(SourceTextBuilder builder, string real) // 异步 Task 方法。 var call = $"{real}.{_contractMethod.Name}({arguments})"; var sourceCode = string.IsNullOrWhiteSpace(arguments) - ? $"MatchMethod(\"{memberId}\", new Func(() => {call}));" - : $"MatchMethod(\"{memberId}\", new Func<{parameterTypes}, Task>(({arguments}) => {call}));"; + ? $"MatchMethod({methodId}, new Func(() => {call}));" + : $"MatchMethod({methodId}, new Func<{parameterTypes}, Task>(({arguments}) => {call}));"; return sourceCode; } else if (isAsync && !returnsVoid) @@ -174,8 +174,8 @@ public string GenerateJointMatch(SourceTextBuilder builder, string real) var @return = $"Task>"; var call = GenerateGarmReturn(builder, asyncReturnType!, $"await {real}.{_contractMethod.Name}({arguments}).ConfigureAwait(false)"); var sourceCode = string.IsNullOrWhiteSpace(arguments) - ? $"MatchMethod(\"{memberId}\", new Func<{@return}>(async () => {call}));" - : $"MatchMethod(\"{memberId}\", new Func<{parameterTypes}, {@return}>(async ({arguments}) => {call}));"; + ? $"MatchMethod({methodId}, new Func<{@return}>(async () => {call}));" + : $"MatchMethod({methodId}, new Func<{parameterTypes}, {@return}>(async ({arguments}) => {call}));"; return sourceCode; } else if (!isAsync && returnsVoid) @@ -183,8 +183,8 @@ public string GenerateJointMatch(SourceTextBuilder builder, string real) // 同步 void 方法。 var call = $"{real}.{_contractMethod.Name}({arguments})"; var sourceCode = string.IsNullOrWhiteSpace(arguments) - ? $"MatchMethod(\"{memberId}\", new Action(() => {call}));" - : $"MatchMethod(\"{memberId}\", new Action<{parameterTypes}>(({arguments}) => {call}));"; + ? $"MatchMethod({methodId}, new Action(() => {call}));" + : $"MatchMethod({methodId}, new Action<{parameterTypes}>(({arguments}) => {call}));"; return sourceCode; } else @@ -193,8 +193,8 @@ public string GenerateJointMatch(SourceTextBuilder builder, string real) var @return = $"Garm<{returnTypeName}>"; var call = GenerateGarmReturn(builder, _contractMethod.ReturnType, $"{real}.{_contractMethod.Name}({arguments})"); var sourceCode = string.IsNullOrWhiteSpace(arguments) - ? $"MatchMethod(\"{memberId}\", new Func<{@return}>(() => {call}));" - : $"MatchMethod(\"{memberId}\", new Func<{parameterTypes}, {@return}>(({arguments}) => {call}));"; + ? $"MatchMethod({methodId}, new Func<{@return}>(() => {call}));" + : $"MatchMethod({methodId}, new Func<{parameterTypes}, {@return}>(({arguments}) => {call}));"; return sourceCode; } } diff --git a/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/IpcPublicPropertyInfo.cs b/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/IpcPublicPropertyInfo.cs index 2f56ea7..744a3f3 100644 --- a/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/IpcPublicPropertyInfo.cs +++ b/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/IpcPublicPropertyInfo.cs @@ -74,15 +74,15 @@ public MemberDeclarationSourceTextBuilder GenerateProxyMember(SourceTextBuilder {propertyTypeName} {containingTypeName}.{_contractProperty.Name} {{ - get => GetValueAsync<{propertyTypeName}>(""{getMemberId}"", {namedValues}).Result; - set => SetValueAsync<{propertyTypeName}>(""{setMemberId}"", {valueArgumentName}, {namedValues}).Wait(); + get => GetValueAsync<{propertyTypeName}>({getMemberId}, {namedValues}).Result; + set => SetValueAsync<{propertyTypeName}>({setMemberId}, {valueArgumentName}, {namedValues}).Wait(); }} ", // get 属性。 (true, false) => $@" -{propertyTypeName} {containingTypeName}.{_contractProperty.Name} => GetValueAsync<{propertyTypeName}>(""{getMemberId}"", {namedValues}).Result; +{propertyTypeName} {containingTypeName}.{_contractProperty.Name} => GetValueAsync<{propertyTypeName}>({getMemberId}, {namedValues}).Result; ", // 不支持 set 属性。 @@ -142,12 +142,12 @@ public string GenerateJointMatch(SourceTextBuilder builder, string real) var (hasGet, hasSet) = (_contractProperty.GetMethod is not null, _contractProperty.SetMethod is not null); if (hasGet && hasSet) { - var sourceCode = $"MatchProperty(\"{getMemberId}\", \"{setMemberId}\", new Func<{garmPropertyTypeName}>(() => {garmPropertyArgumentName}), new Action<{propertyTypeName}>(value => {real}.{_contractProperty.Name} = value));"; + var sourceCode = $"MatchProperty({getMemberId}, {setMemberId}, new Func<{garmPropertyTypeName}>(() => {garmPropertyArgumentName}), new Action<{propertyTypeName}>(value => {real}.{_contractProperty.Name} = value));"; return sourceCode; } else if (hasGet) { - var sourceCode = $"MatchProperty(\"{getMemberId}\", new Func<{garmPropertyTypeName}>(() => {garmPropertyArgumentName}));"; + var sourceCode = $"MatchProperty({getMemberId}, new Func<{garmPropertyTypeName}>(() => {garmPropertyArgumentName}));"; return sourceCode; } else diff --git a/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/MemberIdGenerator.cs b/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/MemberIdGenerator.cs index 2557ae3..1e2653f 100644 --- a/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/MemberIdGenerator.cs +++ b/src/dotnetCampus.Ipc.Analyzers/SourceGenerators/Compiling/Members/MemberIdGenerator.cs @@ -19,9 +19,6 @@ private static string CalculateHash(string text) var inputBytes = Encoding.UTF8.GetBytes(text); var hashBytes = sha256.ComputeHash(inputBytes); - return BitConverter.ToString(hashBytes) - .Replace("-", "") - .Substring(0, 16) - .ToLower(CultureInfo.InvariantCulture); + return $"0x{BitConverter.ToInt64(hashBytes, 0).ToString("X")}"; } } diff --git a/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/GeneratedIpcJoint.cs b/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/GeneratedIpcJoint.cs index 86c9410..03b8958 100644 --- a/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/GeneratedIpcJoint.cs +++ b/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/GeneratedIpcJoint.cs @@ -20,10 +20,10 @@ public abstract class GeneratedIpcJoint /// /// 真实实例。 internal abstract void SetInstance(object realInstance); - internal abstract Garm GetProperty(string memberId, string propertyName); - internal abstract Garm SetProperty(string memberId, string propertyName, object? value); - internal abstract Garm CallMethod(string memberId, string methodName, object?[]? args); - internal abstract Task> CallMethodAsync(string memberId, string methodName, object?[]? args); + internal abstract Garm GetProperty(ulong memberId, string propertyName); + internal abstract Garm SetProperty(ulong memberId, string propertyName, object? value); + internal abstract Garm CallMethod(ulong memberId, string methodName, object?[]? args); + internal abstract Task> CallMethodAsync(ulong memberId, string methodName, object?[]? args); } /// @@ -35,22 +35,22 @@ public abstract class GeneratedIpcJoint : GeneratedIpcJoint where TCo /// /// 获取属性值的方法集合。 /// - private readonly Dictionary>> _propertyGetters = new(); + private readonly Dictionary>> _propertyGetters = new(); /// /// 设置属性值的方法集合(Key 为 MemberId,用于标识一个接口内的唯一一个成员,其中属性的 get 和 set 分别是两个不同的成员)。 /// - private readonly Dictionary> _propertySetters = new(); + private readonly Dictionary> _propertySetters = new(); /// /// 调用方法的方法集合(Key 为 MemberId,用于标识一个接口内的唯一一个成员,其中属性的 get 和 set 分别是两个不同的成员)。 /// - private readonly Dictionary>> _methods = new(); + private readonly Dictionary>> _methods = new(); /// /// 调用异步方法的方法集合。 /// - private readonly Dictionary>>> _asyncMethods = new(); + private readonly Dictionary>>> _asyncMethods = new(); /// /// 设置此对接对象的真实实例。 @@ -78,7 +78,7 @@ internal void SetInstance(TContract realInstance) /// 当对接时,可使用此参数来访问真实对象。 protected abstract void MatchMembers(TContract realInstance); - protected void MatchMethod(string memberId, Action methodInvoker) + protected void MatchMethod(ulong memberId, Action methodInvoker) { _methods.Add(memberId, _ => { @@ -87,7 +87,7 @@ protected void MatchMethod(string memberId, Action methodInvoker) }); } - protected void MatchMethod(string memberId, Func methodInvoker) + protected void MatchMethod(ulong memberId, Func methodInvoker) { _asyncMethods.Add(memberId, async _ => { @@ -96,7 +96,7 @@ protected void MatchMethod(string memberId, Func methodInvoker) }); } - protected void MatchMethod(string memberId, Action methodInvoker) + protected void MatchMethod(ulong memberId, Action methodInvoker) { _methods.Add(memberId, args => { @@ -105,7 +105,7 @@ protected void MatchMethod(string memberId, Action methodInvoker) }); } - protected void MatchMethod(string memberId, Func methodInvoker) + protected void MatchMethod(ulong memberId, Func methodInvoker) { _asyncMethods.Add(memberId, async args => { @@ -114,7 +114,7 @@ protected void MatchMethod(string memberId, Func methodInvoker) }); } - protected void MatchMethod(string memberId, Action methodInvoker) + protected void MatchMethod(ulong memberId, Action methodInvoker) { _methods.Add(memberId, args => { @@ -123,7 +123,7 @@ protected void MatchMethod(string memberId, Action methodInvoker }); } - protected void MatchMethod(string memberId, Func methodInvoker) + protected void MatchMethod(ulong memberId, Func methodInvoker) { _asyncMethods.Add(memberId, async args => { @@ -132,7 +132,7 @@ protected void MatchMethod(string memberId, Func methodInv }); } - protected void MatchMethod(string memberId, Action methodInvoker) + protected void MatchMethod(ulong memberId, Action methodInvoker) { _methods.Add(memberId, args => { @@ -141,7 +141,7 @@ protected void MatchMethod(string memberId, Action metho }); } - protected void MatchMethod(string memberId, Func methodInvoker) + protected void MatchMethod(ulong memberId, Func methodInvoker) { _asyncMethods.Add(memberId, async args => { @@ -150,7 +150,7 @@ protected void MatchMethod(string memberId, Func m }); } - protected void MatchMethod(string memberId, Action methodInvoker) + protected void MatchMethod(ulong memberId, Action methodInvoker) { _methods.Add(memberId, args => { @@ -159,7 +159,7 @@ protected void MatchMethod(string memberId, Action(string memberId, Func methodInvoker) + protected void MatchMethod(ulong memberId, Func methodInvoker) { _asyncMethods.Add(memberId, async args => { @@ -168,7 +168,7 @@ protected void MatchMethod(string memberId, Func(string memberId, Action methodInvoker) + protected void MatchMethod(ulong memberId, Action methodInvoker) { _methods.Add(memberId, args => { @@ -177,7 +177,7 @@ protected void MatchMethod(string memberId, Action(string memberId, Func methodInvoker) + protected void MatchMethod(ulong memberId, Func methodInvoker) { _asyncMethods.Add(memberId, async args => { @@ -186,7 +186,7 @@ protected void MatchMethod(string memberId, Func(string memberId, Action methodInvoker) + protected void MatchMethod(ulong memberId, Action methodInvoker) { _methods.Add(memberId, args => { @@ -195,7 +195,7 @@ protected void MatchMethod(string memberId, Action(string memberId, Func methodInvoker) + protected void MatchMethod(ulong memberId, Func methodInvoker) { _asyncMethods.Add(memberId, async args => { @@ -204,7 +204,7 @@ protected void MatchMethod(string memberId, Func(string memberId, Action methodInvoker) + protected void MatchMethod(ulong memberId, Action methodInvoker) { _methods.Add(memberId, args => { @@ -213,7 +213,7 @@ protected void MatchMethod(string memberId, Action(string memberId, Func methodInvoker) + protected void MatchMethod(ulong memberId, Func methodInvoker) { _asyncMethods.Add(memberId, async args => { @@ -222,7 +222,7 @@ protected void MatchMethod(string memberId, Func(string memberId, Action methodInvoker) + protected void MatchMethod(ulong memberId, Action methodInvoker) { _methods.Add(memberId, args => { @@ -231,7 +231,7 @@ protected void MatchMethod(string memberId, Acti }); } - protected void MatchMethod(string memberId, Func methodInvoker) + protected void MatchMethod(ulong memberId, Func methodInvoker) { _asyncMethods.Add(memberId, async args => { @@ -240,108 +240,108 @@ protected void MatchMethod(string memberId, Func }); } - protected void MatchMethod(string memberId, Func> methodInvoker) + protected void MatchMethod(ulong memberId, Func> methodInvoker) { _methods.Add(memberId, _ => CastReturn(methodInvoker())); } - protected void MatchMethod(string memberId, Func>> methodInvoker) + protected void MatchMethod(ulong memberId, Func>> methodInvoker) { _asyncMethods.Add(memberId, async _ => CastReturn(await methodInvoker().ConfigureAwait(false))); } - protected void MatchMethod(string memberId, Func> methodInvoker) + protected void MatchMethod(ulong memberId, Func> methodInvoker) { _methods.Add(memberId, args => CastReturn(methodInvoker(CastArg(args![0])!))); } - protected void MatchMethod(string memberId, Func>> methodInvoker) + protected void MatchMethod(ulong memberId, Func>> methodInvoker) { _asyncMethods.Add(memberId, async args => CastReturn(await methodInvoker(CastArg(args![0])!).ConfigureAwait(false))); } - protected void MatchMethod(string memberId, Func> methodInvoker) + protected void MatchMethod(ulong memberId, Func> methodInvoker) { _methods.Add(memberId, args => CastReturn(methodInvoker(CastArg(args![0])!, CastArg(args![1])!))); } - protected void MatchMethod(string memberId, Func>> methodInvoker) + protected void MatchMethod(ulong memberId, Func>> methodInvoker) { _asyncMethods.Add(memberId, async args => CastReturn(await methodInvoker(CastArg(args![0])!, CastArg(args![1])!).ConfigureAwait(false))); } - protected void MatchMethod(string memberId, Func> methodInvoker) + protected void MatchMethod(ulong memberId, Func> methodInvoker) { _methods.Add(memberId, args => CastReturn(methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!))); } - protected void MatchMethod(string memberId, Func>> methodInvoker) + protected void MatchMethod(ulong memberId, Func>> methodInvoker) { _asyncMethods.Add(memberId, async args => CastReturn(await methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!).ConfigureAwait(false))); } - protected void MatchMethod(string memberId, Func> methodInvoker) + protected void MatchMethod(ulong memberId, Func> methodInvoker) { _methods.Add(memberId, args => CastReturn(methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!, CastArg(args![3])!))); } - protected void MatchMethod(string memberId, Func>> methodInvoker) + protected void MatchMethod(ulong memberId, Func>> methodInvoker) { _asyncMethods.Add(memberId, async args => CastReturn(await methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!, CastArg(args![3])!).ConfigureAwait(false))); } - protected void MatchMethod(string memberId, Func> methodInvoker) + protected void MatchMethod(ulong memberId, Func> methodInvoker) { _methods.Add(memberId, args => CastReturn(methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!, CastArg(args![3])!, CastArg(args![4])!))); } - protected void MatchMethod(string memberId, Func>> methodInvoker) + protected void MatchMethod(ulong memberId, Func>> methodInvoker) { _asyncMethods.Add(memberId, async args => CastReturn(await methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!, CastArg(args![3])!, CastArg(args![4])!).ConfigureAwait(false))); } - protected void MatchMethod(string memberId, Func> methodInvoker) + protected void MatchMethod(ulong memberId, Func> methodInvoker) { _methods.Add(memberId, args => CastReturn(methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!, CastArg(args![3])!, CastArg(args![4])!, CastArg(args![5])!))); } - protected void MatchMethod(string memberId, Func>> methodInvoker) + protected void MatchMethod(ulong memberId, Func>> methodInvoker) { _asyncMethods.Add(memberId, async args => CastReturn(await methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!, CastArg(args![3])!, CastArg(args![4])!, CastArg(args![5])!).ConfigureAwait(false))); } - protected void MatchMethod(string memberId, Func> methodInvoker) + protected void MatchMethod(ulong memberId, Func> methodInvoker) { _methods.Add(memberId, args => CastReturn(methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!, CastArg(args![3])!, CastArg(args![4])!, CastArg(args![5])!, CastArg(args![6])!))); } - protected void MatchMethod(string memberId, Func>> methodInvoker) + protected void MatchMethod(ulong memberId, Func>> methodInvoker) { _asyncMethods.Add(memberId, async args => CastReturn(await methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!, CastArg(args![3])!, CastArg(args![4])!, CastArg(args![5])!, CastArg(args![6])!).ConfigureAwait(false))); } - protected void MatchMethod(string memberId, Func> methodInvoker) + protected void MatchMethod(ulong memberId, Func> methodInvoker) { _methods.Add(memberId, args => CastReturn(methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!, CastArg(args![3])!, CastArg(args![4])!, CastArg(args![5])!, CastArg(args![6])!, CastArg(args![7])!))); } - protected void MatchMethod(string memberId, Func>> methodInvoker) + protected void MatchMethod(ulong memberId, Func>> methodInvoker) { _asyncMethods.Add(memberId, async args => CastReturn(await methodInvoker(CastArg(args![0])!, CastArg(args![1])!, CastArg(args![2])!, CastArg(args![3])!, CastArg(args![4])!, CastArg(args![5])!, CastArg(args![6])!, CastArg(args![7])!).ConfigureAwait(false))); } - protected void MatchProperty(string getPropertyId, Func> getter) + protected void MatchProperty(ulong getPropertyId, Func> getter) { _propertyGetters.Add(getPropertyId, () => CastReturn(getter())); } - protected void MatchProperty(string getPropertyId, string setPropertyId, Func> getter, Action setter) + protected void MatchProperty(ulong getPropertyId, ulong setPropertyId, Func> getter, Action setter) { _propertyGetters.Add(getPropertyId, () => CastReturn(getter())); _propertySetters.Add(setPropertyId, value => setter(CastArg(value)!)); } - internal sealed override Garm GetProperty(string memberId, string propertyName) + internal sealed override Garm GetProperty(ulong memberId, string propertyName) { if (_propertyGetters.TryGetValue(memberId, out var getter)) { @@ -350,7 +350,7 @@ protected void MatchProperty(string getPropertyId, string setPropertyId, Func throw new NotImplementedException($"无法对接 {typeof(TContract).FullName}.{propertyName} 属性,因为没有在 {GetType().FullName} 的 IPC 对接类中进行匹配。"); } - internal sealed override Garm SetProperty(string memberId, string propertyName, object? value) + internal sealed override Garm SetProperty(ulong memberId, string propertyName, object? value) { if (_propertySetters.TryGetValue(memberId, out var setter)) { @@ -360,7 +360,7 @@ protected void MatchProperty(string getPropertyId, string setPropertyId, Func throw new NotImplementedException($"无法对接 {typeof(TContract).FullName}.{propertyName} 属性,因为没有在 {GetType().FullName} 的 IPC 对接类中进行匹配。"); } - internal sealed override Garm CallMethod(string memberId, string methodName, object?[]? args) + internal sealed override Garm CallMethod(ulong memberId, string methodName, object?[]? args) { var count = args is null ? 0 : args.Length; if (_methods.TryGetValue(memberId, out var method)) @@ -370,7 +370,7 @@ protected void MatchProperty(string getPropertyId, string setPropertyId, Func throw CreateMethodNotMatchException(memberId, methodName); } - internal sealed override async Task> CallMethodAsync(string memberId, string methodName, object?[]? args) + internal sealed override async Task> CallMethodAsync(ulong memberId, string methodName, object?[]? args) { var count = args is null ? 0 : args.Length; if (_asyncMethods.TryGetValue(memberId, out var asyncMethod)) @@ -394,7 +394,7 @@ protected void MatchProperty(string getPropertyId, string setPropertyId, Func return new Garm(argModel.Value, argModel.IpcType); } - private Exception CreateMethodNotMatchException(string memberId, string methodName) + private Exception CreateMethodNotMatchException(ulong memberId, string methodName) { return new NotImplementedException($"无法对接 Id 为 {memberId} 的 {typeof(TContract).FullName}.{methodName} 方法,因为没有在 {GetType().FullName} 的 IPC 对接类中进行匹配。"); } diff --git a/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/GeneratedIpcProxy.cs b/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/GeneratedIpcProxy.cs index 76a99ae..3477726 100644 --- a/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/GeneratedIpcProxy.cs +++ b/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/GeneratedIpcProxy.cs @@ -86,7 +86,7 @@ protected GeneratedIpcProxy() /// 包含属性上标记的调用此 IPC 属性的个性化方式。 /// 属性名称。 /// 可异步等待的属性的值。 - protected async Task GetValueAsync(string memberId, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string propertyName = "") + protected async Task GetValueAsync(ulong memberId, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string propertyName = "") { if (namedValues.IsReadonly ?? false) { @@ -116,7 +116,7 @@ protected GeneratedIpcProxy() /// 包含属性上标记的调用此 IPC 属性的个性化方式。 /// 属性名称。 /// 可异步等待的属性设置。 - protected Task SetValueAsync(string memberId, Garm value, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string propertyName = "") + protected Task SetValueAsync(ulong memberId, Garm value, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string propertyName = "") { return IpcInvokeAsync(MemberInvokingType.SetProperty, memberId, propertyName, new Garm[] { CastArg(value) }, namedValues); } @@ -128,7 +128,7 @@ protected Task SetValueAsync(string memberId, Garm value, IpcProxyMemberNa /// 包含方法上标记的调用此 IPC 方法的个性化方式。 /// 方法名。 /// 可异步等待方法返回值的可等待对象。 - protected Task CallMethod(string memberId, Garm[]? args, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string methodName = "") + protected Task CallMethod(ulong memberId, Garm[]? args, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string methodName = "") { return IpcInvokeAsync(MemberInvokingType.Method, memberId, methodName, args, namedValues); } @@ -140,7 +140,7 @@ protected Task CallMethod(string memberId, Garm[]? args, IpcProxyMember /// 包含方法上标记的调用此 IPC 方法的个性化方式。 /// 方法名。 /// 可异步等待方法返回值的可等待对象。 - protected Task CallMethod(string memberId, Garm[]? args, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string methodName = "") + protected Task CallMethod(ulong memberId, Garm[]? args, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string methodName = "") { return IpcInvokeAsync(MemberInvokingType.Method, memberId, methodName, args, namedValues); } @@ -152,7 +152,7 @@ protected Task CallMethod(string memberId, Garm[]? args, IpcProxyMember /// 包含方法上标记的调用此 IPC 方法的个性化方式。 /// 方法名。 /// 可异步等待方法返回值的可等待对象。 - protected Task CallMethodAsync(string memberId, Garm[]? args, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string methodName = "") + protected Task CallMethodAsync(ulong memberId, Garm[]? args, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string methodName = "") { return IpcInvokeAsync(MemberInvokingType.AsyncMethod, memberId, methodName, args, namedValues); } @@ -164,7 +164,7 @@ protected Task CallMethodAsync(string memberId, Garm[]? args, IpcProxyM /// 包含方法上标记的调用此 IPC 方法的个性化方式。 /// 方法名。 /// 可异步等待方法返回值的可等待对象。 - protected Task CallMethodAsync(string memberId, Garm[]? args, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string methodName = "") + protected Task CallMethodAsync(ulong memberId, Garm[]? args, IpcProxyMemberNamedValues namedValues, [CallerMemberName] string methodName = "") { return IpcInvokeAsync(MemberInvokingType.AsyncMethod, memberId, methodName, args, namedValues); } @@ -178,7 +178,7 @@ protected Task CallMethodAsync(string memberId, Garm[]? args, IpcProxyM /// 调用参数。 /// 包含属性上标记的调用此 IPC 成员的个性化方式。 /// 可异步等待方法返回值的可等待对象。 - private async Task IpcInvokeAsync(MemberInvokingType callType, string memberId, string memberName, Garm[]? args, IpcProxyMemberNamedValues namedValues) + private async Task IpcInvokeAsync(MemberInvokingType callType, ulong memberId, string memberName, Garm[]? args, IpcProxyMemberNamedValues namedValues) { var ignoresIpcException = namedValues.IgnoresIpcException ?? RuntimeConfigs?.IgnoresIpcException ?? false; try @@ -224,7 +224,7 @@ protected Task CallMethodAsync(string memberId, Garm[]? args, IpcProxyM } } - private async Task InvokeWithTimeoutAsync(MemberInvokingType callType, string memberId, string memberName, Garm[]? args, + private async Task InvokeWithTimeoutAsync(MemberInvokingType callType, ulong memberId, string memberName, Garm[]? args, int millisecondsTimeout, bool ignoreException, object? defaultReturn) { var ipcTask = Invoker.IpcInvokeAsync(callType, memberId, memberName, args); diff --git a/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/Models/GeneratedProxyMemberInvokeModel.cs b/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/Models/GeneratedProxyMemberInvokeModel.cs index deffdd4..9684376 100644 --- a/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/Models/GeneratedProxyMemberInvokeModel.cs +++ b/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/Models/GeneratedProxyMemberInvokeModel.cs @@ -42,7 +42,7 @@ public string Id /// 调用的成员 Id(由源代码生成器自动生成,唯一表示一个属性或方法)。 /// [DataMember(Name = "d")] - public string? MemberId { get; internal set; } + public ulong MemberId { get; internal set; } /// /// 调用的成员名称(属性名、方法名)。 diff --git a/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/PublicIpcJointManager.cs b/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/PublicIpcJointManager.cs index 7b381f5..fae903f 100644 --- a/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/PublicIpcJointManager.cs +++ b/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/PublicIpcJointManager.cs @@ -207,7 +207,7 @@ private GeneratedProxyMemberReturnModel CreateReturnModelFromReturnObject(Garm> InvokeMember(GeneratedIpcJoint joint, MemberInvokingType callType, string memberId, string memberName, object?[]? args) + private static async Task> InvokeMember(GeneratedIpcJoint joint, MemberInvokingType callType, ulong memberId, string memberName, object?[]? args) { return callType switch { diff --git a/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/Utils/IpcProxyInvokingHelper.cs b/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/Utils/IpcProxyInvokingHelper.cs index 436a30f..2c479ba 100644 --- a/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/Utils/IpcProxyInvokingHelper.cs +++ b/src/dotnetCampus.Ipc/CompilerServices/GeneratedProxies/Utils/IpcProxyInvokingHelper.cs @@ -44,7 +44,7 @@ internal string TypeName /// internal string? ObjectId { get; set; } - internal async Task IpcInvokeAsync(MemberInvokingType callType, string memberId, string memberName, Garm[]? args) + internal async Task IpcInvokeAsync(MemberInvokingType callType, ulong memberId, string memberName, Garm[]? args) { if (PeerProxy is null) {