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 app开发者_如何学编程ly 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:
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);
Basically, when the FilterType
is objectFilt
then the code goes into a do...while
loop 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_recursive
is false then retval
and myObject
are ignored and myObject
is set to null, so when the recursing condition is checked, it fails and the loop exits.
If m_recursive
is set to true, the setting myObject
to null is determined by two things: myObject
being null and retval
being false.
retval
is set by m_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...while
loop.
精彩评论