EF и Generic

Оставляю кусочек кода себе на память. Универсальный, но в моем случае требует костылей.

#region Generic
        public void CreateLang(TModel langModel, out IEnumerable diff)
        {
            Type entityType = this.TypesModelEntity[typeof(TModel)]; //вот костыль
            var langType = this.TypesEntityLang[entityType]; //и еще один

            Type genericClass = typeof(EFLangRepository);
            Type constructedClass = genericClass.MakeGenericType(typeof(TModel), entityType, langType);

            object repo = Activator.CreateInstance(constructedClass);

            diff = new List();
            object[] args = new object[] { langModel, diff };

            MethodInfo magicMethod = constructedClass.GetMethod("CreateLang");
            object magicValue = magicMethod.Invoke(repo, args);
            diff = args[1] as List;
        }
        #endregion

Continue Reading →