I have some bindings warning that I can't solve:
System.Windows.Data Information: 10 : Cannot retrieve value using the
binding and no valid fallback value exists; using default instead.
BindingExpression:Path=AddNewObjectCommand; DataItem=null; target
element is 'ButtonWithIcon' (Name='uc'); target property is
'ButtonCommand' (type 'ICommand')
My understanding is that I should use a fallback value. This works with simple object types, however don't know how to handle this for complex objects like lists, or in that case commands.
Here is what I have tried, with no luck:
<controls:ButtonWithIcon ButtonCommand="{Binding CancelCommand, FallbackValue={x:Null}}" />
Would you have any thought on this?
Thank you in advance!
Related
I'm using fluent assertions and I have this test:
result.Should().NotBeNull();
result.Link.Should().Equals("https://someinvoiceurl.com");
which works fine but when I try this
result.Should().NotBeNull().Which.Link.Equals("https://someinvoiceurl.com");
I got this error
'AndConstraint<ObjectAssertions>' does not contain a definition for 'Which' and no accessible extension method 'Which' accepting a first argument of type 'AndConstraint<ObjectAssertions>' could be found (are you missing a using directive or an assembly reference?)
What I'm doing wrong?
The problem here is that .NotBeNull() is not generic (it is an extension on ObjectAssertions rather than GenericObjectAssertions), so it can't chain the type information to later calls.
I think this is a flaw in the library design, personally, but it is easily worked around by substituting .NotBeNull() with .BeOfType<T>() as so:
result.Should().BeOfType<ThingWithLink>() // assertion fails if `result` is null
.Which.Link.Should().Be("https://someinvoiceurl.com");
Of course, if you assert on your ThingWithLink type a lot, it could be worth writing a custom assertion so that you can be "more fluent":
result.Should().BeOfType<ThingWithLink>()
.And.HaveLink("https://someinvoiceurl.com");
If you need something more ad-hoc, you can always just use .BeEquivalentTo() to do structural comparison:
result.Should().NotBeNull()
.And.BeEquivalentTo(new { Link = "https://someinvoiceurl.com" }); // ignores all members on `result` except for `result.Link`
I have been using different forms of Mule's Expression language.
I couldn't figure out the difference between
#[flowVars.myVariable]
and
#[flowVars['myVariable']]
They both give the result when there is a variable. But why do they behave differently when the variable is not present?
Like if the variable being called is not available, then the first expression would result in a exception. Whereas the second expression just gives out a warning or prints out as is, if in a logger message.
Why is this difference?
Also when going through the documentation for Mule 3.6 I found that the second expression is not longer shown in the documentation.
Is the expression #[flowVars['myVariable']] being deprecated?
The difference comes from the way MVEL deals with these two different ways of accessing map entries.
#[flowVars['myVariable']] is equivalent to flowVars.get('myVariable'), which does not fail if the flowVars map does not contain the 'myVariable' entry,
#[flowVars.myVariable] treats the flowVars map as a virtual object, leading to an exception if the 'myVariable' entry is missing because in this case it doesn't resolve to a map get but instead to directly using an object member (either a field or a method), which must exist before being accessed.
I don't think #[flowVars['myVariable']] could be deprecated since it's a core feature provided by MVEL.
Reference: http://mvel.codehaus.org/MVEL+2.0+Property+Navigation#MVEL2.0PropertyNavigation-MapAccess
David has given a nice explanation around your question. To extend that explanation I would just like to add that you can use #[flowVars.?myVariable] to make your code null safe. This is equivalent to #[flowVars['myVariable']].
Regarding #[header:originalFilename], as David said this is not MEL. You can get a list of non-mel expressions which are commonly used in Mule applications in the following link.
http://www.mulesoft.org/documentation/display/current/Non-MEL+Expressions+Configuration+Reference
CA1303 Do not pass literals as localized parameters
Method BlankQuestionnaireViewModel.QuestionnaireNames.get() passes a literal string as parameter value of a call to SelectListItem.Text.set(string). Retrieve the following string(s) from a resource table instead: "Core Questionnaires:".
I am getting this warning when i run the code analysis. i can suppress this warning in global suppression class and apply attribute over the method to avoid the warning.
Now, here i dont want to use this method, where i need to add attribute in all the classes because i have many warning and i want to suppress this at application level somewhere in web.config or anywhere, where i change at one place and should affect at all places and warning get suppressed.
Is there any way to achieve this?
To ignore a warning globally:
Create a new rule set (File menu > New > File... > Code Analysis Rule Set)
Configure the new rule set to ignore the warning (CA1303 in your case).
Select the new rule set in the project properties Code Analysis tab.
If you want to fix this warning you can use below way to pass/get literals
private static string FunctionNameToString(string FunctionName)
{
switch (FunctionName)
{
case "CoreQ":
return "Core Questionnaires";
Probably a simple question, but I did not find anything in the documentation or on SO that directly answers it.
I had to work with the Ninject When(Func<IRequest, bool> condition) extension method for the first time, and got hung up for a bit with null object exceptions. I figured out that the IRequest.Target property is sometimes null and I've seen some other examples using When that check for a null Target as well.
I'm curious about the conditions under which Ninject executes the callback without having a value for Target. When creating a binding of the form
Bind<T1>()
.To<T2>
.When(r => SomeTest(r.Target));
I initially and erroneously assumed that there would always be a valid Target of type T1 when the binding was being executed.
It is null for the root object because there is no target in this case. (kernel.Get<MyCompositionRoot>())
Is there a way I can get a attribute set in ServletContext in EL so that it ends up as a JavaScript variable?
I am setting it as
context.setAttribute("testing.port", "9000");
I tried retrieving it like
alert("port" +'${testing.port}');
I am just getting a blank.
The problem is the period (.) in the key name. EL interprets the period as a call to an accessor method named getPort1 on whatever object testing references. Fetch the value from the appropriate implicit object:
${applicationScope['testing.port']}
or just use a different key:
${testingPort}
1Yes, this is a simplification of what really happens. It may also look for a predicate getter named isPort, or try Map#get("port").