aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubReflection.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubReflection.cs')
-rw-r--r--Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubReflection.cs49
1 files changed, 49 insertions, 0 deletions
diff --git a/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubReflection.cs b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubReflection.cs
new file mode 100644
index 000000000..2b0f237ea
--- /dev/null
+++ b/Software/Visual_Studio/StubsUtils/Tango.StubsUtils.Service/StubReflection.cs
@@ -0,0 +1,49 @@
+using FastMember;
+using Google.Protobuf;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using System.Text;
+using System.Threading.Tasks;
+using Tango.PMR;
+using Tango.PMR.Common;
+
+namespace Tango.StubsUtils.Service
+{
+ public class StubReflection
+ {
+ public Type Type { get; set; }
+ public MessageType MessageType { get; set; }
+ public List<PropertyInfo> Properties { get; set; }
+ public TypeAccessor Accesor { get; set; }
+ public MessageParser Parser { get; set; }
+
+ public StubReflection()
+ {
+ Properties = new List<PropertyInfo>();
+ }
+
+ public static StubReflection FromStubName(String stubName, List<Type> stubTypes)
+ {
+ StubReflection reflection = new StubReflection();
+
+ var stubType = stubTypes.SingleOrDefault(x => x.Name.ToLower() == stubName.ToLower() || x.Name.Replace("Request", "").ToLower() == stubName.ToLower());
+
+ if (stubType == null)
+ {
+ throw new InvalidOperationException($"Invalid stub name '{stubName}'.");
+ }
+
+ reflection.Type = stubType;
+ reflection.MessageType = MessageFactory.ParseMessageType(reflection.Type.Name);
+ reflection.Properties = stubType.GetProperties(BindingFlags.Public | BindingFlags.Instance).ToList();
+ reflection.Accesor = TypeAccessor.Create(stubType);
+
+ var instance = Activator.CreateInstance(stubType);
+ reflection.Parser = stubType.GetProperty("Parser").GetValue(instance) as MessageParser;
+
+ return reflection;
+ }
+ }
+}