Click here to Skip to main content
15,895,812 members
Home / Discussions / C#
   

C#

 
QuestionHow do i refer to my own custom control, within the control? Pin
stephen.darling21-Sep-10 9:10
stephen.darling21-Sep-10 9:10 
AnswerRe: How do i refer to my own custom control, within the control? Pin
OriginalGriff21-Sep-10 9:29
mveOriginalGriff21-Sep-10 9:29 
GeneralRe: How do i refer to my own custom control, within the control? Pin
stephen.darling21-Sep-10 10:04
stephen.darling21-Sep-10 10:04 
GeneralRe: How do i refer to my own custom control, within the control? Pin
OriginalGriff21-Sep-10 21:44
mveOriginalGriff21-Sep-10 21:44 
QuestionDetermining the Data Type of a Generic Pin
kevinnicol21-Sep-10 6:59
kevinnicol21-Sep-10 6:59 
AnswerRe: Determining the Data Type of a Generic Pin
kevinnicol21-Sep-10 7:16
kevinnicol21-Sep-10 7:16 
AnswerRe: Determining the Data Type of a Generic Pin
Ian Shlasko21-Sep-10 7:16
Ian Shlasko21-Sep-10 7:16 
AnswerRe: Determining the Data Type of a Generic Pin
AspDotNetDev21-Sep-10 11:34
protectorAspDotNetDev21-Sep-10 11:34 
Reflection is probably the best way to go, but here is another technique which may be faster, though is not as flexible (i.e., you must know in advance if the type is a class or a struct, and it requires the class have a default constructor):
C#
public bool IsClassAnimal<T>()
    where T:new()
{
    T t = new T();
    return t is IAnimal;
}

public bool IsStructAnimal<T>()
{
    T t = default(T);
    if (t == null)
    {
        throw new InvalidOperationException("The type was a class.");
    }
    else
    {
        return t is IAnimal;
    }
}

Sample interface/struct/class:
C#
public interface IAnimal
{
}
public class Dog : IAnimal
{
}
struct Cat : IAnimal
{
}

Sample usage:
C#
if (IsClassAnimal<Dog>())
{
    MessageBox.Show("A dog is an animal!");
}
if (IsStructAnimal<Cat>())
{
    MessageBox.Show("A cat is an animal!");
}

You could simplify that by just passing an instance of the class/struct, but that doesn't seem like what you're after. Also, if your class/struct is large (e.g., with lots of member variables), this could be a very expensive operation; not to mention it could have some weird side-effects. But, hey, thought I'd throw the technique out there anyway in case somebody can make use of it.

AnswerRe: Determining the Data Type of a Generic Pin
phil.o22-Sep-10 3:44
professionalphil.o22-Sep-10 3:44 
QuestionHow to take data from USB-based device using C# ?? Pin
depressedguy21-Sep-10 6:51
depressedguy21-Sep-10 6:51 
AnswerRe: How to take data from USB-based device using C# ?? Pin
Richard Andrew x6421-Sep-10 15:53
professionalRichard Andrew x6421-Sep-10 15:53 
GeneralRe: How to take data from USB-based device using C# ?? Pin
depressedguy21-Sep-10 16:58
depressedguy21-Sep-10 16:58 
GeneralC# and Ring indicator Pin
MarkBng21-Sep-10 5:27
MarkBng21-Sep-10 5:27 
GeneralRe: C# and Ring indicator Pin
Luc Pattyn21-Sep-10 5:41
sitebuilderLuc Pattyn21-Sep-10 5:41 
QuestionUDP Packet Synchronization Pin
softwarejaeger21-Sep-10 3:42
softwarejaeger21-Sep-10 3:42 
AnswerRe: UDP Packet Synchronization Pin
Dave Kreskowiak21-Sep-10 6:41
mveDave Kreskowiak21-Sep-10 6:41 
Questionhow can i use diffrence neuron count in difference layer Pin
karayel_kara21-Sep-10 3:22
karayel_kara21-Sep-10 3:22 
AnswerRe: how can i use diffrence neuron count in difference layer Pin
Alan Balkany21-Sep-10 3:59
Alan Balkany21-Sep-10 3:59 
GeneralRe: how can i use diffrence neuron count in difference layer Pin
karayel_kara21-Sep-10 4:16
karayel_kara21-Sep-10 4:16 
GeneralRe: how can i use diffrence neuron count in difference layer Pin
Alan Balkany21-Sep-10 4:28
Alan Balkany21-Sep-10 4:28 
GeneralRe: how can i use diffrence neuron count in difference layer Pin
Alan Balkany21-Sep-10 4:32
Alan Balkany21-Sep-10 4:32 
AnswerRe: how can i use diffrence neuron count in difference layer Pin
Henry Minute21-Sep-10 4:31
Henry Minute21-Sep-10 4:31 
GeneralRe: how can i use diffrence neuron count in difference layer Pin
harold aptroot21-Sep-10 5:13
harold aptroot21-Sep-10 5:13 
QuestionExtensions Property Pin
reza assar21-Sep-10 3:22
reza assar21-Sep-10 3:22 
AnswerRe: Extensions Property Pin
Dave Kreskowiak21-Sep-10 3:33
mveDave Kreskowiak21-Sep-10 3:33 

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.