Example #1
0
        private void ScanService()
        {
            // Scan once and cache
            if (mServiceActions != null)
            {
                return;
            }
            Console.WriteLine("Scanning Service: " + mService.GetType().FullName);
            mServiceActions = new List <ActionHandler>();

            // Register all actions which have 'GingerAction' attribute
            Type t = mService.GetType();
            var  v = t.GetMethods(); //BindingFlags.Public  BindingFlags.DeclaredOnly);

            foreach (MethodInfo MI in v)
            {
                GingerActionAttribute GAA = (GingerActionAttribute)MI.GetCustomAttribute(typeof(GingerActionAttribute));
                if (GAA != null)
                {
                    ActionHandler AH = new ActionHandler();
                    AH.ServiceActionId = GAA.Id;
                    AH.MethodInfo      = MI;
                    AH.Instance        = mService;
                    mServiceActions.Add(AH);

                    Console.WriteLine("Found Action: " + AH.ServiceActionId);
                }
            }
        }
Example #2
0
        public static void DebugPrint(object obj)
        {
            Type t = obj.GetType();
            // private&public
            BindingFlags flags = BindingFlags.Public
                                 | BindingFlags.Instance
                                 | BindingFlags.NonPublic;
            // fields&properties
            List <MemberInfo> members = new List <MemberInfo>();

            members.AddRange(t.GetFields(flags));
            members.AddRange(t.GetProperties(flags));
            foreach (MemberInfo MI in members)
            {
                DebugPrintAttribute DPA =
                    (DebugPrintAttribute)MI.GetCustomAttribute(typeof(DebugPrintAttribute));
                if (DPA != null)
                {
                    Console.WriteLine(DPA.format, MI.GetValue(obj), MI.Name, MI.ReflectedType);
                }
            }
        }