If it doesn't have to be a single method, you could create a couple overloads, such that one signature accepts an argument of type Person, and the other accepts an argument of type Organization.
public static AdoptionApplicationCollection GetApplicationsByApplicant(Person person)
{
// blah
}
public static AdoptionApplicationCollection GetApplicationsByApplicant(Organization organization)
{
// blah
}
If it must be a single method, you might consider using the 'OneOf' pattern (I use it frequently when defining protobuf messages). You'd need to create a wrapper class that has both a Person, and Organization member (but only one of them should be non-null, assuming they are both reference types). That code would look something like this:
class Applicant {
Person _person;
Organization _organization;
public Applicant(Person person) {
_person = person;
}
public Applicant(Organization organization) {
_organization = organization;
}
public enum ApplicantCase {
None,
Person,
Organization
}
public Person person { get => _person; }
public Organization organization { get => _organization; }
public ApplicantCase applicant_case {
get {
if (_person != null)
return ApplicantCase.Person;
if (_organization != null)
return ApplicantCase.Organization;
return ApplicantCase.None;
}
}
}
public static AdoptionApplicationCollection GetApplicationsByApplicant(Applicant applicant) {
switch (applicant.applicant_case) {
case Applicant.ApplicantCase.Person:
// blah
break;
case Applicant.ApplicantCase.Organization:
// blah
break;
default:
// bad applicant
break;
}
}