Click here to Skip to main content
15,844,754 members
Home / Discussions / C#
   

C#

 
AnswerRe: StreamReader in TcpListener Pin
Paulo Zemek2-Mar-15 8:45
mvaPaulo Zemek2-Mar-15 8:45 
GeneralRe: StreamReader in TcpListener Pin
Member 114922552-Mar-15 9:25
Member 114922552-Mar-15 9:25 
QuestionDatagridview row replay Pin
sdfsdfsdfewrew3feff1-Mar-15 6:03
sdfsdfsdfewrew3feff1-Mar-15 6:03 
GeneralRe: Datagridview row replay Pin
Richard MacCutchan1-Mar-15 7:15
mveRichard MacCutchan1-Mar-15 7:15 
GeneralRe: Datagridview row replay Pin
sdfsdfsdfewrew3feff1-Mar-15 9:23
sdfsdfsdfewrew3feff1-Mar-15 9:23 
GeneralRe: Datagridview row replay Pin
Richard MacCutchan1-Mar-15 23:38
mveRichard MacCutchan1-Mar-15 23:38 
GeneralRe: Datagridview row replay Pin
Eddy Vluggen2-Mar-15 9:02
professionalEddy Vluggen2-Mar-15 9:02 
Questioncreating a generic factory class that handles ValueTypes ? Pin
BillWoodruff1-Mar-15 0:36
professionalBillWoodruff1-Mar-15 0:36 
I have been writing a generic factory class; in pruned-down to walk-the-dog-bits-left-out form:
C#
public class VTBunchOLists : List<IEnumerable<T>>
{
    private bool isInt;

    // 'ctor
    public VTBunchOLists()
    {
        isInt = typeof(T) == typeof(Int32);
    }

    // utility conversion from T to Int32
    public Int32 TToInt32(T value)
    {
        return (Int32)Convert.ChangeType(value, typeof(Int32));
    }

    // 'Add to List
    public void Add(T howmanyT, bool ascending = true)
    {
        if (isInt)
        {
            var range = CreateRange(1, TToInt32(howmanyT), ascending);
            this.Add(range as IEnumerable<T>);
        }
    }

    private IEnumerable<int> CreateRange(Int32 howMany, bool ascending = true)
    {
        var range = Enumerable.Range(start, end);

        return (ascending) ? range : range.Reverse();
    }
}
Here's what concerns me:

1. there's no way to constrain the Type of T to certain ValueTypes ... that I've found in my research. I guess I could look at the Type of T in the 'ctor and return null, or throw an error, if the Type didn't match what I wanted to handle, but that seems less than elegant to me.

2. obviously I'll do quite a different thing (not shown in the code) if T is a double, since you can't use Enumerable.Range for producing anything but and integer Range.

3. similarly the required casting of an integer (or double) range to IEnumerable<t> to be able to add it to the collection kind of gives me an itch I can't scratch, but what do you think ?

4. (related to concern #1) while Enumerable.Range(start#int, end#int) returns a nice IEnumerable<int> ... and so the return value of the factory is an "un-evaluated" IEnumerable, since you have to use a List<doulbe> to create the range of doubles, the return value of the factory will be an "evaluated" structure. That lack of "symmetry" bothers me, but I see no way around this ... now ... except to make the factory return a List<List<T>> ... mmmm ...

Why am I doing this: well, I've already written separate implementations for Int32 and Double, and I'm curious to see what's involved in making it generic. And, there is some very fancy stuff in the current implementations (not shown in the code here) that could be consolidated.

thanks, Bill
«I'm asked why doesn't C# implement feature X all the time. The answer's always the same: because no one ever designed, specified, implemented, tested, documented, shipped that feature. All six of those things are necessary to make a feature happen. They all cost huge amounts of time, effort and money.» Eric Lippert, Microsoft, 2009


modified 1-Mar-15 7:20am.

AnswerRe: creating a generic factory class that handles ValueTypes ? Pin
OriginalGriff1-Mar-15 1:11
mveOriginalGriff1-Mar-15 1:11 
GeneralRe: creating a generic factory class that handles ValueTypes ? Pin
BillWoodruff1-Mar-15 2:23
professionalBillWoodruff1-Mar-15 2:23 
AnswerRe: creating a generic factory class that handles ValueTypes ? Pin
manchanx1-Mar-15 2:53
professionalmanchanx1-Mar-15 2:53 
GeneralRe: creating a generic factory class that handles ValueTypes ? Pin
BillWoodruff1-Mar-15 7:26
professionalBillWoodruff1-Mar-15 7:26 
AnswerRe: creating a generic factory class that handles ValueTypes ? Pin
Richard Deeming2-Mar-15 3:24
mveRichard Deeming2-Mar-15 3:24 
QuestionIs there a way to make "speakers" pickup 440hz? Pin
Member 1148826328-Feb-15 19:13
Member 1148826328-Feb-15 19:13 
AnswerRe: Is there a way to make "speakers" pickup 440hz? Pin
OriginalGriff28-Feb-15 21:05
mveOriginalGriff28-Feb-15 21:05 
AnswerRe: Is there a way to make "speakers" pickup 440hz? Pin
Frankie-C1-Mar-15 2:21
Frankie-C1-Mar-15 2:21 
AnswerRe: Is there a way to make "speakers" pickup 440hz? Pin
GrooverFromHolland1-Mar-15 2:25
GrooverFromHolland1-Mar-15 2:25 
QuestionIs there Any Way to Set the Namespace of a Web Service in Configuration instead of Code? Pin
jojoba2027-Feb-15 23:52
jojoba2027-Feb-15 23:52 
AnswerRe: Is there Any Way to Set the Namespace of a Web Service in Configuration instead of Code? Pin
Dave Kreskowiak28-Feb-15 5:08
mveDave Kreskowiak28-Feb-15 5:08 
AnswerRe: Is there Any Way to Set the Namespace of a Web Service in Configuration instead of Code? Pin
jojoba2028-Feb-15 23:35
jojoba2028-Feb-15 23:35 
QuestionDataGridView Entry Disappears (C#) Pin
Member 1148588827-Feb-15 9:53
Member 1148588827-Feb-15 9:53 
AnswerRe: DataGridView Entry Disappears (C#) Pin
Dave Kreskowiak27-Feb-15 12:26
mveDave Kreskowiak27-Feb-15 12:26 
GeneralRe: DataGridView Entry Disappears (C#) Pin
Member 1148588827-Feb-15 13:08
Member 1148588827-Feb-15 13:08 
GeneralRe: DataGridView Entry Disappears (C#) Pin
Dave Kreskowiak27-Feb-15 14:16
mveDave Kreskowiak27-Feb-15 14:16 
GeneralRe: DataGridView Entry Disappears (C#) Pin
Member 114858881-Mar-15 12:32
Member 114858881-Mar-15 12:32 

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.