Ejemplo n.º 1
0
        protected override void Load()
        {
            base.Load();

            if (!type.IsAbstract)
            {
                var defaultConstructor = type.GetConstructor(Type.EmptyTypes);
                if (defaultConstructor != null)
                {
                    defaultConstructorInvoker = defaultConstructor.CreateInvoker();
                }

                var listConstructor = type.GetConstructor(new[] { typeof(int) });
                if (listConstructor != null)
                {
                    listConstructorInvoker = listConstructor.CreateInvoker();
                }
            }

            allConstructors = type.GetConstructors(ALL_INSTANCE).Select(ConstructorInfo.Preloaded).ToArray();

            allProperties          = type.GetProperties(ALL_INSTANCE).Select(PropertyInfo.Preloaded).ToArray();
            allPropertiesNameIndex = MemberIndex.Build(allProperties, p => p.Name);

            allStaticProperties          = type.GetProperties(ALL_STATIC).Select(PropertyInfo.Preloaded).ToArray();
            allStaticPropertiesNameIndex = MemberIndex.Build(allStaticProperties, p => p.Name);

            allMethods          = type.GetMethods(ALL_INSTANCE).Where(m => !m.IsSpecialName).Select(MethodInfo.Preloaded).ToArray();
            allMethodsNameIndex = MemberIndex.Build(allMethods, m => m.Name);

            allStaticMethods          = type.GetMethods(ALL_STATIC).Where(m => !m.IsSpecialName).Select(MethodInfo.Preloaded).ToArray();
            allStaticMethodsNameIndex = MemberIndex.Build(allStaticMethods, m => m.Name);

            parseMethod = allStaticMethods.SingleOrDefault(m => m.HasParameters <string>() && m.Returns(this, "Parse"));
        }
Ejemplo n.º 2
0
        public static MemberIndex <TKey, TItem> Build <TKey, TItem>(IEnumerable <TItem> list, Func <TItem, TKey> keyFunction)
        {
            var result = new MemberIndex <TKey, TItem>();

            foreach (var item in list)
            {
                result.Add(keyFunction(item), item);
            }

            return(result);
        }