Replies: 3 comments
-
Here is almost ready to go example: |
Beta Was this translation helpful? Give feedback.
-
You said what you didn't want to do - reflection - but you didn't say what you want to do instead of reflection. Would it be okay to still use reflection, but at compile time, and then generate some code like "new MyType()" to run at runtime? If so, please give an example of the kind of code you would like to generate. There is no equivalent to One notable challenge to doing something like this at compile-time is that the standard workflow for using EC# is to use a single-file generator in EC#. If you use the single-file generator approach, then after you add or remove types, you would have to run the single-file generator again. To avoid this inconvenience, I think @dadhi was figuring out how to use LeMP with MSBuild instead... this file appears to be a key part of his solution. I'm not familiar with MSBuild but I have a feeling that this part can be simplified. Every project in Visual Studio has a "Build Events" page where you can input a "Pre-build event command line" and you could invoke LeMP here instead of messing around with MSBuild directly. Unfortunately, this approach requires you to have a copy of LeMP downloaded and unzipped... perhaps I should figure out how to package the LeMP tool into NuGet... When it comes to analyzing code at compile time, it's often easier if the types you want to examine are already compiled. If you want to analyze code within the current project before it is compiled, this is more difficult, but possible... so please describe in more detail what you need to do. |
Beta Was this translation helpful? Give feedback.
-
Yes, it works for me as a proof-of-concept. Considering how quirky and fragile the source-code package support in msbuild / nuget I consider this a success. But I am not an MSBuild expert - I hope that it can be simplified. |
Beta Was this translation helpful? Give feedback.
-
hi,
i have this Method:
`public static void Collect()
{
var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(_ => _.GetTypes());
foreach (var t in types)
{
if (typeof(ICommandHandler).IsAssignableFrom(t) && !t.IsInterface)
{
var attr = t.GetCustomAttribute();
var instance = (ICommandHandler)Activator.CreateInstance(t);
but i want to avoid Reflection and use lemp to do that with ecsharp.
how could ill do this?
Beta Was this translation helpful? Give feedback.
All reactions