Esempio n. 1
0
 internal VC_FunctionInfo(VC_FunctionAttribute attr, MethodInfo method)
 {
     Alias       = attr.Alias;
     Usage       = attr.Usage;
     Description = attr.Description;
     Method      = method;
 }
Esempio n. 2
0
        public static void AddClassType(Type[] types)
        {
            types = types.Distinct().ToArray();
            for (int i = 0; i < types.Length; i++)
            {
                Type         t            = types[i];
                MethodInfo[] allMethods   = t.GetMethods(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Static);
                MethodInfo[] validMethods = allMethods.Where(m => m.GetCustomAttributes(typeof(VC_FunctionAttribute), false).Length > 0).ToArray();
                foreach (MethodInfo method in validMethods)
                {
                    VC_FunctionAttribute cmdAttr = method.GetCustomAttribute(typeof(VC_FunctionAttribute), false) as VC_FunctionAttribute;

                    string alias = string.Empty;

                    if (string.IsNullOrWhiteSpace(cmdAttr.Alias))
                    {
                        alias = string.Format("{0}.{1}", t.Name, method.Name);
                        string error = string.Format("Unnamed command!{0}Generated alias: {1}", Environment.NewLine, alias);
                    }
                    else
                    {
                        alias = cmdAttr.Alias;
                    }

                    alias = alias.Trim();

                    if (functionInfos.ContainsKey(alias))
                    {
                        cmdAttr.Alias = cmdAttr.Alias == alias?string.Format("{0}.{1}", t.Name, method.Name) : string.Format("{0}.{1}", t.FullName, method.Name);

                        string error = string.Format("{0} is already defined and has been replaced with {1}", alias, cmdAttr.Alias);
                        //RTConsole.Instance.LogInternal(LogTypes.Warning, "Commands provider", error);
                    }
                    else
                    {
                        cmdAttr.Alias = alias;
                    }

                    functionInfos.Add(cmdAttr.Alias.Trim(), new VC_FunctionInfo(cmdAttr, method));
                }
            }
        }