Hello,
I have a class that has a Generic type "G"
In my class model i have
public class DetailElement : ElementDefinition
Let's say i have a method like this
public void DoSomething<G>(G generic)
where G : ElementDefinition
{
if (generic is DetailElement)
{
((DetailElement)generic).DescEN = "Hello people"; //line 1
//////
ElementDefinition element = generic;
((DetailElement)element).DescEN = "Hello again"; //line 3
//////
(generic as DetailElement).DescEN = "Howdy"; //line 5
}
else
{
//do other stuff
}
}
Compiler reports one error in line 1:
Cannot convert type 'G' to 'DetailElement'
But line 3 works fine. I can workaround this issue by doing the code written in line 5.
What i would like to know is why does the compiler reports the error in line 1 and not the one in line 3, given that, as far as i know, they are identical.
edit: I am afraid i might be missing some important piece of the framework logic
edit2: Although solutions for the compiler error are important, my question is about why the compiler reports an error on line 1 and not in line 3.
Thank you, Luís