Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As I see it you have two options. The easy option is to expose the value (as an object) on the interface (and possibly its type as well). Here's how that would look:</p> <pre><code>interface ISomeClass { object ValueINeed { get; set; } // Only needed if you care about static type rather than using ValueINeed.GetType() Type TypeOfValue { get; } } class SomeClass&lt;T&gt; : ISomeClass { public T ValueINeed { get; set; } public Type TypeOfValue { get { return typeof(T); } } object ISomeClass.ValueINeed { get { return ValueINeed; } set { ValueINeed = (T)value; } } } </code></pre> <p>This has the disadvantage that there's a bit of casting going on and you might need to invoke reflection to do certain things with the value. It has the advantage that it's easy to understand and implement.</p> <p>The other alternative would be to encode an "existential type" which truly represents a <code>SomeClass&lt;T&gt;</code> for some unknown <code>T</code> (like a <code>SomeClass&lt;?&gt;</code> in Java). This is much more complicated and hard to follow, but avoids any casts:</p> <pre><code>interface ISomeClassUser&lt;X&gt; { X Use&lt;T&gt;(SomeClass&lt;T&gt; s); } interface ISomeClassUser { void Use&lt;T&gt;(SomeClass&lt;T&gt; s); } interface ISomeClass { X Apply&lt;X&gt;(ISomeClassUser&lt;X&gt; user); void Apply(ISomeClassUser user); } class SomeClass&lt;T&gt; : ISomeClass { public T ValueINeed { get; set; } public X Apply&lt;X&gt;(ISomeClassUser&lt;X&gt; user) { return user.Use(this); } public void Apply(ISomeClassUser user) { user.Use(this); } } // Assumes you want to get a string out, use a different generic type as needed class XmlUser : ISomeClassUser&lt;string&gt; { public string Use&lt;T&gt;(SomeClass&lt;T&gt; s) { string str = ""; // do your conditional formatting here, branching on T as needed // ... return str; } } class ClassThatHasListOfGenericObjects { List&lt;ISomeClass&gt; _l = new List&lt;ISomeClass&gt;(); XmlUser user = new XmlUser(); public string SomeMethod() { string s = ""; foreach (ISomeClass i in _l) { s += i.Apply(user); } return s; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    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. 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