Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are two approaches to this problem:</p> <p>Create a base class that has all these common properties and derive the others from it.</p> <pre><code>public abstract class MyBaseClass { public string Name { get; set; } public string Signature { get; set; } public int Checksum { get; set; } } public class ClassX : MyBaseClass { // Add the other properties here } public class ClassY : MyBaseClass { // Add the other properties here } public class ClassZ : MyBaseClass { // Add the other properties here } </code></pre> <p>Your helper method will have a parameter of type MyBaseClass:</p> <pre><code>public void MyHelperMethod(MyBaseClass obj) { // Do something with obj.Name, obj.Siganture and obj.Checksum } </code></pre> <p>It would also be a good idea to place the helper method in MyBaseClass, but without parameters, since now it can access the properties directly:</p> <pre><code>public abstract class MyBaseClass { public string Name { get; set; } public string Signature { get; set; } public int Checksum { get; set; } public void CreateChecksum() // Your helper method { Checksum = Name.GetHashCode() ^ Signature.GetHashCode(); } } </code></pre> <p>Then you can call it directly from your objects:</p> <pre><code>objA.CreateChecksum(); objB.CreateChecksum(); objB.CreateChecksum(); </code></pre> <hr> <p>Or define an interface that your three classes implement:</p> <pre><code>public interface IMyInterface { string Name { get; set; } string Signature { get; set; } int Checksum { get; set; } } public class ClassX : IMyInterface { public string Name { get; set; } public string Signature { get; set; } public int Checksum { get; set; } // Add the other properties here } public class ClassY : IMyInterface { public string Name { get; set; } public string Signature { get; set; } public int Checksum { get; set; } // Add the other properties here } public class ClassZ : IMyInterface { public string Name { get; set; } public string Signature { get; set; } public int Checksum { get; set; } // Add the other properties here } </code></pre> <p>Your helper method will have a parameter of type IMyInterface:</p> <pre><code>public void MyHelperMethod(IMyInterface obj) { // Do something with obj.Name, obj.Siganture and obj.Checksum } </code></pre> <hr> <p>You can call MyHelperMethod like this</p> <pre><code>MyHelperMethod(objA); MyHelperMethod(objB); MyHelperMethod(objC); </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.
    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