Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the issue that you're having is because you're trying to create a generic type, and then create a list of that generic type. You could accomplish what you're trying to do by contracting out the data types you're trying to support, say as an IData element, and then create your MyData generic with a constraint of IData. The downside to this would be that you would have to create your own data types to represent all the primitive data types you're using (string, int, float, long). It might look something like this:</p> <pre><code>public class MyData&lt;T, C&gt; where T : IData&lt;C&gt; { public T Data { get; private set; } public MyData (T value) { Data = value; } } public interface IData&lt;T&gt; { T Data { get; set; } void SomeMethod(); } //you'll need one of these for each data type you wish to support public class MyString: IData&lt;string&gt; { public MyString(String value) { Data = value; } public void SomeMethod() { //code here that uses _data... Console.WriteLine(Data); } public string Data { get; set; } } </code></pre> <p>and then you're implementation would be something like:</p> <pre><code>var myData = new MyData&lt;MyString, string&gt;(new MyString("new string")); // Could be MyString, MyInt, ... myData.Data.SomeMethod(); </code></pre> <p>it's a little more work but you get the functionality you were going for.</p> <p><strong>UPDATE:</strong> remove SomeMethod from your interface and just do this</p> <pre><code>SomeMethod(myData.Data.Data); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload