Exemple #1
0
        /// <summary>
        /// Gets the mapping of journal type value to JournalEntry type
        /// </summary>
        /// <returns>Map of type values to types</returns>
        private static Dictionary <JournalTypeEnum, Type> GetJournalEntryTypes()
        {
            Dictionary <JournalTypeEnum, Type> typedict = new Dictionary <JournalTypeEnum, Type>();
            var asm   = System.Reflection.Assembly.GetExecutingAssembly();
            var types = asm.GetTypes().Where(t => typeof(JournalEntry).IsAssignableFrom(t) && !t.IsAbstract).ToList();

            foreach (Type type in types)
            {
                JournalEntryTypeAttribute typeattrib = type.GetCustomAttributes(false).OfType <JournalEntryTypeAttribute>().FirstOrDefault();
                if (typeattrib != null)
                {
                    typedict[typeattrib.EntryType] = type;
                }
            }

            return(typedict);
        }
Exemple #2
0
        private static Dictionary <string, BaseUtils.ObjectActivator.Activator <JournalEntry> > GetClassActivators()
        {
            var actlist = new Dictionary <string, BaseUtils.ObjectActivator.Activator <JournalEntry> > ();

            var asm   = System.Reflection.Assembly.GetExecutingAssembly();
            var types = asm.GetTypes().Where(t => typeof(JournalEntry).IsAssignableFrom(t) && !t.IsAbstract).ToList();

            foreach (Type type in types)
            {
                JournalEntryTypeAttribute typeattrib = type.GetCustomAttributes(false).OfType <JournalEntryTypeAttribute>().FirstOrDefault();
                if (typeattrib != null)
                {
                    System.Reflection.ConstructorInfo ctor = type.GetConstructors().First();        // this is freaking deep c# here.
                    var r = ctor.GetParameters();
                    System.Diagnostics.Debug.Assert(r.Count() == 1);
                    var r0t = r[0].GetType();
                    System.Diagnostics.Debug.Assert(r[0].ParameterType.Name == "JObject");      // checking we are picking the correct ctor
                    actlist[typeattrib.EntryType.ToString()] = BaseUtils.ObjectActivator.GetActivator <JournalEntry>(ctor);
                    //   System.Diagnostics.Debug.WriteLine("Activator " + typeattrib.EntryType.ToString());
                }
            }

            return(actlist);
        }