VB.NET equivalent of Func - vb.net

I have a C# statement
solidGauge1.LabelFormatter = val => val.ToString("P");
I want the VB.NET equivalent. Telerik code converter gives
"solidGauge1.LabelFormatter = Function(val) val.ToString("P")"
This is not correct since it seems to be ignored. The C# statment works in a C# project. The usage/source of this is lvCharts Gauge control

Try this
solidGauge1.LabelFormatter = Val.ToString("P")

Related

Typescript Quickstart Tutorial

I am working with Visual Studio 2015, ASP.NET Core
When I walkthrough the Typescript Tutorial version 2.0.6.0 I have a problem with the function sayHello not producing the correct output.
function sayHello() {
const compiler = (document.getElementById("compiler") as HTMLInputElement).value;
const framework = (document.getElementById("framework") as HTMLInputElement).value;
return "Hello from ${compiler} and ${framework}!";
}
When I edit a textbox I see the following output:
Hello from ${compiler} and ${framework}!
The variables are not replaced as would be expected.
Does anyone have any idea what could be wrong here?
You have to use template strings surrounded by backtick/backquote (`) characters to embed expressions within.
return `Hello from ${compiler} and ${framework}!`;

MonoGame/XNA Mouse.GetState() always returns 0,0 position

I'm trying to get the position of the cursor by calling the mouse class and using the GetState method but the return value is always 0,0. I've searched everywhere and all the code looks the same on other examples. I've tried alternative ways of declare the class but I get the same results.
public void Update() {
var ms = Mouse.GetState();
cursorPos = new Vector2(ms.X, ms.y);
}
If you are using Mono, it's possible that Mouse.GetState method is extended. On some past versions there was problems Mouse.SetState method, could be that also problem was also in Mouse.GetState... so I suggest you take latest Mono framework.
Or you can try to access directly to that method.
var ms = Microsoft.Xna.Framework.Input.Mouse.GetState();
var mp = new Point(ms.X, ms.Y);

Ability to set the context of the expression

Is there a way to set the context of the expression in Dynamic Expresso library, so that we can do something like the following:
interpreter.Eval("FirstName", new Parameter("person", new { FirstName="Homer", LastName="Simpson"}));
rather than
interpreter.Eval("person.FirstName", new Parameter("person", new { FirstName="Homer", LastName="Simpson"}));
Maybe we could have a another option that would say that the first parameter is to be used as the context for the expression.
I guess there could also be another version of Parse and Eval methods that simply takes the expression text and a simple object value that will serve as the expression context.
Other than that and the lack of support for dynamic types, I am really liking this library. I had worked on something similar, but had not added support for extension methods and generic method calls.
Thanks for the great library,
Neal
There isn't a built-in solution but you can simulate it in many ways:
Option 1: Inject an expression
var workingContext = new { FirstName = "homer" };
var workingContextExpression = Expression.Constant(workingContext);
var firstNameExpression = Expression.Property(workingContextExpression, "FirstName");
var interpreter = new Interpreter();
interpreter.SetExpression("FirstName", firstNameExpression);
Assert.AreEqual(workingContext.FirstName, interpreter.Eval("FirstName"));
Basically I inject an expression using SetExpression method. The injected expression is the property that you want to be available.
Option 2: Use this/me/it variable
You can inject a variable that will contain your working object. I usually call it this (or me or it depending on the application).
var workingContext = new { FirstName = "homer" };
var interpreter = new Interpreter();
interpreter.SetVariable("this", workingContext);
Assert.AreEqual(workingContext.FirstName, interpreter.Eval("this.FirstName"));
Option 3: A combination of the previous solutions
var workingContext = new { FirstName = "homer" };
var interpreter = new Interpreter();
interpreter.SetVariable("this", workingContext);
var firstNameExpression = interpreter.Parse("this.FirstName").LambdaExpression.Body;
interpreter.SetExpression("FirstName", firstNameExpression);
Assert.AreEqual(workingContext.FirstName, interpreter.Eval("FirstName"));
Equal to the first solution but I generate the expression using the parser itself.
Consider that all solutions assume that you must have an Interpreter instance for each context.
Disclaimer: I'm the author of Dynamic Expresso library.
Starting with DynamicExpresso v2.13.0, it's possible to define a variable named "this", that will be used for implicit resolution:
var target = new Interpreter();
target.SetVariable("this", new { FirstName="Homer", LastName="Simpson"});
// 'this' variable is used implicitly
Assert.AreEqual("Homer", target.Eval("FirstName"));
// 'this' variable can also be used explicitly
Assert.AreEqual("Homer", target.Eval("this.FirstName"));

How to write a VB.Net Lambda expression

I am working on a VB.net project now. I am new to VB.Net LINQ and would like to know the Lambda equivalent of
var _new = orders.Select(x => x.items > 0);
in VB.Net.
Someone please suggest!
The lambda syntax isn't that much different than creating a regular delegate.
If creating a lambda which has a return value, use Function. Otherwise if you're creating one that doesn't, use Sub.
Dim _new = orders.Select(Function(x) x.Items > 0)
Dim action As Action(Of Item) = Sub(x) Console.WriteLine(x.Items)

How can I set up expectations for event registration on a multimock

I am using RhinoMocks 3.6 and would like to use the multimock feature to implement both a class and a interface.
var mocks = new MockRepository();
var project = mocks.StrictMultiMock(
typeof(Project),
typeof(INotifyCollectionChanged));
using (mocks.Record())
{
((INotifyCollectionChanged)project).CollectionChanged += null;
LastCall.Constraints(Is.NotNull()).Repeat.Any();
}
The LastCall is working though. I get this message :
System.InvalidOperationException : Invalid call, the last call has been used or no call has been made (make sure that you are calling a virtual (C#) / Overridable (VB) method).
What am I doing wrong here??
Have you actually checked that the Project class has methods you can override as the error message indicates? I'll assume you have. :-)
I'd suggest you switch to using the AAA syntax instead of record/replay as shown here:
I assume you're wanting to know if the class under test reacts the right way when the CollectionChanged event is fired? If that's the case, you can do it something like this:
var project = MockRepository.GenerateMock<Project, INotifyPropertyChanged>();
project.Expect(p => p.SomeMethod())
.Repeat.Any()
.Raise(p => ((INotifyCollectionChanged)p).CollectionChanged += null,p,new NotifyCollectionChangedEventArgs());