-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C# Transpiler, API, and Tests #129
Conversation
That's awesome, thanks for doing that work :) |
Very awesome @pragmatrix :-) A few things that I am wondering about ..
Of the above (1) should be quite easy. And for (2) I guess it would just require documentation. Can NuGet packages be released by a command line tool similar to the way npm works? |
Yes, |
thanks @pragmatrix ! do you mind changing the syntax to c# 5? Not everyone can use the latest VS. I think this makes the library a little more re-usable. |
@woehrl01 No I don't mind, Resharper got me there :) Can you do the pull request? And would a .NET 4.0 compatible NuGet package fit into your project? |
@woehrl01 I had some time to see how hard it would be to get rid of |
@pragmatrix Awesome! Compiles perfectly, here. I just had to reference |
This pull request adds a C#/.NET transpiler, API, and tests to the css-layout project. The transpiler is integrated by adding a few lines to transpile.js and the API is very similar to the Java version.
Details
Formatting
Even though the contribution guide states otherwise, the C# code is indented by 4 spaces instead of 2, and
{
braces are usually placed on the next line. I think that keeping the default Visual Studio settings for C# code will make the code easier to maintain, also I've added an.editorconfig
file so that other editors can pick up the correct format.Idiomatic CSharp
All public names of classes, methods, and members are in PascalCase. Properties were used when they seemed appropriate.
Enum members defined by CSSAlign, CSSConstants, CSSDirection, CSSFlexDirection, CSSJustify, CSSPositionType, and CSSWrap have been converted to PascalCase.
CSharpTranspiler.js
will take care of the case conversion for the generated code.Method forwarders / duplication
To keep the differences between the Java and C# transpiler minimal, I decided to leave some internal methods in camlCase. When appropriate, these methods were implemented as extension methods.
Visual Studio Solution
The solution's CSSLayout project is located in
src/csharp
and produces a portable class library Profile 259, which supports the .NET Framework 4.5, Windows 8+, Windows Phone 8.1, Windows Phone Silverlight 8, and Xamarin.Android, Xamarin.iOS, and Xamarin.iOS (Classic API).The solution also includes the test project, which uses NUnit.
The code uses C# 6 syntax.
File Format
All *.cs files are encoded in UTF-8, LF line endings, no BOMs. *.sln, *.csproj, and *.config files are in UTF-8 with BOMs and CRLF line endings.
File Notes
CSSNode.cs
Width
andHeight
instead ofStyleWidth
andStyleHeight
. All properties except the ones beginning withLayout
are meant to be style related.CSSNode.style
member is not accessible through CSSNode yet.Spacing.cs
This class seems not to be indented to be public, but gets exposed in CSSNode in the Java API through a field named
padding
. I decided to remove CSSNode.padding for now, because padding can already be modified with CSSNode's methods.CSSSpacingType.cs
I did not liked the idea of using integers for the spacing type, so I've introduced an enum named CSSSpacingType, which is used in CSSNode for specifying the various types of spacing for paddings, margins, and borders.
Build Script
Only the transpiler is run from the gruntfile. However, there is a Makefile in the
src/csharp
directory that is used to build & test the solution and pack & upload the NuGet package.NuGet Package
This pull request is based on an unofficial adoption, which I am maintaining for some time. Also there is a NuGet package available that is named
Facebook.CSSLayout
. I am happy to transfer ownership, if this pull request is accepted.I've decided to properly clean up the API before creating this pull request, thereby introducing (hopefully very minor) incompatibilities with code written against the NuGet packages.
And sorry, no history, I've never rebased the csharp version, but will from now on.