aboutsummaryrefslogtreecommitdiffstats
path: root/Software
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2017-11-02 12:38:04 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2017-11-02 12:38:04 +0200
commit78f085920bc5912e18d0192c1f5d391d653bcb0c (patch)
treebea4527a953f2446bd68de5a488bf6bdfd9f440d /Software
parent142676bf7b5b9959c64fdbd3f28127ad74cf29f7 (diff)
downloadTango-78f085920bc5912e18d0192c1f5d391d653bcb0c.tar.gz
Tango-78f085920bc5912e18d0192c1f5d391d653bcb0c.zip
Added compiler factory for language string.
Diffstat (limited to 'Software')
-rw-r--r--Software/Visual Studio/Tango.Protobuf/CompilerFactory.cs21
1 files changed, 21 insertions, 0 deletions
diff --git a/Software/Visual Studio/Tango.Protobuf/CompilerFactory.cs b/Software/Visual Studio/Tango.Protobuf/CompilerFactory.cs
index 6b08d8310..7c0ee54a4 100644
--- a/Software/Visual Studio/Tango.Protobuf/CompilerFactory.cs
+++ b/Software/Visual Studio/Tango.Protobuf/CompilerFactory.cs
@@ -48,5 +48,26 @@ namespace Tango.Protobuf
return compilers;
}
+
+ /// <summary>
+ /// Creates a protobuf compiler instance by the specified language string.
+ /// </summary>
+ /// <param name="language">The language.</param>
+ /// <returns></returns>
+ /// <exception cref="ArgumentException">Could not locate protobuf compiler for language " + language.ToString()</exception>
+ public static IProtoCompiler CreateCompiler(String language)
+ {
+ LogManager.Log("Generating protobuf compiler for " + language.ToString() + "...");
+
+ CompilerLanguage lan = (CompilerLanguage)Enum.Parse(typeof(CompilerLanguage), language, true);
+
+ foreach (var cType in typeof(CompilerFactory).Assembly.GetTypes().Where(x => x.IsClass && !x.IsAbstract && typeof(IProtoCompiler).IsAssignableFrom(x)))
+ {
+ var instance = Activator.CreateInstance(cType) as IProtoCompiler;
+ if (instance.Language == lan) return instance;
+ }
+
+ throw LogManager.Log(new ArgumentException("Could not locate protobuf compiler for language " + language.ToString()));
+ }
}
}