I am converting a lot of VB.NET code over to C# and there are a lot of VB functions that C# doesn't have such as DateAdd and DateDiff. Can someone tell me the libraries I would have to reference in order to have access to these functions in my C# code if it is even possible. I already tried adding a reference to Microsoft.VisualBasic and it doesn't work.
Time is a factor here which is the only reason I am looking into doing things this way. I want to leave the code in place as much as possible.
Opps it actually is in Microsoft.VisualBasic.
You have to access it like this:
Microsoft.VisualBasic.DateAndTime.DateAdd()
Related
after long time of reading on google I still don't know how can I work with this EDB http://msdn.microsoft.com/en-us/library/aa912256 at C#. I read a lot of about wrapers and SWIG solution. But how can I wrap functions which are at windbase.h.
I want to make EDB in my c# program. Can I make some way dll from <.h>?
After some effort I think now, it is not good idea try to use windbase.h in C#. There are great and useful articles about P/invok. Just write "Call Unmanaged DLLs from C#" to google. One of best for me was:
http://msdn.microsoft.com/en-us/magazine/cc301501.aspx
But because our unmanaged function requires a structure as a parameter, the structure needs to be defined in the managed code as well as in the unmanaged code. In other words, it is needed to rewrite all structures and constants and stuffs to c#. And there are also other dependencies on windbase_edb.h, winnt.h, windef.h, winbase.h...
From my point of view it is too difficult way. Or it can be done differently?
I have developed a dll in C#.net. Can we decompile the same in VB.net. If yes, how to do that?
Use a tool like Reflector to convert a compiled C# assembly (IL) into decompiled VB.NET source code (might lose some meaning with certain variable names). Another post mentions some free alternatives to Reflector.
Or convert the C# code using an online resource such as this one (1 code file at a time though).
I agree with Mitch, but as a free alternative to Reflector:
ILSpy
dotPeek
Assuming you have the source, you can use sharpdevelop to convert whole solutions back and forth between c#.net and vb.net
The same group also developed a plugin for visual studio: Code Converter C# to/from VB.NET
Sometimes C# cannot be converted (or decompiled) into VB.Net because there are some elements of C# that have no equivalent in VB. E.g. iterators (yield) and unsafe code. Furthermore some of the free converters fail badly even when there are direct equivalents.
Why do you want to do this anyway? It's probably easy to just use the C# DLL from VB.Net code: you can call it, you can inherit from it. "CLS compliance" will help with this.
For what it's worth, it's also true that there are some elements of VB that have no equivalent in C#, e.g. exception filters.
If you've developed it your self I assume you have access to the source? If so you can just convert it all though here:
http://www.developerfusion.com/tools/convert/csharp-to-vb/
I am trying to write a replacement for a VB6 dll that is referenced by another VB6 in c#.net.
For now we can only work on the later and I am having some success with this. Except I have run into a problem.
My Enums are being mangling resulting it being called 'A1BACSTrans_BACSAU' instead of the expect 'BACSAU'
the legacy code will (obviously) no longer compile.
Can this be prevented? if so, how? I have heard of modifying the IDL but I can see no references in their to a mangled name only unmangled...
Thank you in advance!
Guys, I have been discussing this over at c-sharpcorner also and although I mainly arrived at the solution myself I have document it there
http://www.c-sharpcorner.com/Forums/Thread/111642/preventing-com-name-mangling.aspx
Basically changing the IDL is the way I found to do it.
I'd love to know if there is a way to do it in code, maybe an attribute but if there is a way I don't know it!
I've read many of the non-nullable questions and answers. It looks like the best way to get close to non-nullable types in C# (4.0) is Jon Skeet's NonNullable<> hack.
However, it seems that C++/CLI has solved much of the problem by supporting managed references: Foo% (instead of native C++ Foo&). The compiler makes this work by adding modreq(IsImplicitlyDereferenced) to the argument. Trying to call such a function from C# results in:
'<FunctionName>' is not supported by the language
Is there anything better then NonNullable<>?
Is there any way to (reasonably--i.e., w/o using reflection) call a C++/CLI method Foo::Method(Bar%) from C#?
[edit] It seems there is currently nothing better than NonNullable<>...I wish I would have gotten some comments on the C++/CLI stuff as it already has at least a partial solution.
I've run into this a few times...I've yet to find anything better than Skeet's solution. It's solved all the cases I've come across, so I have to give it my vote.
I agree it's a bit of a hacky situation that we have to resort to that...but his fix does solve the problem.
Yep, spec#: http://research.microsoft.com/en-us/projects/specsharp/
-- Edit: I just noticed you said C# 4.0; I'm fairly sure Spec# doesn't support that version. Nevertheless, it's worth a review.
You may also be able (I think) to check at a slightly later stage then compile, via a rule in Gendarme: http://www.mono-project.com/Gendarme (assuming that runs against 4.0)
What is the equivalent C# code for this VB.NET code?
My.Computer.FileSystem.GetFiles(....)
The My class is VB.NET specific.
You can use the static methods of the System.IO.Directory class - e.g. Directory.GetFiles.
You can use the VB.Net's "My" in C#. It's all code, after all. In your C# project, you'd simply add a reference to Microsoft.VisualBasic
You can check out a more detailed explanation here:
http://www.codeproject.com/KB/cs/MyNamespace.aspx
I don't think there is anything in 'My' that you can't achieve without using it; but just because you aren't programming in VB.Net you have to not use it.
Having said all that - most architect type people I know would roll their eyes at you if they saw you adding a reference to VisualBasic in a C# project. But it's totally doable.