From 13311493cb1659ff11dc12f50e8f33f86ced7669 Mon Sep 17 00:00:00 2001 From: MaZiFAU <63099053+MaZiFAU@users.noreply.github.com> Date: Mon, 18 Sep 2023 02:48:14 +0200 Subject: [PATCH] Minor Bugfix and Unsupported cases for AnonymousTypes --- .../CommunicationProtocoll/MMTConstants.cs | 7 ++++--- .../SOMDocToLambdaExpression.cs | 4 +++- .../MMTServer/CommunicationProtocoll/SOMDocs.cs | 14 ++++++++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs b/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs index 27a7ec08..3c50a79e 100644 --- a/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs +++ b/Assets/Scripts/MMTServer/CommunicationProtocoll/MMTConstants.cs @@ -222,15 +222,16 @@ public static class MMTConstants Product }, { MakeType, MakeTypeType }, - // needed? - //{ MakeTypeType, - // MakeTypeType }, + { MakeTypeType, + MakeTypeType }, }; public static readonly IReadOnlyDictionary<string, string> TypeOF_TO_HeterogenApplication = HeterogenApplication_TO_TypeOF.ReverseKeyVal(); public static readonly IReadOnlyDictionary<string, string> HomogenApplication_TO_TypeOF = new Dictionary<string, string> { { ListApplicant, ListType }, + { ListType, + ListType }, }; public static readonly IReadOnlyDictionary<string, string> TypeOF_TO_HomogenApplication = HomogenApplication_TO_TypeOF.ReverseKeyVal(); diff --git a/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs b/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs index f3029556..24fd247a 100644 --- a/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs +++ b/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocToLambdaExpression.cs @@ -289,7 +289,9 @@ void ThrowArgumentException(ExpressionType expression_cast, int expected) int free_params = lambda_lambda.Parameters.Count() - lambda_applicant.Length; if (free_params <= 0) return Expression.Lambda( - Expression.Invoke(lambda_lambda, lambda_applicant[..^Math.Max(0, free_params)]), + Expression.Invoke( + lambda_lambda, + lambda_applicant.Select(app => app.Body).Take(lambda_lambda.Parameters.Count())), found_bound_params ); diff --git a/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocs.cs b/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocs.cs index ec522d4c..8f70b595 100644 --- a/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocs.cs +++ b/Assets/Scripts/MMTServer/CommunicationProtocoll/SOMDocs.cs @@ -82,7 +82,10 @@ public static SOMDoc SOMDocType(Type type) type = typeof(Tuple); if (type.HasElementType) // pretend its a List - type = typeof(List<>); // Dictionary does not like Generics + type = typeof(List<>); + + if (type.IsGenericType) // Dictionary does not like Assembled Generics + type = type.GetGenericTypeDefinition(); if (FuncExtensions.IsFuncType(type, out _)) @@ -93,6 +96,13 @@ public static SOMDoc SOMDocType(Type type) ? new OMA(new OMS(uri), args) : new OMS(uri); + if (type.IsAnonymousType()) + return new OMA( + new OMS(MMTConstants.MakeTypeType), + type.GetFields() + .Select(mem => new OML_Member(mem.Name, SOMDocType(mem.FieldType), null)) + .ToArray()); + throw new NotImplementedException($"For Type {type}"); } @@ -554,7 +564,7 @@ protected internal override Type ToType(Type[] args, (string name, Type type)[] { if (FactRecorder.AllFacts.TryGetValue(uri, out Fact found)) return found.GetType(); - + if (MMTConstants.HeterogenApplication_TO_TypeOF.TryGetValue(uri, out string s_type)) { Type type = MMTConstants.OMS_TO_TYPE[s_type]; -- GitLab