This is a very specific problem. Not quite sure how to even word it. Basically I am implementing the unit of work and repository pattern, I have a dynamic object that I convert to an int, but if I use var
it will throw an exception when trying to call the method.
I tried to remove all the trivial variables to this problem that I can. For some reason I only see it happen with these two design patterns. The exception I get is Additional information: 'BlackMagic.ITacoRepo' does not contain a definition for 'DoStuff'
Here is the code:
class BlackMagic
{
static void Main(string[] args)
{
dynamic obj = new ExpandoObject();
obj.I = 69;
UnitOfWork uow = new UnitOfWork();
int i1 = Convert.ToInt32(obj.I);
var i2 = Convert.ToInt32(obj.I);
if(i1.Equals(i2))
{
uow.TacoRepo.DoStuff(i1); // Works fine
uow.TacoRepo.DoStuff(i2); // Throws Exception
}
}
}
class UnitOfWork
{
public ITacoRepo TacoRepo { get; set; }
public UnitOfWork()
{
TacoRepo = new TacoRepo();
}
}
class Repo<T> : IRepo<T> where T : class
{
public void DoStuff(int i)
{
}
}
interface IRepo<T> where T : class
{
void DoStuff(int i);
}
class TacoRepo : Repo<Taco>, ITacoRepo
{
}
interface ITacoRepo : IRepo<Taco>
{
}
class Taco
{
}
EDIT: The main question I am trying to find an answer for, is why would the exception get thrown by calling DoStuff
inside the unit of work (while using the repo) but not get thrown if DoStuff existed in the BlackMagic
class.