Databases Reference
In-Depth Information
LISTING 13.1
Continued
while (currentType != null)
{
yield return currentType.FullName;
yield return currentType.Name;
if (currentType == typeof(int))
yield return “Integer”;
if (currentType == typeof(string))
yield return “Text”;
if (!FallbackTypes.TryGetValue(currentType, out currentType))
break;
}
}
}
}
The
GetFilterCandidates
method mimics the algorithm implemented by the built-in
FieldTemplateFactory
for
field
templates. It first returns the UI hint specified in page
markup, then the UI hint specified in
FilterUIHintAttribute
that might be applied to
the property in the entity model, and the type name specified in the
DataTypeAttribute
.
If a matching template has not been found, the
GetFilterCandidates
method begins a
fallback loop, where it tries the full name of the property type (such as
System.Int32
), its
short name (such as
Int32
), and alias (such as Integer, if any) and continues the process
with the next type.
The fallback rules are defined in a static dictionary called
FallbackTypes
declared in the
beginning of the class. Looking at the initialization code, you can tell that for a property
of type
Int16
(
short
in C#), the fallback type is
Int32
(
int
in C#), and for
Int32
, the fall-
back type is
String
. Take the
UnitsInStock
property of the Product entity as an example.
This property is of type
Int16
and, in absence of the
FilterUIHintAttribute
and
DataTypeAttribute
, the
UnleashedFilterFactory
tries the sequence of filter template
names shown in Table 13.1 until it finds a matching file in the Filters directory.
TABLE 13.1
Example of Filter Template Lookup for Int16 Column
Iteration 1
Iteration 2
Iteration 3
System.Int16.ascx
System.Int32.ascx
System.String.ascx
Int16.ascx
Int32.ascx
String.ascx
Integer.ascx
Text.ascx
The diagram in Figure 13.2 summarizes the filter lookup algorithm implemented by the
UnleashedFilterFactory
. Similar to the lookup rules for field templates discussed in
Chapter 3, this algorithm assumes that all primitive data types have corresponding filter
templates. The Text filter template created in Chapter 5, “Filter Templates,” is similar to
the Text field template in how it can handle all of the primitive data types; however,
that limits it to performing only a simple equality check, leaving out other, more useful