Click here to Skip to main content
15,799,018 members
Home / Discussions / C#
   

C#

 
AnswerRe: SQL Connection in Visual Studio Pin
Eddy Vluggen24-Apr-20 13:40
professionalEddy Vluggen24-Apr-20 13:40 
AnswerRe: SQL Connection in Visual Studio Pin
Matt Slay24-Apr-20 17:28
Matt Slay24-Apr-20 17:28 
AnswerRe: SQL Connection in Visual Studio Pin
OriginalGriff24-Apr-20 21:09
mvaOriginalGriff24-Apr-20 21:09 
AnswerRe: SQL Connection in Visual Studio Pin
Gerry Schmitz25-Apr-20 12:46
mveGerry Schmitz25-Apr-20 12:46 
Questioncasting from interface instance back to generic instance ? Pin
BillWoodruff24-Apr-20 2:11
professionalBillWoodruff24-Apr-20 2:11 
GeneralRe: casting from interface instance back to generic instance ? Pin
harold aptroot24-Apr-20 2:29
harold aptroot24-Apr-20 2:29 
GeneralRe: casting from interface instance back to generic instance ? Pin
BillWoodruff24-Apr-20 3:41
professionalBillWoodruff24-Apr-20 3:41 
GeneralRe: casting from interface instance back to generic instance ? Pin
Richard Deeming24-Apr-20 4:26
mveRichard Deeming24-Apr-20 4:26 
The problem is that you don't know at compile-time what the run-time type of the instance will be.

As Harold said, there isn't a compile-time type you can use which would give you access to the properties or methods of the run-time type.

Consider:
C#
public abstract class Being
{
    public string Name { get; set; }
}

public class Dog : Being
{
    public void Bark() { ... }
}

public class Human : Being
{
    public void ComposeMusic() { ... }
}

List<Being> beings = LoadBeings();
Being aBeing = beings[0];
Type beingType = aBeing.GetType();

{ What could possibly go here? } myBeing = BeingAsType(aBeing, beingType);

myBeing.{ Which method could you call here? }();

Perhaps the visitor pattern might help you?



"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer

GeneralRe: casting from interface instance back to generic instance ? Pin
BillWoodruff24-Apr-20 5:52
professionalBillWoodruff24-Apr-20 5:52 
GeneralRe: casting from interface instance back to generic instance ? Pin
Richard Deeming24-Apr-20 5:59
mveRichard Deeming24-Apr-20 5:59 
AnswerRe: casting from interface instance back to generic instance ? Pin
jschell26-Apr-20 10:59
jschell26-Apr-20 10:59 
AnswerMessage Closed Pin
23-Apr-20 3:41
Corrie Lang23-Apr-20 3:41 
GeneralRe: During Pin
OriginalGriff23-Apr-20 4:15
mvaOriginalGriff23-Apr-20 4:15 
QuestionRefreshing data on a parent form at child close Pin
Uranium-23521-Apr-20 21:24
Uranium-23521-Apr-20 21:24 
AnswerRe: Refreshing data on a parent form at child close Pin
OriginalGriff21-Apr-20 22:44
mvaOriginalGriff21-Apr-20 22:44 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23521-Apr-20 23:48
Uranium-23521-Apr-20 23:48 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff22-Apr-20 0:04
mvaOriginalGriff22-Apr-20 0:04 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23523-Apr-20 0:27
Uranium-23523-Apr-20 0:27 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff23-Apr-20 1:09
mvaOriginalGriff23-Apr-20 1:09 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23523-Apr-20 11:46
Uranium-23523-Apr-20 11:46 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff23-Apr-20 12:06
mvaOriginalGriff23-Apr-20 12:06 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23524-Apr-20 18:53
Uranium-23524-Apr-20 18:53 
GeneralRe: Refreshing data on a parent form at child close Pin
OriginalGriff24-Apr-20 21:08
mvaOriginalGriff24-Apr-20 21:08 
GeneralRe: Refreshing data on a parent form at child close Pin
Uranium-23525-Apr-20 20:42
Uranium-23525-Apr-20 20:42 
AnswerRe: Refreshing data on a parent form at child close Pin
#realJSOP22-Apr-20 8:15
mve#realJSOP22-Apr-20 8:15 

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.