Closed weitzhandler closed 9 years ago
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. But you missed the point, I wasn't complaining or asking for workarounds, I was merely suggesting a feature. Sorry if I sounded different, feel free to edit my post if you're a contributor.
@weitzhandler Put the XML processing part in seperate DLL so it can can be referenced in a C# Project (or any other .net language).
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 <
as an expression beginning token.
There is the leftshift operator which is a double <<
- invalid as XML literal anyway
AFAIK c# paradigm is to stay away from technology specific features. So I doubt we'll ever see xml literals or json literals built into the language itself. I think this is also a reason we don't have close to the metal support for INotifyPropertyChanged.
2015-04-02 2:19 GMT+02:00 Shimmy notifications@github.com:
There is the leftshift operator which is a double << - invalid as XML literal anyway
— Reply to this email directly or view it on GitHub https://github.com/dotnet/roslyn/issues/1746#issuecomment-88672913.
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. ITOH, XML is a general means to store and retrieve tree data, and is widely used in every single platform that's built on top of C#. So I still vote YESSSSS.
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 XML
is your custom imported static method:
public static class XmlExtension
{
public static XmlDocument XML([XmlString] string xml) { /*Logic*/ }
}
...and XmlStringAttribute
is used by Roslyn to highlight and process the string the way ReSharper handles custom string formatters?
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 feels in VB. Wrapping it in quotes is missing the whole point. Am I the only over around heavily using XML? Am I the only one who got to taste VB literals?
Sent from my Android On Apr 2, 2015 4:23 PM, "MgSam" notifications@github.com wrote:
@gafter https://github.com/gafter I love the "Over Our Dead Bodies" label and "When Heck Freezes Over" milestone. Responding entirely through metadata.
Reply to this email directly or view it on GitHub https://github.com/dotnet/roslyn/issues/1746#issuecomment-88895055.
I think there's a few reasons this wouldn't happen: a) XML is out of favor now in favor of lighter protocols like JSON. b) Adding embedded DSLs into a language has a really high bar to get over. LINQ query comprehension syntax is the only case where anything has passed this bar for the C# team. c) There are other, more general features which probably mostly satisfy this need. I've proposed before adding block quotes, which would allow you to paste in XML (or anything else) without the need to escape any characters at all. Others have suggested having user-defined string delimiters to achieve a similar outcome.
I think the tag should be Over Ander's Dead Body
@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: :smile:
@weitzhandler
<variable
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 XML$
could hook into the IDE and provide the syntax highlighting and intellisense that XML literals enjoy in VB.
Similar extensions such as JSON$
or YAML$
can also be created by the community.
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 And https://github.com/volkovku/RazorTemplates to use it without MVC or ASP
@AdamSpeight2008
...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.
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. Giving language-level support for any tree-based technology would lead to an endless demand of support for various mechanisms like XML, JSON, and other blob architectures and mechanisms, that who knows how long those technologies are to last anyway.
And @davepermen regarding https://github.com/dotnet/roslyn/issues/1746#issuecomment-88883979 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) Then, the support for serializing those trees to XML, JSON, Redis is already a matter of provider implementation. So this should be really be thought thru to be able to comply with the major tree based techniques already existing, namely XML, JSON, Redis and other NoSql .NET client capabilities etc.
Here's some pseudo prototyping out of my brains stack.
var people = new dynamic
//anything under dynamic can be either exsiting objects
//or gets interpreted as dynamic
{
LastAccessDate = DateTime.Now,
People = new[] {
new Person //Person isn't declared it's a pseudu dynamic object
{
FirstName = "John",
LastName = "Doe",
Children = new[] {
new Person
{
FirstName = "Ed",
Address =
new Address
{
City = "New York",
//primitive types are always parsed as attributes,
//unless explicitly specified
[Element]
Country = "USA"
}
},
new Person
{
FirstName = "Beth",
LastName = "Doe",
BirthDate = DateTime.Now.AddYears(-20),
Spouse = new Person
{
MaidenName = "Washington"
}
}
}
},
new Professor : Person //???
{
LastName = "Einstein",
Phone = new Phone
{
Type = PhoneType.Home, //???
Number = "911"
}
}
}
};
And here comes the most important part. Please learn a bit about LINQ to XML in VB.NET, and XML manipulation in VB.NET. Although XML is indeed very comprehensive I'm sure this pattern can be generalized. And I say most important part, because the searching capabilities in No-Sql is even more important than being able to define it on the fly.
var doeFamily = x.People...<Person>
.Where(p => p.@LastName == "Doe")
.OrderBy(p => p.@BirthDate);
foreach (var doeMember in doeFamily)
Console.WriteLine("{0} {1}", doeMember.FirstName, doeMember.LastName);
var allPplWithPhones = x...<Phone>.Select(p => p.Parent());
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. The precise standards could be different than VB.NET and unbound to XML or any other technology, but the mechanism is very useful and compelling.
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:
Property description | Example | Description
------------------------------------------------------------------------------------------------
child axis | contact.<phone> | Gets all phone elements that are child elements
| | of the contact element.
attribute axis | phone.@type | Gets all type attributes of the phone element.
descendant axis | contacts...<name> | Gets all name elements of the contacts element,
| | regardless of how deep in the hierarchy they
| | occur.
extension indexer | contacts...<name>(0) | Gets the first name element from the sequence.
value | contacts...<name>.Value | Gets the string representation of the first
| | object in the sequence, or Nothing if the
| | sequence is empty.
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 FormattableString
support that already exists in string interpolation could be helpful?
This proposal may make it introducing any script syntax to C# syntax: https://github.com/dotnet/roslyn/issues/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):