I have strange question but i hope someone can help me i have this vb.Net Code
For Each navigation In navigations
If obj.GetType().GetProperty(navigation.Name) IsNot Nothing Then
Dim childs = obj.GetType().GetProperty(navigation.Name)
Dim childValues = childs.GetValue(obj, Nothing)
If childValues Is Nothing Then
Continue For
End If
For Each item In childValues
If item Is Nothing Then
Continue For
End If
SetValues(item, entityState)
Next
End If
Next
childValues values is object but i know it's a list of navigation properties.
and i can do thi in vb.net
For Each item In childValues
' Do Stuff
Next
sometimes childValues is Entity collection of TEntity and sometimes it's FixupCollection. but in both scenario the above code works well.
now i want to change this code to c# and i don't know how can i do that
can please someone explain to me how vb works and how can i do this in c#?
To start off, you can replace the ifs with a .Where filter
navigations.Where(n => n.GetType.GetProperty(n.Name) != null) // nothing?
Then "convert" each Navigation into its children:
.Select(n => obj.GetType().GetProperty(navigation.Name))
.Select(n => childs.GetValue(obj, null)) // nothing?
Then replace the if with another .Where filter:
.Where(chVals => chVals != null) // nothing?
before iterating over them
.ForEach(chVals =>
chVals.Where(item => item != nothing) // Not sure what nothing means in VB...
.ForEach(item => SetValues(item, entityState))
);
Related
I am writing Cypress tests for an application that has a dynamic group/list of items. Each item has a details link that when clicked creates a popup with said details. I need to close that popup and move to the next item in the group.
I first tried to use the .each() command on the group and then would .click({multiple:true}) the details but the popup would cover the the next click. Adding {foce:true} does allow all of the popups to display but I don't think that is in the spirit of how the application should function.
My latest attempt has been to create a custom command using .next() to iterate through the group. This works but when .next() reaches the end of the group it yields "" and so the test ultimately fails.
The actual error I get is:
Expected to find element: ``, but never found it. Queried from element: <div.groups.ng-star-inserted>
the .spec.ts
describe('Can select incentives and view details', () => {
it('Views incentive details', () => {
cy.optionPop('section#Incentives div.groups:first')
})
})
the index.ts
Cypress.Commands.add('optionPop', (clickable) => {
cy.get(clickable).find('[ng-reflect-track="Estimator, open_selection_dial"]').click()
cy.get('mat-dialog-container i.close').click()
cy.get(clickable).next().as('clicked').then(($clicked) => {
//fails at .next ^ because '' is yielded at end of list
cy.wrap($clicked).should('not.eq','')
})
cy.optionPop('#clicked')
})
You basically have the right idea, but it might work better in a plain JS function rather than a custom command.
function openPopups(clickables) {
if (clickables.length === 0) return // exit when array is empty
const clickable = clickables.pop() // extract one and reduce array
cy.wrap(clickable)
.find('[ng-reflect-track="Estimator, open_selection_dial"]').click()
cy.get('mat-dialog-container i.close')
.should('be.visible') // in case popup is slow
.click()
// wait for this popup to go, then proceed to next
cy.get('mat-dialog-container')
.should('not.be.visible')
.then(() => {
openPopups(clickables) // clickables now has one less item
})
}
cy.get('section#Incentives div.groups') // get all the popups
.then($popups => {
const popupsArray = Array.from($popups) // convert jQuery result to array
openPopups(popupsArray)
})
Some extra notes:
Using Array.from($popups) because we don't know how many in the list, and want to use array.pop() to grab each item and at the same time reduce the array (it's length will control the loop exit).
clickables is a list of raw elements, so cy.wrap(clickable) makes the individual element usable with Cypress commands like .find()
.should('be.visible') - when dealing with popup, the DOM is often altered by the click event that opens it, which can be slow relative to the speed the test runs at. Adding .should('be.visible') is a guard to make sure the test is not flaky on some runs (e.g if using CI)
.should('not.be.visible').then(() => ... - since you have some problems with multiple overlapping popups this will ensure each popup has gone before testing the next one.
Hello? I'm building an app using the flutter provider pattern. And I created a process to query the values inside the object. I also have data in my model dart file.
Check the code below.
List<Device> _devices = [
Device(one: 'apple', two: 'iphone'),
Device(one: 'samsung', two: 'galaxy')
];
String Query(String value) {
return _media.where((medium) => medium.one == value)
.map((medium) => (medium.two)).toString();
Query("apple")
So, when I call that function, I expect iphone to be returned. But the results come in (iphne). Actually I know why. After all, the data returned is a List<Device> type. But what I want is to remove the parentheses by returning only the first value in the queried list(meaning only queried list, not the full list). In other words, I want to receive iphone, not (iphone). Currently, I am using substring removing the first and the final word, which seems to have some limitations. Is there any way to remove parentheses in that logic?
You have parentheses because you're calling .toString() on a list:
return _media.where((medium) => medium.one == value)
.map((medium) => (medium.two))
.toString();
To return just .two or the first found object, you just have to do:
return _media.firstWhere(
(medium) => medium.one == value, orElse: () => null)?.two;
That will return the value of .two of the first found object or null if nothing found.
Doc: Iterable.firstWhere()
I struggle to find a solution for what is probably pretty simple, and despite I crawl a lot of questions, I can't manage to make it work.
Here are 2 HTML elements:
Test1
Test2
I want to get ONLY the content of the 1st element's href property (#content1). It must match because the html element contains no "onclick" property.
This regex works for matching the 1st element only:
^<a href="#"((?!onclick).)*$
but I can't figure out how to get the HREF content.
I've tried this:
^<a href="#(.*)"((?!onclick).)*$
but in this case, both elements are matching.
Thanks for your help !
I strongly suggest that you should do that in two steps. For one thing, parsing arbitrary html with a regexp is a notoriously slippery and winding road. For the other: there is no achievement in doing everything with one illegible regex.
And there's more to it: "contains no "onclick" attribute" is not the same as "href attribute is not directly followed by onclick attribute". So, a one-regex-solution would be either very complicated or very fragile (html tags have arbitrary attributes order).
var a = [
'Test1',
'Test2'
];
console.log(
a.filter(i => i.match(/onclick/i) == null)
.map(i => i.match(/href="([^"]+)"/i)[1]
)
This assumes that your href attribute values are valid and do not contain quotes (which is, of course, technically possible).
Regex is not made for this. JavaScript would work better. This code will store an array of the hrefs matching your requirements in the variable hrefArray.
var hrefArray = [];
for (var elem of document.getElementsByTagName('a')) {
if (elem.onclick) hrefArray.push(elem.href)
}
An example with your HTML is in the snippet below:
var hrefArray = [];
for (var elem of document.getElementsByTagName('a')) {
if (elem.onclick) hrefArray.push(elem.href)
}
console.log(hrefArray);
body {
background-color: gray;
}
Test1
Test2
similiar problem has already been mentioned, described and solved here using dynamic actions but I still can't implement it in my case.
I have a form (created authomatically but page creator) to change password in remote database. There are three items
login : P15_UNAME (select list) LOV
new password: P15_NEW (password)
button to execute: SUBMIT (button).
Button fires a simple stored procedure:
declare
success int;
msg varchar(100);
begin
SYS.CHANGEPASSWORD#abc(
PUSERNAME => :P15_UNAME,
PNEWPASSWORD => :P15_NEW,
PRESULT => success,
PMESSAGE => msg);
if success = 0 then
apex_application.g_print_success_message := msg;
else
apex_application.g_print_success_message := '<span style="color:red">' || msg || '</span>';
end if ;
end ;
Unfortunately choosen/typed values of login and password are not called by stored procedure. I probably should use dynamic action but have no idea how to call store procedure and dynamic simultaneously. Could you give me some hints please.
K.
Are you trying to pass the page item values directly into the database? Your procedure / procedure call should look something like this.
-- database
PROCEDURE p_change_details(p_uname varchar2, p_password varchar2)
IS
success int;
msg varchar(100);
begin
SYS.CHANGEPASSWORD#abc(
PUSERNAME => p_uname,
PNEWPASSWORD => p_password,
PRESULT => success,
PMESSAGE => msg);
if success = 0 then
apex_application.g_print_success_message := msg;
else
apex_application.g_print_success_message := '<span style="color:red">' || msg || '</span>';
end if ;
end ;
--APEX
p_change_details(:P15_UNAME, :P15_NEW)
You can create a Dynamic Action to execute a PL/SQL code on button click.
refer this example- Link
Hope this will help you. Let me know for any question.
I am using CakePHP to develop a website and currently struggling with cookie.
The problem is that when I write cookie with multiple dots,like,
$this->Cookie->write("Figure.1.id",$figureId);
$this->Cookie->write("Figure.1.name",$figureName);`
and then read, cakePHP doesn't return nested array but it returns,
array(
'1.id' => '82',
'1.name' => '1'
)
I expected something like
array(
(int) 1 => array(
'id'=>'82',
'name'=>'1'
)
)
Actually I didn't see the result for the first time when I read after I write them. But from second time, result was like that. Do you know what is going on?
I'm afraid it doesn't look as if multiple dots are supported. If you look at the read() method of the CookieComponent (http://api.cakephp.org/2.4/source-class-CookieComponent.html#256-289), you see this:
277: if (strpos($key, '.') !== false) {
278: $names = explode('.', $key, 2);
279: $key = $names[0];
280: }
and that explode() method is being told to explode the name of your cookie into a maximum of two parts around the dot.
You might be best serializing the data you want to store before saving and then deserializing after reading as shown here: http://abakalidis.blogspot.co.uk/2011/11/cakephp-storing-multi-dimentional.html