| |||||||||||||||||
Source File | Conditionals | Statements | Methods | TOTAL | |||||||||||||
Configuration\Sql\Dynamic\Handlers\IsEmptyTagHandler.cs | 62.5 % | 75.0 % | 100.0 % | 71.4 % |
|
1 | ||
2 | #region Apache Notice | |
3 | /***************************************************************************** | |
4 | * $Header: $ | |
5 | * $Revision: $ | |
6 | * $Date: $ | |
7 | * | |
8 | * iBATIS.NET Data Mapper | |
9 | * Copyright (C) 2004 - Gilles Bayon | |
10 | * | |
11 | * | |
12 | * Licensed under the Apache License, Version 2.0 (the "License"); | |
13 | * you may not use this file except in compliance with the License. | |
14 | * You may obtain a copy of the License at | |
15 | * | |
16 | * http://www.apache.org/licenses/LICENSE-2.0 | |
17 | * | |
18 | * Unless required by applicable law or agreed to in writing, software | |
19 | * distributed under the License is distributed on an "AS IS" BASIS, | |
20 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
21 | * See the License for the specific language governing permissions and | |
22 | * limitations under the License. | |
23 | * | |
24 | ********************************************************************************/ | |
25 | #endregion | |
26 | ||
27 | #region Imports | |
28 | using System; | |
29 | using System.Collections; | |
30 | ||
31 | using IBatisNet.DataMapper.Configuration.Sql.Dynamic.Elements; | |
32 | using IBatisNet.Common.Utilities.Objects; | |
33 | #endregion | |
34 | ||
35 | ||
36 | namespace IBatisNet.DataMapper.Configuration.Sql.Dynamic.Handlers | |
37 | { | |
38 | /// <summary> | |
39 | /// IsEmptyTagHandler represent a isEmpty tag element in a dynamic mapped statement. | |
40 | /// </summary> | |
41 | public class IsEmptyTagHandler : ConditionalTagHandler | |
42 | { | |
43 | ||
44 | #region Methods | |
45 | /// <summary> | |
46 | /// | |
47 | /// </summary> | |
48 | /// <param name="ctx"></param> | |
49 | /// <param name="tag"></param> | |
50 | /// <param name="parameterObject"></param> | |
51 | /// <returns></returns> | |
52 | 43 | public override bool IsCondition(SqlTagContext ctx, SqlTag tag, object parameterObject) |
53 | { | |
54 | 43 | if (parameterObject == null) |
55 | { | |
56 | 0 | return true; |
57 | } | |
58 | else | |
59 | { | |
60 | 43 | string propertyName = ((BaseTag)tag).Property; |
61 | 43 | object value = null; |
62 | 43 | if (propertyName != null && propertyName.Length>0) |
63 | { | |
64 | 41 | value = ObjectProbe.GetPropertyValue(parameterObject, propertyName); |
65 | } | |
66 | else | |
67 | { | |
68 | 2 | value = parameterObject; |
69 | } | |
70 | 43 | if (value is ICollection) |
71 | { | |
72 | 0 | return ((value == null) || (((ICollection) value).Count< 1)); |
73 | } | |
74 | 43 | else if (value != null && typeof(Array).IsAssignableFrom(value.GetType())) //value.GetType().IsArray |
75 | { | |
76 | 0 | return ((Array) value).GetLength(0) == 0; |
77 | } | |
78 | else | |
79 | { | |
80 | 43 | return ((value == null) || (System.Convert.ToString(value).Equals(""))); |
81 | } | |
82 | } | |
83 | } | |
84 | #endregion | |
85 | ||
86 | } | |
87 | } | |
88 |
|