|
I actively avoid learning new language features, and I'm unlikely to use that, but is there something similar for TryParse ?
if ( System.Int32.TryParse ( s , out int i ) ...
To likewise limit the scope.
|
|
|
|
|
I believe that was added at C# 7 - and it should work exactly as you show.
The
if (obj is string str)
{ is really handy when you write event handlers, where you want to use a control:
private void AnEventHandler(object sender, EventArgs e)
{
if (sender is TextBox tb)
{
...
}
} Instead of
private void AnEventHandler(object sender, EventArgs e)
{
if (sender is TextBox)
{
TextBox tb = (TextBox) tb;
...
}
} Or
private void AnEventHandler(object sender, EventArgs e)
{
TextBox tb = sender as TextBox;
if (tb != null)
{
...
}
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
Ah, yeah, OK I see it. I don't like the syntax, but it's something I would use... were I not limited to VS 2013 (due to SSIS 2014).
|
|
|
|
|
Oh, by the way: the TryParse declaration - I just checked and it doesn't limit the scope the way I assumed it would.
private void MyMethod()
{
{
if (System.Int32.TryParse("666", out int i))
{
Console.WriteLine(i);
}
Console.WriteLine(i);
}
Console.WriteLine(i);
}
"I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
AntiTwitter: @DalekDave is now a follower!
|
|
|
|
|
|
So it's... a love hate relationship?!
Pink would say, you hate it so much it can only mean true love!
|
|
|
|
|
Yes, like with anonymous methods, awaitable methods, iterators, but for different reasons.
(By iterators i means C#'s yield "coroutine" capabilities, not the related IEnumerable nonsense - can't stand that)
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
This as operator is faster than a C# cast?! It seems to work like dynamic_cast , which is C++'s slowest one (use the vptr to verify the type). Other C++ casts are fast because they just assume the target is of the desired type, perhaps after a compile-time check.
|
|
|
|
|
Yep it's faster in .NET. Go figure. I guess verification the cast is successful is a separate step or something. .Net Tips - using as vs casting in C# | theburningmonk.com[^]
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Now can you add an isnt or (aint) operator?
if ( v isnt string ) ...
|
|
|
|
|
It parses fast enough, but it takes so long to resolve what it parsed though. I need to figure out how to optimize this thing.
Still, the parser is getting more and more stable. It already parses better than that ANTLR C#6 grammar did.
Technically, it can usually convert to VB without going through the resolution process, but it's kind of a hack. It just so happens that in VB there's no difference in syntax between a delegate invocation and a method call, nor a field access and a property access so it happens to work, but it's not proper to resolve method invocations as delegate invocations and all member access as field access which is what the parser has to do, since it doesn't have type info.
Overall I'm happy with the project but I need to figure on something to make it more speedy so it will be generally useful.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Awesome work (and best of luck with the optimising)
cheers
Chris Maunder
|
|
|
|
|
Thanks. The articles bombed so far but I think that's either because it's so preliminary, or people don't understand it, or nobody has a use for it. Or a combination of those things. Still, *I* have a couple of uses for it and I understand it so that's a start.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
There are no lines.
Something I keep wondering about your Slang system is whether or not it can be used to implement a language extension similar to Oracle's PRO*C or Microsoft's ESQL -- SQL statements embedded in C programs (or C# now I suppose).
|
|
|
|
|
LINQ already kind of provides that, but yes. You can use this as a starting point to implement a Domain Specific Language.
If I was real clever I might make it so you could extend the language through the language itself. Adding keywords and such but that's out of the scope of this for now.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
honey the codewitch wrote: LINQ already kind of provides that
It does no such thing.
|
|
|
|
|
Then i misunderstood what you meant. LINQ provides SQL like syntax over disparate datasources, including databases.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
|
Then I must be using a magic feature of an as of yet unheard of version of C# with magical embedded sql like syntax that nobody else has access to.
Gosh thanks microsoft. Boy, I feel speshul.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Unstoppable force, may I introduce immovable object.
ESQL and Pro*C aren't "SQL Like".
They are embedded SQL.
|
|
|
|
|
Wow... are you trying to impress us?
well.... it might work!
you need to make an article with some cool nifty example! :P
|
|
|
|
|
The 2 articles i posted on it so far bombed LOL
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
mm... I am not sure what you mean by "bombed"
is it this and that one?
I can only see 4 and 2 votes so far!
Just quickly read that at work just now!
Mm.... this is cool and obviously quite an achievement
However I am not sure where I could reuse that myself..
I'll have to think about it again if / when I need code generation....
|
|
|
|
|
It *is* pretty specialized. I do a lot of codegen so obv to me it's useful but i don't think it will ever have a wide audience.
Where it's super useful to is once it's shored up enough I can use it in my parsers for code inside the grammar. If you write it in Slang it will render out in whatever so it doesn't tie the grammar to a particular output language. Downside is the language in the grammar must be Slang.
Right now I've also added an Evaluate() method to CodeDomResolver so it can evaluate expressions, call methods and such at runtime. If I did full evaluation i could do runtime grammars without codegen but it would be S-L-O-W.
When I was growin' up, I was the smartest kid I knew. Maybe that was just because I didn't know that many kids. All I know is now I feel the opposite.
|
|
|
|
|
Neal.fun[^]
Frank Wilhoit: “Conservatism consists of exactly one proposition …There must be in-groups whom the law protects but does not bind, alongside out-groups whom the law binds but does not protect.”
We never have had a president* so completely deserving of scorn and yet so small in the office that it almost seems a waste of time and energy to summon the requisite contempt
|
|
|
|