Пример #1
0
        public static LibraryFunction[] ExtractLibraryFunctions(EvaluationContext context, object instance)
        {
            if (instance == null)
            {
                return(new LibraryFunction[0]);
            }

            var list = new List <LibraryFunction>();

            MethodInfo[] methods = instance.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly);
            foreach (MethodInfo method in methods)
            {
                var fun = method.CreateDelegate <LibraryDelegate>(instance, false);
                if (fun != null)
                {
                    var fname = method.GetCustomAttribute <FunctionNamesAttribute>();
                    var names = (fname == null) ? new string[] { method.Name } : fname.Names;
                    foreach (var strName in names)
                    {
                        IronySymbol name = SymbolTable.Symbols.TextToSymbol(strName);
                        name = context.LanguageCaseSensitive ? name : name.LowerSymbol;
                        list.Add(new LibraryFunction(name, fun));
                    }
                }
            }

            return(list.ToArray());
        }
Пример #2
0
 private LibraryFunction(IronySymbol n, LibraryDelegate fun)
 {
     Name     = n;
     Function = fun;
 }