Esempio n. 1
0
        public void Run(object obj, string[] args)
        {
            var binders = ArgBinder.Get(obj);
            var entries = Enumerable.Concat(m_Default, GetArgEntries(args).Where(x => x != null)).ToArray();

            foreach (var binder in binders)
            {
                binder.CheckRequired(entries);
            }
            foreach (var entry in entries)
            {
                foreach (var binder in binders)
                {
                    if (binder.IsMatch(entry))
                    {
                        binder.Set(entry);
                    }
                }
            }
        }
Esempio n. 2
0
        public static ArgBinder[] Get(object obj)
        {
            var entries = new List <ArgBinder>();

            foreach (var attr in obj.GetType().GetCustomAttributes(typeof(ArgAttribute)))
            {
                if (attr is ArgAttribute arg)
                {
                    entries.Add(new ImportArgBinder
                    {
                        m_Arg = arg,
                        m_Obj = obj
                    });
                }
            }
            foreach (var field in obj.GetType().GetFields())
            {
                var arg = field.GetCustomAttribute <ArgAttribute>();
                if (arg == null)
                {
                    continue;
                }
                ArgBinder entry = null;
                if (field.FieldType.IsEnum)
                {
                    entry = new EnumArgBinder();
                }
                else
                {
                    entry = s_Dic[field.FieldType]();
                }
                entry.m_Obj  = obj;
                entry.m_Info = field;
                entry.m_Arg  = arg;
                entries.Add(entry);
            }
            return(entries.ToArray());
        }