Note that there are some explanatory texts on larger screens.

plurals
  1. POObtaining a collection of constructed subclassed types using reflection
    text
    copied!<p>I want to create a class which implements IEnumerable&lt;T&gt; but, using reflection, generates T's and returns them via IEnumerable&lt;T&gt;, where T' is a entirely constructed subclass of T with some properties hidden and others read-only. </p> <p>Okay., that might not be very clear. Let me explain this via the medium of code - I'd like to have a class CollectionView&lt;T&gt; as follows:-</p> <pre><code>public class CollectionView&lt;T&gt; : IEnumerable&lt;T&gt; { public CollectionView(IEnumerable&lt;T&gt; inputCollection, List&lt;string&gt; hiddenProperties, List&lt;string&gt; readonlyProperties) { // ... } // IEnumerable&lt;T&gt; implementation which returns a collection of T' where T':T. } ... public class SomeObject { public A { get; set; } public B { get; set; } public C { get; set; } } ... var hiddenProperties = new List&lt;string&gt;(new[] { "A" }); var readOnlyProperties = new List&lt;string&gt;(new[] { "C" }); IEnumerable&lt;SomeObject&gt; someObjects = CollectionView&lt;SomeObject&gt;(hiddenProperties, readOnlyProperties); ... dataGridView1.DataSource = someObjects; </code></pre> <p>(When displayed in dataGridView1 shows columns B and C and C has an underlying store which is read-only)</p> <p>Is this possible/desirable or have I completely lost my mind/does this question demonstrate my deep inadequacy as a programmer?</p> <p>I want to do this so I can manipulate a collection that is to be passed into a DataGridView, <em>without having to directly manipulate the DataGridView to hide columns/make columns read-only</em>. So no 'oh just use dataGridView1.Columns.Remove(blah) / dataGridView1.Columns[blah].ReadOnly = true' answers please!!</p> <p>Help!</p>
 

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