forked from Xamla/ROS.NET
-
Notifications
You must be signed in to change notification settings - Fork 2
/
MessageFieldHelper.cs
69 lines (67 loc) · 2.59 KB
/
MessageFieldHelper.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using YAMLParser;
namespace FauxMessages
{
public static class MessageFieldHelper
{
public static string Generate(SingleType members)
{
string mt = "xamla/unknown";
string pt = KnownStuff.GetNamespacedType(members);
if (members.meta)
{
string t = members.Type.Replace("Messages.", "");
if (!t.Contains('.'))
{
if (members.Definer != null)
{
t = members.Definer.Package + "." + t;
}
else
{
t = null;
}
}
if (t != null)
mt = t.Replace(".", "/");
else
members.meta = false;
}
return String.Format
("\"{0}\", new MsgFieldInfo(\"{0}\", {1}, {2}, {3}, \"{4}\", {5}, \"{6}\", {7}, {8})",
members.Name.Replace("@", ""),
members.IsLiteral.ToString().ToLower(),
("typeof(" + pt + ")"),
members.Const.ToString().ToLower(),
members.ConstValue.TrimStart('"').TrimEnd('"'),
//members.Type.Equals("string", StringComparison.InvariantCultureIgnoreCase) ? ("new String("+members.ConstValue+")") : ("\""+members.ConstValue+"\""),
members.IsArray.ToString().ToLower(),
members.length,
//FIX MEEEEEEEE
members.meta.ToString().ToLower(),
mt);
}
public static KeyValuePair<string, MsgFieldInfo> Instantiate(SingleType member)
{
string mt = "xamla/unknown";
if (member.meta)
{
string t = member.Type.Replace("Messages.", "");
if (!t.Contains('.'))
t = "std_msgs." + t;
mt = t.Replace(".", "/");
}
return new KeyValuePair<string, MsgFieldInfo>(member.Name, new MsgFieldInfo(member.Name, member.IsLiteral, member.Type, member.Const, member.ConstValue, member.IsArray, member.length, member.meta));
}
public static Dictionary<string, MsgFieldInfo> Instantiate(IEnumerable<SingleType> stuff)
{
return stuff.Select(Instantiate).ToDictionary(field => field.Key, field => field.Value);
}
}
}