Skip to content

Commit 3641d65

Browse files
committed
Refactor getPropertyAsFloat and getPropertyAsInteger
DEVSIX-1381 Autoported commit. Original commit hash: [5dd5975]
1 parent 9127760 commit 3641d65

File tree

3 files changed

+20
-38
lines changed

3 files changed

+20
-38
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
3+
namespace iText.IO.Util {
4+
public static class NumberUtil {
5+
6+
public static float? AsFloat(Object obj) {
7+
return obj != null ? Convert.ToSingle(obj) : (float?)null;
8+
}
9+
10+
public static int? AsInteger(Object obj) {
11+
return obj != null ? Convert.ToInt32(obj) : (int?)null;
12+
}
13+
14+
}
15+
}

itext/itext.layout/itext/layout/renderer/AbstractRendererExtensions.cs

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ source product.
4242
4343
*/
4444
using System;
45+
using iText.IO.Util;
4546
using iText.Layout.Properties;
4647

4748
namespace iText.Layout.Renderer
@@ -64,18 +65,7 @@ public static class AbstractRendererExtensions
6465
public static float? GetPropertyAsFloat(this AbstractRenderer renderer, int property)
6566
{
6667
Object value = renderer.GetProperty<Object>(property);
67-
return (value is sbyte
68-
|| value is byte
69-
|| value is short
70-
|| value is ushort
71-
|| value is int
72-
|| value is uint
73-
|| value is long
74-
|| value is ulong
75-
|| value is float
76-
|| value is double
77-
|| value is decimal)
78-
? Convert.ToSingle(value) : (float?)null;
68+
return NumberUtil.AsFloat(value);
7969
}
8070

8171
/// <summary>Returns a property with a certain key, as a floating point value.</summary>
@@ -90,20 +80,8 @@ public static class AbstractRendererExtensions
9080
/// </returns>
9181
public static float? GetPropertyAsFloat(this AbstractRenderer renderer, int property, float? defaultValue)
9282
{
93-
9483
Object value = renderer.GetProperty<Object>(property, defaultValue);
95-
return (value is sbyte
96-
|| value is byte
97-
|| value is short
98-
|| value is ushort
99-
|| value is int
100-
|| value is uint
101-
|| value is long
102-
|| value is ulong
103-
|| value is float
104-
|| value is double
105-
|| value is decimal)
106-
? Convert.ToSingle(value) : (float?)null;
84+
return NumberUtil.AsFloat(value);
10785
}
10886

10987
/// <summary>Returns a property with a certain key, as an integer value.</summary>
@@ -118,18 +96,7 @@ public static class AbstractRendererExtensions
11896
public static int? GetPropertyAsInteger(this AbstractRenderer renderer, int property)
11997
{
12098
Object value = renderer.GetProperty<Object>(property);
121-
return (value is sbyte
122-
|| value is byte
123-
|| value is short
124-
|| value is ushort
125-
|| value is int
126-
|| value is uint
127-
|| value is long
128-
|| value is ulong
129-
|| value is float
130-
|| value is double
131-
|| value is decimal)
132-
? Convert.ToInt32(value) : (int?)null;
99+
return NumberUtil.AsInteger(value);
133100
}
134101
}
135102
}

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5e52d4dc121eaca3d41608c7bcf4b4901475fc5f
1+
5dd5975d1c4283469936e66f6a972037927f79ba

0 commit comments

Comments
 (0)