Exemple #1
0
        public void AddExportedFunctionsFromClass(Type type)
        {
            var functions = type.GetMethods()
                            .Where(m => m.GetCustomAttributes <ExportFunctionAttribute>().Any());

            foreach (var func in functions)
            {
                var names = func.GetCustomAttributes <ExportFunctionAttribute>();
                foreach (var name in names)
                {
                    ExportedFunctions.Add(name.FunctionName,
                                          (ExportedFunction)func.CreateDelegate(typeof(ExportedFunction)));
                }
            }
        }
Exemple #2
0
        public void AddExportedModule(Type type)
        {
            var moduleName = type.GetCustomAttribute <ExportModuleAttribute>().ModuleName;
            var functions  = type.GetMethods()
                             .Where(m => m.CustomAttributes.Any(a =>
                                                                ReferenceEquals(a.AttributeType, typeof(ExportFunctionAttribute))));

            foreach (var func in functions)
            {
                var names = func.GetCustomAttributes <ExportFunctionAttribute>();
                foreach (var name in names)
                {
                    var nameWithModule = $"{moduleName}::{name.FunctionName}";
                    ExportedFunctions.Add(nameWithModule,
                                          (ExportedFunction)func.CreateDelegate(typeof(ExportedFunction)));
                }
            }
        }