gridprotectionalliance / go2cs Goto Github PK
View Code? Open in Web Editor NEWGolang to C# Converter
Home Page: https://go2cs.net
License: MIT License
Golang to C# Converter
Home Page: https://go2cs.net
License: MIT License
For this strategy, a roughly equivalent and simpler C# form is to make use of tuples on both sides of the assignment.
In your example:
x, y = y, x+y
a comparable C# equivalent would be
(x, y) = (y, x+y)
Trying to use this but it appears to require a gopath to be set. On linux, I no longer use gopath in favor of using go modules which are now the default. It would be nice if go2cs could work in module mode and not require this (would also be nice if there were instructions for getting it to work on linux).
The following methods in sstring.cs
are preventing it from compiling:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator sstring(slice<byte> value) => new(value);
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator sstring(slice<char> value) => new(value);
It gives two error messages:
I've cloned the repo locally then opened cs2go.sln in Visual Studio Community (latest version). Since golib.cs does not compile, I'm really stuck! Any help would be greatly appreciated!
Visual Studio suggested the following fiz:
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator sstring(slice<byte> value) => new(value: value);
But it didn't work. So I removed the in
clause in the constructors affected:
public sstring(in slice<char> value) : this(value.ToArray()) { }
But I don't know the performance implications of these changes...
Hi everyone,
I have an Issue when i run deploy-gocore.bat.
error MSB4025: The project file could not be loaded. Data at the root level is invalid. Line 1, position 1.
I am very thankful for all the help.
Best regards!
Even though I am 2 days into GO (golang), I've been able to download, build and run csvq, onto a Windows 10 PC. Works brilliantly.
So thought it would be awesome if I could port it from GO to C#, then I can roll a CsvDataReader similar to a SqlDataReader around the csvq.net port and pull in the data directly into a DTO/POCO.
Upon running go2cs on the csvq => go2cs -o -i -s C:\Repo1\csvq I kept getting WARNING: Failed messages. So then I tried the -r option and nothing in terms of productive C# code was produced. See attached file for the command line output.
go2cs issue.txt
Hey, interesting project - just had to point out that "human-readable byte-code" is a contradiction in terms though.
Hi, great project!
I have a full unix-workflow and so was trying to get this working end-to-end in unix, through Docker.
I finally got it working, but it required some patches:
cd go2cs/src/go2cs/ScannerBase && sed 's/"\\\\"/Char.ToString(Path.DirectorySeparatorChar)/g' ScannerBase.cs
cd go2cs/src/go2cs && sed 's#\\\\#/#g' Options.cs
(This one could be changed to use Path.DirectorySeparatorChar too)
Without these changes, it didn't work properly, since Unix uses exclusively forward slashes for the path, and it was not finding the files or outputting properly.
Great job developing this project, it is simply amazing🎉
What are your thoughts regarding transpiling Go to F#? Is this something that you have considered?
I move go2cs.exe to bin folder
and extract dependencies.zip to src folder.
and when i run go2cs.exe,
the console window showed up and closed immediately.
nothing showed up.
is there something i missed?
Hello @ritchiecarroll,
I have been struggling with trying to convert my go code using this go2cs converter. I attempted to run the deploy-gocore.bat script but am unsure where the go executable is located once I complete this script or if I am missing a step in creating the go2cs executable. Also, does it matter if my go2cs code is located in the go directory where the golang is stored on my PC or can it be in a separate directory on my local drive.
Hi, I was eager to see what go2cs can do on linux. The installation section of the readme references go2cs.exe
but I can't find that anywhere in the repo or the release section, or information on source compilation.
Hi,
I am trying to convert an already existing go lang code to c#.
After converting the corresponding file to c#, there are some dependencies issue.
Even though I have downloaded the corresponding go standard libraries, I am still facing the issue saying that it cant find the standard libraries.
Kindly let me know how to resolve this issue.
Regards,
Rashmi
I am pleasantly impressed by all your work on this effort. Let me know if there is anything I can help with.
Is it possible to do it in reverse to convert C# to Golang
Hello,
Please let me know, if I am interested only in using ready open source GO libraries then is there any difference in using your tool and RemObjects GOLD ? So I need to reference these GO libraries from my .NET program and then run it on .NET runtime.
https://docs.elementscompiler.com/Gold/
It seems there is less activity in your project development now?
Output from the console output...
C:\Users\willi\go\src\go2cs\golib\GoFunc.cs(505,24): warning CS8600: Converting null literal or possible null value to non-nullable type. [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\GoFunc.cs(421,24): warning CS8600: Converting null literal or possible null value to non-nullable type. [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\GoFunc.cs(337,24): warning CS8600: Converting null literal or possible null value to non-nullable type. [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\GoFunc.cs(547,24): warning CS8600: Converting null literal or possible null value to non-nullable type. [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\GoFunc.cs(589,24): warning CS8600: Converting null literal or possible null value to non-nullable type. [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\GoFunc.cs(631,24): warning CS8600: Converting null literal or possible null value to non-nullable type. [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\GoFunc.cs(799,24): warning CS8600: Converting null literal or possible null value to non-nullable type. [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\GoFunc.cs(757,24): warning CS8600: Converting null literal or possible null value to non-nullable type. [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\GoFunc.cs(715,24): warning CS8600: Converting null literal or possible null value to non-nullable type. [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\GoFunc.cs(673,24): warning CS8600: Converting null literal or possible null value to non-nullable type. [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\TypeExtensions.cs(198,36): error CS8598: The suppression operator is not allowed in this context [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\TypeExtensions.cs(313,33): error CS8598: The suppression operator is not allowed in this context [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\TypeExtensions.cs(198,36): error CS8598: The suppression operator is not allowed in this context [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
C:\Users\willi\go\src\go2cs\golib\TypeExtensions.cs(313,33): error CS8598: The suppression operator is not allowed in this context [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
39 Warning(s)
4 Error(s)
Time Elapsed 00:00:01.21
The warnings I'm not worried about, but it's the last few "error CS8598: The suppression operator is not allowed in this context" that brings it all to a halt.
I'll use C:\Users\willi\go\src\go2cs\golib\TypeExtensions.cs(198,36): error CS8598: The suppression operator is not allowed in this context [C:\Users\willi\go\src\go2cs\golib\golib.csproj]
as the example here...
/// <summary>
/// Determines if <paramref name="targetType"/> implements specified <paramref name="interfaceType"/>.
/// </summary>
/// <param name="targetType">Target type to test.</param>
/// <param name="interfaceType">Interface to search.</param>
/// <returns>
/// <c>true</c> if <paramref name="targetType"/> implements specified <paramref name="interfaceType"/>;
/// otherwise, <c>false</c>.
/// </returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool ImplementsInterface(this Type targetType, Type interfaceType)
{
if (!interfaceType.IsInterface)
return false;
while (!(targetType is null!))
{
if (targetType.GetInterfaces().Any(targetInterface => targetInterface == interfaceType || targetInterface.ImplementsInterface(interfaceType)))
return true;
targetType = targetType.BaseType!;
}
return false;
}
It's failing the build due to the trailing ! on null
in the where clause. I think this would be fine if an actual type is described in that spot, but with null
it may be problematic.
please help me bro, my problem is in the go2cs.exe file, how can i get that file?
Step to reproduce
===========================================================
Starting Go code pre-scan to update metadata...
Starting pre-scan of "C:\Go\src\archive\tar\common.go"...
Finished.
Starting pre-scan of "C:\Go\src\errors\errors.go"...
Finished.
Starting pre-scan of "C:\Go\src\fmt\doc.go"...
Finished.
Starting pre-scan of "C:\Go\src\math\abs.go"...
Finished.
Starting pre-scan of "C:\Go\src\os\dir.go"...
Finished.
Starting pre-scan of "C:\Go\src\path\example_test.go"...
Finished.
WARNINGS:
example_test.go:5:0: Defined package clause "path_test" does not match file
path "C:\Go\src\path\example_test.go"
Windows shows "go2cs Has Stopped Working"
Is it because Map/Channel is not yet implemented? But according to the doc it can compile Go standard library. May I know which version of Go can be successfully compiled it's Standard Library you tested?
I change netstandard2.1 will show some error.
PS: Error CS0266 can not change type 'long' to 'nint'。golib (netstandard2.1) ..\go2cs\src\gocore\golib\builtin.cs
Using VS 17.2.6, and .NET 6.0. After running batch file to get packages built, restarted Visual Studio.
Keep getting build breaks on SortArrayType.Main().
While I understood what the code was trying to do, I'm pretty certain it's invalid in C#: not sure why it's building for you, but it simply wasn't for me.
When testing out the example:
Convert a single Go file: go2cs -l Main.go
I get the following error:
Error: Unable to resolve GOROOT src directory: "C:\Go\src". Validate that Go is properly installed.
Is there any configuration I need to do for this to work? 🙂
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.