I am trying to get the value from
IKeyValuePair<Platform::Guid,Platform:: Object>
Say for example I have Api Called SomeApi() which returns IKeyValuePair<Platform::Guid,Platform:: Object>
C++ Code:
auto res = SomeApi();
String ^str = res->key; // I am able to get Guid Here
Now How to get Value from it
res->value returns object but how to know type of object and get the value from it.
if I do
String^ value = res->value.ToString(); // this returns something else not value
Please explain me through code how can i get value from IKeyValuePair.
You should cast from Platform::Object^ to the underlying type, eg:
String^ value = safe_cast<String^>(res->value);
String^ value = res->value->ToString();
Related
#Test
public void testTotalMarks(){
Mark gMark = fakeMarkGenerator.createMarks();
DBMark dbMark = markMapper.toDBMark(gMark);
when(repoLayer.findMarksByStudentId()).thenReturn(Optional.of(dbMark));
markService.createMarks(gMark); //Actually createMarks method return type is DBMark.
//But this code works fine.
//Shouldn't this be DBMark dbMark2 = markService.createMarks(gMark); ??
verify(mockMarkMapper, times(2)).toTotal(any(Total.class)); //I don't understand times here
Assert statement
}
I don't understand times here
Times indicates the number of invocations you're expecting for the method you're verifying.
Shouldn't this be DBMark dbMark2 = markService.createMarks(gMark); ??
If you're trying to assert a value returning from a method you're testing, then yes, you should assign it to a variable and assert your value. Ex:
assertThat(dbMarks.size, <maybe your matcher here>)
Below is the theJson string which I have converted to object by JSON.parse
var clientScopeJson={"cl1":{"List":"rwe","urlList":["nclsdlc","alkdcjla"]}};
JSON.hasOwnProperty(id) returns as true but JSON.id gives undefined:
id = "cl1"
//scope = JSON.parse(clientScopeJson);
console.log(clientScopeJson);
clientId = "cl1";
exists = clientScopeJson.hasOwnProperty(clientId); // This returns as true
console.log(exists);
scopeList = clientScopeJson.clientId;
console.log(scopeList);
If you want to access key that is saved in variable, you can access it like this
const clientId = "cl1";
const scopeList = clientScopeJson[clientId];
If you try to use it with dot, you are trying to access 'clientId' key.
Can anyone help me with making an Exception. I want to catch an error when a user Inputs an non numeric value in an array. After it catches the error i would like to ask the user to retry and give their input again, this time being an integer.
Assuming JAVA,
All you have to do is get the I put as a string, then convert the string to integer by Integer.parseInt().
If the parseInt doesn't throw NumberFormatException, user entered a numeric input, add that to the array, if not, get an input again
If you need to do this in a simple application in order to test your Exception-handling skills, here is a sample code that fills an array with integers and expects int as input. When given another value, the code prompts the user to try again.
int[] array = new int[10];
Scanner sc = new Scanner(System.in);
boolean shouldAskAgain = true;
int index = 0;
do{
System.out.println("Enter an integer value for the array");
try{
array[index] = sc.nextInt();
index++;
if(index == array.length-1)
shouldAskAgain = false;
}
catch(InputMismatchException e) {
System.out.println("Wrong input. Try again");
sc.nextLine();
}
}while(shouldAskAgain);
I'm using the Jackson Object Mapper (com.fasterxml.jackson.databind.ObjectMapper) to parse a json string and need to count the number of times the word "path"
occures in the string. The string looks like:
"rows":[{"path":{"uid":"2"},"fields":[]},{"path":{"uid":"4"},"fields":[]},{"path":{"uid":"12"},....
Does anyone know which API option is most efficeint for achieving this?
To count total number of 'childs' inside the 'rows' root, you can use a code like this:
String inputJsonString = "{\"rows\":[{\"path\":{\"uid\":\"2\"},\"fields\":[]},{\"path\":{\"uid\":\"4\"},\"fields\":[]},{\"path\":{\"uid\":\"12\"},\"fields\":[]}]}";
ObjectNode root = (ObjectNode) new ObjectMapper().readTree( inputJsonString );
root.get( "rows" ).size();
If you need to get the exact count of 'path' occurrences, you may use the code like this:
int counter = 0;
for( Iterator<JsonNode> i = root.get( "rows" ).iterator(); i.hasNext(); )
if( i.next().has( "path" ) )
counter++;
System.out.println(counter);
I have a table called Subjects,
I have an another Table called Allocations, which stores the Allocations of the Subjects
I have a Datagridview, which is populated with Subject Allocations from the Allocations Table
Now i need to get the Subjects that are not in the Datagridview
To do this
I Get All Subjects from the ObjectContext
Now i get all the Subjects that are alloted from the Datagridview (It Returns me an InMemory Collection)
Now i use the LINQ.EXCEPT method to filter the results, but it is throwing me the Following Exception,
"Unable To Create Constant Value of Type "ObjectContext.Subjects" Only primitive types ('such as Int32, String, and Guid') are supported in this context."
Below is my Code
public static IOrderedQueryable<Subject> GetSubjects()
{
return OBJECTCONTEXT.Subjects.OrderBy(s => s.Name);
}
private IQueryable<Subject> GetAllocatedSubjectsFromGrid()
{
return (from DataGridViewRow setRow in dgv.Rows
where !setRow.IsNewRow
select setRow.DataBoundItem).Cast<Allocation>() //I know the Problem lies somewhere in this Function
.Select(alloc =>alloc.Subject).AsQueryable();
}
private void RUN()
{
IQueryable<Subject> AllSubjects = GetSubjects(); //Gets
IQueryable<Subject> SubjectsToExclude = GetAllocatedSubjectsFromGrid();
IQueryable<Subject> ExcludedSubjects = AllSubjects.Except(SubjectsToExclude.AsEnumerable());
//Throwing Me "Unable to create a constant value of type 'OBJECTCONTEXT.Subject'. Only primitive types ('such as Int32, String, and Guid') are supported in this context."
}
As a result of googling i found that it happens because LINQ can't compare between InMemory collection(Records from DGV) and Objectcontext(FromDB)
A little short of time, have not tested it. But I guess you can try to get it all in memory. So instead of using
IQueryable<Subject> AllSubjects = GetSubjects(); //Gets
You do
List<Subject> AllSubjects = GetSubjects().ToList(); //
List<Subject> SubjectsToExclude = GetAllocatedSubjectsFromGrid().ToList();
List<Subject> ExcludedSubjects = AllSubjects.Except(SubjectsToExclude);
I got around this by comparing keys in a Where clause rather than using Except.
So instead of:
var SubjectsToExclude = GetAllocatedSubjectsFromGrid();
var ExcludedSubjects = AllSubjects.Except(SubjectsToExclude.AsEnumerable());
Something more like:
var subjectsToExcludeKeys =
GetAllocatedSubjectsFromGrid()
.Select(subject => subject.ID);
var excludedSubjects =
AllSubjects
.Where(subject => !subjectsToExcludeKeys.Contains(subject.ID));
(I'm guessing what your entity's key looks like though.)
This allows you to keep everything in Entity Framework, rather than pulling everything into memory.