Click here to Skip to main content
15,867,141 members
Home / Discussions / C#
   

C#

 
AnswerRe: Start the Windows form app from Window service Pin
OriginalGriff15-Apr-22 21:43
mveOriginalGriff15-Apr-22 21:43 
AnswerRe: Start the Windows form app from Window service Pin
Gerry Schmitz16-Apr-22 6:03
mveGerry Schmitz16-Apr-22 6:03 
QuestionAccessing one of many possible objects passed to a function Pin
TNCaver15-Apr-22 11:24
TNCaver15-Apr-22 11:24 
AnswerRe: Accessing one of many possible objects passed to a function Pin
Tony Hill15-Apr-22 21:02
mveTony Hill15-Apr-22 21:02 
GeneralRe: Accessing one of many possible objects passed to a function Pin
TNCaver17-Apr-22 11:16
TNCaver17-Apr-22 11:16 
AnswerRe: Accessing one of many possible objects passed to a function Pin
Mycroft Holmes16-Apr-22 12:56
professionalMycroft Holmes16-Apr-22 12:56 
GeneralRe: Accessing one of many possible objects passed to a function Pin
TNCaver17-Apr-22 11:18
TNCaver17-Apr-22 11:18 
AnswerClarification Pin
TNCaver17-Apr-22 11:14
TNCaver17-Apr-22 11:14 
What I'm trying to do is avoid duplicating code to access/manipulate the common properties. In TestFunction I want to be able to take unknownObject, cast it to its actual class type, and display or change its properties. Something like the following (which won't build):
C#
private void TestFunction(object unknownClass)
{
   var localObject = null;
   string specificProperty = string.empty;

   switch (unknownObject.GetType().Name)
   {
      case "ClassOne":
         localObject = (ClassOne)unknownObject;
         specificProperty = object.ClassOneProperty;
         break;
      case "ClassTwo":
         localObject = (ClassTwo)unknownObject;
         specificProperty = object.ClassTwoProperty;
         break;
   }

   Console.PrintLine($"Common Property = {localObject.CommonProperty}, Specific Property = {specificProperty}.");
}
If you think 'goto' is evil, try writing an Assembly program without JMP.

GeneralRe: Clarification Pin
Mycroft Holmes17-Apr-22 12:10
professionalMycroft Holmes17-Apr-22 12:10 
GeneralRe: Clarification Pin
TNCaver17-Apr-22 14:16
TNCaver17-Apr-22 14:16 
GeneralRe: Clarification Pin
Richard Deeming18-Apr-22 21:56
mveRichard Deeming18-Apr-22 21:56 
AnswerRe: Accessing one of many possible objects passed to a function Pin
Gerry Schmitz18-Apr-22 5:31
mveGerry Schmitz18-Apr-22 5:31 
QuestionHow to trigger an event with a COM port? Pin
Member 1405587913-Apr-22 2:10
Member 1405587913-Apr-22 2:10 
AnswerRe: How to trigger an event with a COM port? Pin
Ralf Meier13-Apr-22 2:47
professionalRalf Meier13-Apr-22 2:47 
AnswerRe: How to trigger an event with a COM port? Pin
OriginalGriff13-Apr-22 2:48
mveOriginalGriff13-Apr-22 2:48 
AnswerRe: How to trigger an event with a COM port? Pin
Raphael Adeniji13-Apr-22 11:31
Raphael Adeniji13-Apr-22 11:31 
QuestionNeed help advice Pin
hardsoft11-Apr-22 18:06
hardsoft11-Apr-22 18:06 
AnswerRe: Need help advice Pin
Gerry Schmitz12-Apr-22 4:59
mveGerry Schmitz12-Apr-22 4:59 
GeneralRe: Need help advice Pin
hardsoft12-Apr-22 13:25
hardsoft12-Apr-22 13:25 
GeneralRe: Need help advice Pin
Gerry Schmitz12-Apr-22 13:41
mveGerry Schmitz12-Apr-22 13:41 
GeneralRe: Need help advice Pin
hardsoft12-Apr-22 14:04
hardsoft12-Apr-22 14:04 
QuestionProblem to read Com port with while loop? Pin
Member 1405587911-Apr-22 0:55
Member 1405587911-Apr-22 0:55 
AnswerRe: Problem to read Com port with while loop? Pin
OriginalGriff11-Apr-22 1:28
mveOriginalGriff11-Apr-22 1:28 
AnswerRe: Problem to read Com port with while loop? Pin
Raphael Adeniji11-Apr-22 2:39
Raphael Adeniji11-Apr-22 2:39 
AnswerRe: Problem to read Com port with while loop? Pin
Luc Pattyn11-Apr-22 12:21
sitebuilderLuc Pattyn11-Apr-22 12:21 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.