C# pass by ref different types of object that have the same properties inside and populate them without interface
<p>How to pass by ref different types of objects that have the same properties inside and populate them without interface.</p>

<p>In my app there are totally different types which have some properties in common.
Let's say this properties are double arrays.</p>

<pre><code>double[] samples;
</code></pre>

<p>Now I have to populate these samples for 20 objects.
I don't have any access to the class definition of this object, so I can't make interface, or make them inherit from a base class.</p>

<p>How can use one method which I call and this method to populate all my properties.</p>

<p>I want to have one method like this:</p>

<pre><code>private static void FillSamples(ref WhoKnowsWhat dataType, MyObject theSamples)
{

for (int i = 0; i &lt; sampleCount; i++)
                        {
                            dataType.SampleLength[i] = MyObject.X[i];
                            dataType.SampleValue[i]  = MyObject.y[i];
                        }
}
</code></pre>

<p>And call this with totally different types.</p>

<pre><code>FillSamples(ref BigStruct.OneTypeMine, theSamples);
FillSamples(ref BigStruct.AnotherTypeMine, theSamples);
FillSamples(ref BigStruct.HisType12345, theSamples);
</code></pre>

<p>Then the big struct should have these samples filled in the end.</p>

<p>Is there a way in C#?</p>

<p>Thanks!</p>
