c# - Creation of a new instance of generic type parameter not getting code coverage -


i've run code through code coverage , line below shows 1 block not covered.

can tell me part of line isn't executing?

enter image description here

an example play with:

public abstract class base {     public abstract iexample createentity<texample>() texample : iexample, new(); }  public class class1 : base {     public override iexample createentity<texample>()     {         iexample temp = new texample();         return temp;     } }  public interface iexample {  }  public class tex : iexample {  } 

and test method

    [testmethod]     public void testmethod1()     {         class1 ex = new class1();         ex.createentity<tex>();     } 

change constraint force texample class:

public abstract iexample createentity<texample>() texample : class, iexample, new(); 

if run compiled code through tool ilspy, see block not getting coverage:

texample temp = (default(texample) == null) ? activator.createinstance<texample>() : default(texample); return temp; 

it performing check see if type passed generic reference type or value type. forcing class, check removed. read more on default keyword here: http://msdn.microsoft.com/en-us/library/xwth0h0d.aspx

another way complete code coverage use struct implements iexample:

public struct s1 : iexample {  } 

and add test:

[testmethod] public void structtest() {     class1 ex = new class1();     ex.createentity<s1>(); } 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -