Take the 2-minute tour ×
Tridion Stack Exchange is a question and answer site for Tridion developers and administrators. It's 100% free, no registration required.

I have below two Criteria -

  1. Criteria searchCriteria = CriteriaFactory.And(ItemSchemaCriteria, PublicationCriteria);

  2. finalCriteria = CriteriaFactory.And(andCriteria);

here andCriteria is an array of some Keyword Criteria.

Now when I try to add these both criteria and assign it in another Criteria named myCriteria the as below:

myCriteria = searchCriteria.addCriteria(finalCriteria);

Below compilation error comes:

"Type mismatch: cannot convert from void to Criteria"

NOTE: As I debug and found that both searchCriteria and finalCriteria are not NULL.

Could somebody give me some pointers here to fix this error?

share|improve this question
2  
I suspect that addCriteria is a void method and it modifies your search criteria in place, hence you see that error when you try to assign the result of addCritera to your myCriteria variable. Can you post a more complete example of your code? –  NVanderEnde Dec 27 '13 at 11:25
    
Not sure if this is the right place for this question given that this is pretty much a pure programming problem and not necessarily related to Tridion (aside from the fact that Tridion libraries are being used). –  Ant P Dec 27 '13 at 12:12
add comment

1 Answer 1

up vote 9 down vote accepted

As hinted at by Nick, the Criteria.AddCriteria method doesn't return a Criteria object, so you can't assign it as you're trying to. What you probably want is something like this:

searchCriteria.AddCriteria(finalCriteria);
myCriteria = searchCriteria;

Note that if you do this, searchCriteria and myCriteria will be the same object instance, so changes to one will affect the other (until one of them is reassigned).

share|improve this answer
    
yes, Ant you are correct. Thanks to NVanderEnde also. –  user584 Dec 27 '13 at 12:16
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.