Hi,
I need to execute functions in C# code in QM, The following error message is prompted after execution
Error (RT) in <open ":1848: /157">Run_C#: 0x80131600,
<macro "Scripting_Link /97 12 2 ''Run_C#''">Run_C#(97,12): error CS1502: The best overloaded method match for 'System.Collections.Generic.List<string>.Contains(string)' has some invalid arguments
<macro "Scripting_Link /97 35 2 ''Run_C#''">Run_C#(97,35): error CS1503: Argument 1: cannot convert from 'object' to 'string'
<macro "Scripting_Link /155 9 2 ''Run_C#''">Run_C#(155,9): error CS1502: The best overloaded method match for 'System.Collections.Generic.List<string>.Contains(string)' has some invalid arguments
<macro "Scripting_Link /155 32 2 ''Run_C#''">Run_C#(155,32): error CS1503: Argument 1: cannot convert from 'object' to 'string'. <help #IDP_ERR>?
In linqpad(.net 4.8) , C# code can be executed successfully
The result of C# code execution is as follows:
┃Y_Country┃ Country[]United States[]United Kingdom[]France
---------------
My name is ┃N_Name┃, My country is ┃Y_Country┃, My age is ┃N_Age┃, thank you!
This result, which is finally split, is assigned to variables str B C
It is actually the value of variable B and variable C in C# code, In the qm code, get the value of these two variables directly? is it possible?
Thanks in advance for any advice and help
david
Macro Run_C#
I need to execute functions in C# code in QM, The following error message is prompted after execution
Error (RT) in <open ":1848: /157">Run_C#: 0x80131600,
<macro "Scripting_Link /97 12 2 ''Run_C#''">Run_C#(97,12): error CS1502: The best overloaded method match for 'System.Collections.Generic.List<string>.Contains(string)' has some invalid arguments
<macro "Scripting_Link /97 35 2 ''Run_C#''">Run_C#(97,35): error CS1503: Argument 1: cannot convert from 'object' to 'string'
<macro "Scripting_Link /155 9 2 ''Run_C#''">Run_C#(155,9): error CS1502: The best overloaded method match for 'System.Collections.Generic.List<string>.Contains(string)' has some invalid arguments
<macro "Scripting_Link /155 32 2 ''Run_C#''">Run_C#(155,32): error CS1503: Argument 1: cannot convert from 'object' to 'string'. <help #IDP_ERR>?
In linqpad(.net 4.8) , C# code can be executed successfully
The result of C# code execution is as follows:
┃Y_Country┃ Country[]United States[]United Kingdom[]France
---------------
My name is ┃N_Name┃, My country is ┃Y_Country┃, My age is ┃N_Age┃, thank you!
This result, which is finally split, is assigned to variables str B C
It is actually the value of variable B and variable C in C# code, In the qm code, get the value of these two variables directly? is it possible?
Thanks in advance for any advice and help
david
Macro Run_C#
_s=
;┋Country, United States, United Kingdom, France
;My name is ┃Name┃, My country is ┃Country┃, My age is ┃Age┃, thank you!
CsScript x
x.AddCode("")
_s=x.Call("Formater.Format" _s)
out _s
str B C
tok _s &B 2 "---------------"
out B.trim
out C.trim
#ret
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
public class Formater
{
,static void Main(string[] args)
,{
,,if (args.Length == 0)
,,{
,,,return;
,,}
,,Console.WriteLine(Format(args[0]));
,}
,static readonly Regex reLabel = new Regex("┋([^,]*),(\\s*)", RegexOptions.Compiled);
,static readonly Regex reLabel2 = new Regex(",\\s*", RegexOptions.Compiled);
,static readonly Regex reContent = new Regex("┃([^┃]*)┃", RegexOptions.Compiled);
,static readonly Regex reDelims = new Regex("\\r?\\n", RegexOptions.Compiled);
,public static string Format(string input)
,{
,,List<string> B = new List<string>();
,,List<string> C = new List<string>();
,,List<string> CLocal = new List<string>();
,,List<string> keysInContent = new List<string>();//#keys in content
,,Dictionary<string, int> dicLabelCtr = new Dictionary<string, int>(StringComparer.OrdinalIgnoreCase);
,,OrderedDictionary dicLabelLocal4B = new OrderedDictionary();
,,//# label
,,MatchEvaluator sbLabel = delegate (Match m)
,,{
,,,string k = m.Groups[1].Value;
,,,if (dicLabelCtr.ContainsKey(k))
,,,{
,,,,int ctr = ++dicLabelCtr[k];
,,,,return string.Format("┃Y_{0}{1}┃{2}{0}{1}[]", k, ctr, m.Groups[2].Value);
,,,}
,,,else
,,,{
,,,,dicLabelCtr[k] = 1;
,,,,return string.Format("┃Y_{0}┃{1}{0}[]", k, m.Groups[2].Value);
,,,}
,,};
,,//# content
,,MatchEvaluator sbContent = delegate (Match m)
,,{
,,,string k = m.Groups[1].Value;
,,,if (dicLabelLocal4B.Contains(k))
,,,{
,,,,keysInContent.Add(k);
,,,,if (dicLabelCtr.ContainsKey(k))
,,,,{
,,,,,return string.Format("┃Y_{0}{1}┃", k, dicLabelCtr[k] + 1);
,,,,}
,,,,else
,,,,{
,,,,,return string.Format("┃Y_{0}┃", k);
,,,,}
,,,}
,,,else
,,,{
,,,,return string.Format("┃N_{0}┃", k);
,,,}
,,};
,,int stack = 0;
,,foreach (var line in reDelims.Split(input))
,,{
,,,if (stack == 0)
,,,{
,,,,if (line.StartsWith("┋"))
,,,,{
,,,,,stack = 1;
,,,,,//# procossing prev section
,,,,,for (int i = 0; i < CLocal.Count; i++)
,,,,,{
,,,,,,CLocal[i] = reContent.Replace(CLocal[i], sbContent);
,,,,,}
,,,,,foreach (var key in dicLabelLocal4B.Keys)
,,,,,{
,,,,,,if (!keysInContent.Contains(key))
,,,,,,{
,,,,,,,C.Add((string)dicLabelLocal4B[key]);
,,,,,,}
,,,,,,else
,,,,,,{
,,,,,,,B.Add(reLabel2.Replace(reLabel.Replace((string)dicLabelLocal4B[key], sbLabel), "[]"));
,,,,,,}
,,,,,}
,,,,,C.AddRange(CLocal);
,,,,,CLocal.Clear();
,,,,,keysInContent.Clear();
,,,,,dicLabelLocal4B.Clear();
,,,,,//# next section
,,,,,Match m = reLabel.Match(line);
,,,,,if (m.Success)
,,,,,{
,,,,,,dicLabelLocal4B[m.Groups[1].Value] = line;
,,,,,}
,,,,,else
,,,,,{
,,,,,,dicLabelLocal4B[line] = line;
,,,,,}
,,,,}
,,,,else
,,,,{
,,,,,CLocal.Add(line);
,,,,}
,,,}
,,,else
,,,{
,,,,//#stack=1
,,,,if (line.StartsWith("┋"))
,,,,{
,,,,,Match m = reLabel.Match(line);
,,,,,if (m.Success)
,,,,,{
,,,,,,dicLabelLocal4B[m.Groups[1].Value] = line;
,,,,,}
,,,,,else
,,,,,{
,,,,,,dicLabelLocal4B[line] = line;
,,,,,}
,,,,}
,,,,else
,,,,{
,,,,,stack = 0;
,,,,,CLocal.Add(line);
,,,,}
,,,}
,,}
,,//# procossing prev section
,,for (int i = 0; i < CLocal.Count; i++)
,,{
,,,CLocal[i] = reContent.Replace(CLocal[i], sbContent);
,,}
,,foreach (var key in dicLabelLocal4B.Keys)
,,{
,,,if (!keysInContent.Contains(key))
,,,{
,,,,C.Add((string)dicLabelLocal4B[key]);
,,,}
,,,else
,,,{
,,,,B.Add(reLabel2.Replace(reLabel.Replace((string)dicLabelLocal4B[key], sbLabel), "[]"));
,,,}
,,}
,,C.AddRange(CLocal);
,,CLocal.Clear();
,,keysInContent.Clear();
,,dicLabelLocal4B.Clear();
,,//return result
,,B.Add("---------------");
,,//Merge variables B and C
,,B.AddRange(C);
,,return string.Join(Environment.NewLine, B.ToArray());
,}
}