public ActionsLoader()

in src/CTA.Rules.Actions/ActionsLoader.cs [32:185]


        public ActionsLoader(List<string> assemblyPaths)
        {
            compilationUnitActions = new List<MethodInfo>();
            attributeActions = new List<MethodInfo>();
            attributeListActions = new List<MethodInfo>();
            classActions = new List<MethodInfo>();
            identifierNameActions = new List<MethodInfo>();
            invocationExpressionActions = new List<MethodInfo>();
            expressionActions = new List<MethodInfo>();
            methodDeclarationActions = new List<MethodInfo>();
            elementAccessActions = new List<MethodInfo>();
            memberAccessActions = new List<MethodInfo>();
            objectCreationExpressionActions = new List<MethodInfo>();
            namespaceActions = new List<MethodInfo>();
            projectLevelActions = new List<MethodInfo>();
            interfaceActions = new List<MethodInfo>();
            projectFileActions = new List<MethodInfo>();

            var actionsAssembly = AppDomain.CurrentDomain.GetAssemblies().Where(a => a.FullName.Contains("CTA.Rules.Actions")).FirstOrDefault();

            var assemblies = new List<Assembly>
            {
                actionsAssembly
            };

            foreach (var path in assemblyPaths)
            {
                try
                {
                    var assembly = AssemblyLoadContext.Default.LoadFromAssemblyPath(path);
                    assemblies.Add(assembly);
                }
                catch (Exception ex)
                {
                    LogHelper.LogError(ex, string.Format("Error loading assembly from {0}{1}{2}", path, Environment.NewLine, ex.Message));
                }
            }

            foreach (var assembly in assemblies)
            {
                try
                {
                    var types = assembly.GetTypes().Where(t => t.Name.EndsWith("Actions"));

                    attributeObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.AttributeActions));
                    attributeListObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.AttributeListActions));
                    classObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.ClassActions));
                    compilationUnitObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.CompilationUnitActions));
                    identifierNameObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.IdentifierNameActions));
                    invocationExpressionObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.InvocationExpressionActions));
                    expressionObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.ExpressionActions));
                    methodDeclarationObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.MethodDeclarationActions));
                    elementAccessObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.ElementAccessActions));
                    memberAccessObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.MemberAccessActions));
                    namespaceObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.NamespaceActions));
                    objectExpressionObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.ObjectCreationExpressionActions));
                    projectLevelObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.ProjectLevelActions));
                    interfaceObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.InterfaceActions));
                    projectFileObject = Activator.CreateInstance(types.FirstOrDefault(t => t.Name == Constants.ProjectFileActions));


                    foreach (var t in types)
                    {
                        switch (t.Name)
                        {
                            case Constants.AttributeActions:
                                {
                                    attributeActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.AttributeListActions:
                                {
                                    attributeListActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.ClassActions:
                                {
                                    classActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.InterfaceActions:
                                {
                                    interfaceActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.CompilationUnitActions:
                                {
                                    compilationUnitActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.IdentifierNameActions:
                                {
                                    identifierNameActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.InvocationExpressionActions:
                                {
                                    invocationExpressionActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.ExpressionActions:
                                {
                                    expressionActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.MethodDeclarationActions:
                                {
                                    methodDeclarationActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.ElementAccessActions:
                                {
                                    elementAccessActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.MemberAccessActions:
                                {
                                    memberAccessActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.ObjectCreationExpressionActions:
                                {
                                    objectCreationExpressionActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.NamespaceActions:
                                {
                                    namespaceActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.ProjectLevelActions:
                                {
                                    projectLevelActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            case Constants.ProjectFileActions:
                                {
                                    projectFileActions.AddRange(GetFuncMethods(t));
                                    break;
                                }
                            default:
                                {
                                    LogHelper.LogError(string.Format("Action type {0} is not found", t.Name));
                                    break;
                                }
                        }
                    }
                }
                catch (Exception ex)
                {
                    LogHelper.LogError(ex, string.Format("Error loading actions from {0}", assembly.FullName, ex.Message));
                }
            }
        }