Terraria
v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches
CountPropertyHelper.cs
Go to the documentation of this file.
1
using
System.Collections
;
2
using
System.Diagnostics.CodeAnalysis
;
3
using
System.Reflection
;
4
5
namespace
System.ComponentModel.DataAnnotations
;
6
7
internal
static
class
CountPropertyHelper
8
{
9
[RequiresUnreferencedCode(
"Uses reflection to get the 'Count' property on types that don't implement ICollection. This 'Count' property may be trimmed. Ensure it is preserved."
)]
10
public
static
bool
TryGetCount
(
object
value
, out
int
count
)
11
{
12
if
(
value
is
ICollection
collection
)
13
{
14
count
=
collection
.Count;
15
return
true
;
16
}
17
PropertyInfo
runtimeProperty =
value
.GetType().GetRuntimeProperty(
"Count"
);
18
if
(runtimeProperty !=
null
&& runtimeProperty.
CanRead
&& runtimeProperty.
PropertyType
== typeof(
int
))
19
{
20
count
= (int)runtimeProperty.
GetValue
(
value
);
21
return
true
;
22
}
23
count
= -1;
24
return
false
;
25
}
26
}
System.ComponentModel.DataAnnotations.CountPropertyHelper.TryGetCount
static bool TryGetCount(object value, out int count)
Definition
CountPropertyHelper.cs:10
System.ComponentModel.DataAnnotations.CountPropertyHelper
Definition
CountPropertyHelper.cs:8
System.Reflection.PropertyInfo.CanRead
bool CanRead
Definition
PropertyInfo.cs:17
System.Reflection.PropertyInfo.GetValue
object? GetValue(object? obj)
Definition
PropertyInfo.cs:60
System.Reflection.PropertyInfo.PropertyType
Type PropertyType
Definition
PropertyInfo.cs:11
System.Reflection.PropertyInfo
Definition
PropertyInfo.cs:8
System.Collections.ICollection
Definition
ICollection.cs:4
System.Collections
Definition
BlockingCollection.cs:8
System.ComponentModel.DataAnnotations
Definition
ColumnAttribute.cs:3
System.Diagnostics.CodeAnalysis
Definition
AllowNullAttribute.cs:1
System.Reflection
Definition
ICustomTypeProvider.cs:1
System.ExceptionArgument.value
@ value
System.ExceptionArgument.collection
@ collection
System.ExceptionArgument.count
@ count
source
System.ComponentModel.Annotations
System.ComponentModel.DataAnnotations
CountPropertyHelper.cs
Generated by
1.10.0