-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Proposal: XML literals and embedded expressions in C# #1746
Comments
What's preventing you from using both languages in a Solution? |
@AdamSpeight2008 First of all, as I mentioned, when I have a code base in C# and I want to link out several classes in a different platform. |
@weitzhandler |
Again Adam thanks for trying to help, I know how to work around that, but this post is not about how to workaround the lack of this feature, but a request and discussion on how to implement this language feature in the C# language. |
I think it would be hard or require a rewrite of the C# lexer and parser, to be statful like VB.net, As the grammar rules for XML are different to VB's. For example '<' has ~18 different meaning in vb.net depending on where it is used. |
But AFAIK C# has no |
There is the leftshift operator which is a double |
AFAIK c# paradigm is to stay away from technology specific features. So I 2015-04-02 2:19 GMT+02:00 Shimmy [email protected]:
|
Although I understand that, I wouldn't say XML is as tech-specific as INPC, INPC is widely used in XAML apps, but not used in ASP.NET at all. Same applies to JSON, which is only web-specific. |
OH that OverOurDeadBodies label LMAO! Right on fools day night! HAHA! |
when heck freezes wtf hahahaha |
Hmm I use json outside of webdev all the time. I never use XML anymore. So no, it makes no sense to support one specific tech over the other. |
Instead, transpilers like jsx (XML inside JavaScript) or razor (c# inside html) would be more flexible off the main language projects.. Something like csx (XML inside c#) as an own project instead? |
How about this: var contactDoc = XML(@"
<?xml version=""1.0""?>
<contact>
<name>Patrick Hines</name>
<phone type=""home"">206-555-0144</phone>
<phone type=""work"">425-555-0145</phone>
</contact>"); Where public static class XmlExtension
{
public static XmlDocument XML([XmlString] string xml) { /*Logic*/ }
} ...and http://www.jetbrains.com/resharper/webhelp80/Code_Analysis__String_Formatting_Methods.html |
@gafter I love the "Over Our Dead Bodies" label and "When Heck Freezes Over" milestone. Responding entirely through metadata. |
Yeah my wife woke up from my laughter this morning... Anyway @dsaf I believe you never actually saw how XML literals works and Sent from my Android
|
I think there's a few reasons this wouldn't happen: |
I think the tag should be |
@dsaf VB.net has language support for XML-Literals.So for example if if rename a node, put forget to alter the closing node. It is a compile-time error. If you also import the schema you'll get intellisense support as well. |
Everything old is new again: 😄 |
@weitzhandler Is that:-
You could always fork and implement it in your own flavour of C#, or use COmega. |
@dsaf So here's a thought... there has been some discussion about making the string interpolation mechanism extensible using prefixes, e.g. var xml = XML$"<?xml version=""1.0""?>
<contact>
<name>Patrick Hines</name>
<phone type=""home"">206-555-0144</phone>
<phone type=""work"">425-555-0145</phone>
</contact>"; A benefit of extensible string parsing is that Similar extensions such as |
Just use the razor engine, that way you won't clutter your code with xml bloat and you still have the expressiveness that comes with model binding in an xml view. Example: http://stackoverflow.com/questions/5943396/how-do-i-output-xml-with-asp-net-razor |
As far as I understand Roslyn can tackle both without altering C# syntax. |
If support for something like this is added I would very much prefer a generalizable approach like the one @bondsbw mentions. Also, I use JSON outside of web projects all the time. |
XML literals, are recognized as part of VB.NET. And @davepermen regarding #1746 (comment) that XML is out of fashion, yeah I agree that XML might be too verbose, but don't forget that it has schema, attributes and other very important feature support that JSON lacks. That being said, I believe the solution should be agnostic, and there can be support for tree-data in a root/element/attribute way, bound to the language. There should maybe be support to map objects to a schema (see here how it's done in VB.NET) Here's some pseudo prototyping out of my brains stack.
And here comes the most important part.
So this could be great in C# having an in-language option to walk thru children of dynamic objects by property name/value etc. etc. This might open a whole new convenience in storing, accessing, and manipulating NoSql data. Giving options for implementation of Linq to NoSql for databases like Redis etc. And I quote from the previous link on how VB.NET provides support for accessing XML:
|
Per #3912 we are probably never going to do this. We aren't comfortable tying C# to a specific format like that. |
@MadsTorgersen, I can't stop myself from wondering why we included an SQL-variant syntax for LINQ if we are not comfortable tying C# to a specific 3rd part language - in all cases, XML is more integral to C# than SQL... To be constructive, what I'd like to see is the equivalent of NuGet packages enabling inlining of different languages, JSON, XML, HTML ... |
@bjorn-ali-goransson Then it is not longer C#. XML (and the Xpath, XSLT family) is merely an different syntax of Lisp/Scheme. |
LINQ query syntax is only SQL-like, it's not SQL and it doesn't tie C# to any outside language/format specifications. I think that when integrating logic with wire formats like XML, HTML or JSON that a templating engine like razor makes more sense. |
If it's possible, then to interpolate C#-values in XML like we do in strings in C#6 would be nice and very time saving, especially if it could be done through some pluggable mechanism ... But then again, it would be quite far-fetched to hope for that the infrastructure would allow this without major changes. |
@bjorn-ali-goransson I'm not quite sure what you're asking for, but maybe the |
This proposal may make it introducing any script syntax to C# syntax: #34821 |
Hi,
I am a born VB dev. Currently I develop only C# because I prefer the terse syntax over VB's verbose words, but I do miss some awesome features we had in VB.
One of the most notable and very compelling features I do miss very much, is the awesome XML literals and Embedded Expressions paradise going on in VB.
As soon as you get used to these features, separating out really feels like going hardcoded back again.
When I'm to develop a project that involves a lot of XML I'll prefer VB, eventho I don't like it's verbose syntax, and won't be able to link to other source files of my C# code base.
Anyway for those of you unfamiliar with VB, get a taste. Notice how all the XML literals are recognized as XML by the compiler (they're not wrapped with double-quotes).
Manipulating objects with strings (embedded expressions):
The text was updated successfully, but these errors were encountered: