Click here to Skip to main content
15,893,622 members
Home / Discussions / .NET (Core and Framework)
   

.NET (Core and Framework)

 
QuestionExport to excel [modified] Pin
Uma J10-Dec-09 0:16
Uma J10-Dec-09 0:16 
AnswerRe: Export to excel Pin
dan!sh 10-Dec-09 1:18
professional dan!sh 10-Dec-09 1:18 
AnswerRe: Export to excel Pin
Ashfield10-Dec-09 1:24
Ashfield10-Dec-09 1:24 
AnswerRe: Export to excel Pin
Dave Kreskowiak10-Dec-09 4:26
mveDave Kreskowiak10-Dec-09 4:26 
AnswerRe: Export to excel Pin
The Man from U.N.C.L.E.11-Dec-09 22:57
The Man from U.N.C.L.E.11-Dec-09 22:57 
QuestionPOP3 Class Pin
joelle@scope9-Dec-09 2:17
joelle@scope9-Dec-09 2:17 
AnswerRe: POP3 Class Pin
Richard MacCutchan9-Dec-09 3:26
mveRichard MacCutchan9-Dec-09 3:26 
QuestionType inference problem [modified/solved] Pin
Gideon Engelberth8-Dec-09 13:50
Gideon Engelberth8-Dec-09 13:50 
I have a generic class that I am trying to instantiate through a non-generic static method, but I am having some problems getting the type inference to work. Does anyone see some way to resolve this?

VB
Public Class MirrorObservableCollection(Of T)
    Inherits ObservableCollection(Of T)

    Friend Sub New(ByVal base As IList(Of T), ByVal mirror As Func(Of T, T))
    End Sub
End Class

Public NotInheritable Class MirrorObservableCollection
    Private Sub New()
    End Sub

    Public Shared Function Create(Of TItem, _
                                     TList As {INotifyCollectionChanged, _
                                               IList(Of TItem)})( _
                              ByVal base As TList, _
                              ByVal mirror As Func(Of TItem, TItem))  _
                       As MirrorObservableCollection(Of TItem)
        Return New MirrorObservableCollection(Of TItem)(base, mirror)
    End Function
End Class

Dim mirror = Function(s As String) s.ToUpperInvariant()
Dim base = New ObservableCollection(Of String)()
'this works
Dim m1 = MirrorObservableCollection.Create(Of String, _
             ObservableCollection(Of String))(base, mirror)
'this is what I want to do
'Compile Error: Data type of the type parameters in method 
'Create cannot be inferred from these arguments
Dim m2 = MirrorObservableCollection.Create(base, mirror)


EDIT: I tried some other things and found a few ways to make it work. Mixing variables initialized with lambdas and generic inference is not good for your health.

VB
Dim asFunc As Func(Of String, String) = Function(s) s.ToUpperInvariant()
Dim m3 = MirrorObservableCollection.Create(base, asFunc)
Dim m4 = MirrorObservableCollection.Create(base, Function(s As String) s.ToUpperInvariant())
'This does not work, the compiler cannot infer the lambda parameter type.
Dim m5 = MirrorObservableCollection.Create(base, Function(s) s.ToUpperInvariant())


Poking around in Reflector shows that mirror is of type AnonymousDelegate(Of string, string). For those that are interested, my conclusions about what is going on are:
m1) The compiler knows that it needs Func(Of string, string) and will wrap mirror accordingly.
m2) The compiler has not been able to figure out what type to use for TItem and thus if the annonymous delgate signature will match.
m3) The compiler is given a Func(Of string, string) which it will use to deduce that TItem is string and goes from there.
m4) The compiler is given a lambda that is string->string. There is some voodoo magic to combine lambda signature generation with generic inference and it all works.
m5) The compiler is given a lambda that is ???->???. It cannot determine what type the parameter is and thus assumes object. The error actually given is that the lambda parameter type cannot be determined, but also mentions that base does not implement IList(Of Object).

What surprises me most is that in neither of the error cases does it seem that the compiler was able to deduce TItem from base, which implements IList(Of String)
Questionhow to use .net framework with c++; Pin
geniuspc8-Dec-09 12:04
geniuspc8-Dec-09 12:04 
AnswerRe: how to use .net framework with c++; Pin
DaveyM698-Dec-09 12:34
professionalDaveyM698-Dec-09 12:34 
AnswerRe: how to use .net framework with c++; Pin
Paul Conrad8-Dec-09 13:28
professionalPaul Conrad8-Dec-09 13:28 
AnswerRe: how to use .net framework with c++; Pin
The Man from U.N.C.L.E.9-Dec-09 7:10
The Man from U.N.C.L.E.9-Dec-09 7:10 
Questionhow to insert image Pin
darkyro8-Dec-09 4:03
darkyro8-Dec-09 4:03 
AnswerRe: how to insert image Pin
Luc Pattyn8-Dec-09 5:10
sitebuilderLuc Pattyn8-Dec-09 5:10 
QuestionDifference between events in c# and vb.net Pin
ddecoy8-Dec-09 1:39
ddecoy8-Dec-09 1:39 
AnswerRe: Difference between events in c# and vb.net Pin
Dave Kreskowiak8-Dec-09 5:22
mveDave Kreskowiak8-Dec-09 5:22 
AnswerRe: Difference between events in c# and vb.net Pin
The Man from U.N.C.L.E.8-Dec-09 8:17
The Man from U.N.C.L.E.8-Dec-09 8:17 
GeneralRe: Difference between events in c# and vb.net Pin
ddecoy9-Dec-09 2:42
ddecoy9-Dec-09 2:42 
GeneralRe: Difference between events in c# and vb.net Pin
The Man from U.N.C.L.E.9-Dec-09 7:07
The Man from U.N.C.L.E.9-Dec-09 7:07 
QuestionHow to upload a xml file on Rest web server Pin
~Khatri Mitesh~7-Dec-09 1:22
~Khatri Mitesh~7-Dec-09 1:22 
AnswerRe: How to upload a xml file on Rest web server Pin
Rama Krishna Vavilala7-Dec-09 6:29
Rama Krishna Vavilala7-Dec-09 6:29 
AnswerRe: How to upload a xml file on Rest web server Pin
The Man from U.N.C.L.E.7-Dec-09 7:49
The Man from U.N.C.L.E.7-Dec-09 7:49 
GeneralRe: How to upload a xml file on Rest web server Pin
~Khatri Mitesh~8-Dec-09 1:17
~Khatri Mitesh~8-Dec-09 1:17 
QuestionHow to Debug a DLL written in VC 6.0 in ASP.NET ( MSVS 2008 ) application? Pin
yudhisthira7-Dec-09 0:51
yudhisthira7-Dec-09 0:51 
AnswerRe: How to Debug a DLL written in VC 6.0 in ASP.NET ( MSVS 2008 ) application? Pin
puri keemti7-Dec-09 19:37
puri keemti7-Dec-09 19:37 

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.