@@ -8,88 +8,88 @@ This Source Code Form is subject to the terms of the Mozilla Public
8
8
using System . Reflection ;
9
9
using System . Text ;
10
10
11
- namespace PhpSerializerNET {
12
- internal static class ArrayExtensions {
11
+ namespace PhpSerializerNET ;
13
12
14
- public static string Utf8Substring ( this byte [ ] array , int start , int length , Encoding encoding ) {
15
- if ( length > array . Length - start ) {
16
- return "" ;
17
- }
13
+ internal static class ArrayExtensions {
18
14
19
- if ( encoding == Encoding . UTF8 ) {
20
- // Using the ReadonlySpan<> saves some copying:
21
- return Encoding . UTF8 . GetString ( new System . ReadOnlySpan < byte > ( array , start , length ) ) ;
22
- } else {
23
- // Sadly, Encoding.Convert does not accept a Span.
24
- byte [ ] substring = new byte [ length ] ;
25
- System . Buffer . BlockCopy ( array , start , substring , 0 , length ) ;
26
- return Encoding . UTF8 . GetString (
27
- Encoding . Convert ( encoding , Encoding . UTF8 , substring )
28
- ) ;
29
- }
15
+ public static string Utf8Substring ( this byte [ ] array , int start , int length , Encoding encoding ) {
16
+ if ( length > array . Length - start ) {
17
+ return "" ;
30
18
}
31
19
32
- public static Dictionary < object , PropertyInfo > GetAllProperties ( this PropertyInfo [ ] properties , PhpDeserializationOptions options ) {
33
- var result = new Dictionary < object , PropertyInfo > ( properties . Length ) ;
34
- foreach ( var property in properties ) {
35
- var isIgnored = false ;
36
- var attributes = PhpPropertyAttribute . GetCustomAttributes ( property , false ) ;
37
- PhpPropertyAttribute phpPropertyAttribute = null ;
38
- foreach ( var attribute in attributes ) {
39
- if ( attribute is PhpIgnoreAttribute ) {
40
- isIgnored = true ;
41
- break ;
42
- }
43
- if ( attribute is PhpPropertyAttribute foundAttribute ) {
44
- phpPropertyAttribute = foundAttribute ;
45
- }
46
- }
47
- if ( phpPropertyAttribute != null ) {
48
- if ( phpPropertyAttribute . IsInteger ) {
49
- result . Add ( phpPropertyAttribute . Key , isIgnored ? null : property ) ;
50
- } else {
51
- var attributeName = options . CaseSensitiveProperties
52
- ? phpPropertyAttribute . Name
53
- : phpPropertyAttribute . Name . ToLower ( ) ;
54
- result . Add ( attributeName , isIgnored ? null : property ) ;
55
- }
56
- }
57
- var propertyName = options . CaseSensitiveProperties
58
- ? property . Name
59
- : property . Name . ToLower ( ) ;
60
- result . Add ( propertyName , isIgnored ? null : property ) ;
61
- }
62
- return result ;
20
+ if ( encoding == Encoding . UTF8 ) {
21
+ // Using the ReadonlySpan<> saves some copying:
22
+ return Encoding . UTF8 . GetString ( new System . ReadOnlySpan < byte > ( array , start , length ) ) ;
23
+ } else {
24
+ // Sadly, Encoding.Convert does not accept a Span.
25
+ byte [ ] substring = new byte [ length ] ;
26
+ System . Buffer . BlockCopy ( array , start , substring , 0 , length ) ;
27
+ return Encoding . UTF8 . GetString (
28
+ Encoding . Convert ( encoding , Encoding . UTF8 , substring )
29
+ ) ;
63
30
}
31
+ }
64
32
65
- public static Dictionary < string , FieldInfo > GetAllFields ( this FieldInfo [ ] fields , PhpDeserializationOptions options ) {
66
- var result = new Dictionary < string , FieldInfo > ( fields . Length ) ;
67
- foreach ( var field in fields ) {
68
- var isIgnored = false ;
69
- var attributes = PhpPropertyAttribute . GetCustomAttributes ( field , false ) ;
70
- PhpPropertyAttribute phpPropertyAttribute = null ;
71
- foreach ( var attribute in attributes ) {
72
- if ( attribute is PhpIgnoreAttribute ) {
73
- isIgnored = true ;
74
- break ;
75
- }
76
- if ( attribute is PhpPropertyAttribute foundAttribute ) {
77
- phpPropertyAttribute = foundAttribute ;
78
- }
33
+ public static Dictionary < object , PropertyInfo > GetAllProperties ( this PropertyInfo [ ] properties , PhpDeserializationOptions options ) {
34
+ var result = new Dictionary < object , PropertyInfo > ( properties . Length ) ;
35
+ foreach ( var property in properties ) {
36
+ var isIgnored = false ;
37
+ var attributes = PhpPropertyAttribute . GetCustomAttributes ( property , false ) ;
38
+ PhpPropertyAttribute phpPropertyAttribute = null ;
39
+ foreach ( var attribute in attributes ) {
40
+ if ( attribute is PhpIgnoreAttribute ) {
41
+ isIgnored = true ;
42
+ break ;
79
43
}
80
- if ( phpPropertyAttribute != null ) {
44
+ if ( attribute is PhpPropertyAttribute foundAttribute ) {
45
+ phpPropertyAttribute = foundAttribute ;
46
+ }
47
+ }
48
+ if ( phpPropertyAttribute != null ) {
49
+ if ( phpPropertyAttribute . IsInteger ) {
50
+ result . Add ( phpPropertyAttribute . Key , isIgnored ? null : property ) ;
51
+ } else {
81
52
var attributeName = options . CaseSensitiveProperties
82
53
? phpPropertyAttribute . Name
83
54
: phpPropertyAttribute . Name . ToLower ( ) ;
84
- result . Add ( attributeName , isIgnored ? null : field ) ;
55
+ result . Add ( attributeName , isIgnored ? null : property ) ;
85
56
}
57
+ }
58
+ var propertyName = options . CaseSensitiveProperties
59
+ ? property . Name
60
+ : property . Name . ToLower ( ) ;
61
+ result . Add ( propertyName , isIgnored ? null : property ) ;
62
+ }
63
+ return result ;
64
+ }
86
65
87
- var fieldName = options . CaseSensitiveProperties
88
- ? field . Name
89
- : field . Name . ToLower ( ) ;
90
- result . Add ( fieldName , isIgnored ? null : field ) ;
66
+ public static Dictionary < string , FieldInfo > GetAllFields ( this FieldInfo [ ] fields , PhpDeserializationOptions options ) {
67
+ var result = new Dictionary < string , FieldInfo > ( fields . Length ) ;
68
+ foreach ( var field in fields ) {
69
+ var isIgnored = false ;
70
+ var attributes = PhpPropertyAttribute . GetCustomAttributes ( field , false ) ;
71
+ PhpPropertyAttribute phpPropertyAttribute = null ;
72
+ foreach ( var attribute in attributes ) {
73
+ if ( attribute is PhpIgnoreAttribute ) {
74
+ isIgnored = true ;
75
+ break ;
76
+ }
77
+ if ( attribute is PhpPropertyAttribute foundAttribute ) {
78
+ phpPropertyAttribute = foundAttribute ;
79
+ }
80
+ }
81
+ if ( phpPropertyAttribute != null ) {
82
+ var attributeName = options . CaseSensitiveProperties
83
+ ? phpPropertyAttribute . Name
84
+ : phpPropertyAttribute . Name . ToLower ( ) ;
85
+ result . Add ( attributeName , isIgnored ? null : field ) ;
91
86
}
92
- return result ;
87
+
88
+ var fieldName = options . CaseSensitiveProperties
89
+ ? field . Name
90
+ : field . Name . ToLower ( ) ;
91
+ result . Add ( fieldName , isIgnored ? null : field ) ;
93
92
}
93
+ return result ;
94
94
}
95
- }
95
+ }
0 commit comments