I have an application in which some sides i am using Filter conditions,,But i dont know the meaningof usage of word
“recursive” in that filter conditions
Here is a bit of code
// Indicates a recursive filter. Only valid for object type property filters.
private bool m_recursive = false;
------------------------
/// <summary>
/// Method to apply an object filter to an object.
/// </summary>
/// <param name="myObject">the object to which to apply the filter</param>
/// <returns>true if the object passes the filter, false otherwise</returns>
public bool Apply(DataModelObject myObject)
{
----------------------
/// Method to apply a property filter
/// </summary>
/// <param name="myObject">the object to which to apply the filter</param>
/// <param name="filteredType">type of the object to which to apply the filter</param>
/// <returns>true if the object passes the property filter, false otherwise</returns>
public bool Apply(DataModelObject myObject, Type filteredType)
{
switch( FilterType )
{
case enumFilterType.regularExpr:
switch( Operator )
{
case enumOperator.eq:
------------------------------------
case enumFilterType.strExpr:
switch( Operator )
{
case enumOperator.eq:
-------------------------------------
case enumFilterType.objectFilt:
do
{
retval = ((ObjectFilter)m_filterValue).Apply(propVal);
myObject = propVal;
if (m_recursive && retval == false && myObject != null)
{
propVal = (DataModelObject)prop.GetValue(myObject, null);
}
else
{
myObject = null;
}
} while (myObject != null);
}
if( m_operator == enumOperator.ne )
{
retval = !retval;
}
-----------------------
public object Clone()
{
clone.m_recursive = this.m_recursive;
return clone;
}
Can any one tell me why recursive false is using here
The important part of you code is this:
Basically, when the
FilterTypeisobjectFiltthen the code goes into ado...whileloop which is a loop of code that is always run at least once, because the recursing condition (in this case,myObject != null) is checked after the loop code has been executed once.If
m_recursiveis false thenretvalandmyObjectare ignored andmyObjectis set to null, so when the recursing condition is checked, it fails and the loop exits.If
m_recursiveis set to true, the settingmyObjectto null is determined by two things:myObjectbeing null andretvalbeing false.retvalis set bym_filterValue.Apply(propVal). It’s not clear where propVal comes from.In case you’re unaware of what recursion is, it is where a piece of code causes its self to be run again. In your code, this is represented by the
do...whileloop.