@@ -19,8 +19,8 @@ internal struct IISConfigurationData
19
19
public string pwzBindings ;
20
20
public uint maxRequestBodySize ;
21
21
22
- [ CustomTypeMarshaller ( typeof ( IISConfigurationData ) , CustomTypeMarshallerKind . Value , Features = CustomTypeMarshallerFeatures . UnmanagedResources | CustomTypeMarshallerFeatures . TwoStageMarshalling ) ]
23
- public unsafe ref struct Marshaller
22
+ [ CustomMarshaller ( typeof ( IISConfigurationData ) , MarshalMode . Default , typeof ( Marshaller ) ) ]
23
+ public static class Marshaller
24
24
{
25
25
public struct Native
26
26
{
@@ -34,53 +34,49 @@ public struct Native
34
34
public uint maxRequestBodySize ;
35
35
}
36
36
37
- private Native _native ;
38
-
39
- public Marshaller ( IISConfigurationData managed )
37
+ public static Native ConvertToUnmanaged ( IISConfigurationData managed )
40
38
{
41
- _native . pNativeApplication = managed . pNativeApplication ;
42
- _native . pwzFullApplicationPath = managed . pwzFullApplicationPath is null ? IntPtr . Zero : Marshal . StringToBSTR ( managed . pwzFullApplicationPath ) ;
43
- _native . pwzVirtualApplicationPath = managed . pwzVirtualApplicationPath is null ? IntPtr . Zero : Marshal . StringToBSTR ( managed . pwzVirtualApplicationPath ) ;
44
- _native . fWindowsAuthEnabled = managed . fWindowsAuthEnabled ? 1 : 0 ;
45
- _native . fBasicAuthEnabled = managed . fBasicAuthEnabled ? 1 : 0 ;
46
- _native . fAnonymousAuthEnable = managed . fAnonymousAuthEnable ? 1 : 0 ;
47
- _native . pwzBindings = managed . pwzBindings is null ? IntPtr . Zero : Marshal . StringToBSTR ( managed . pwzBindings ) ;
48
- _native . maxRequestBodySize = managed . maxRequestBodySize ;
39
+ Native native ;
40
+ native . pNativeApplication = managed . pNativeApplication ;
41
+ native . pwzFullApplicationPath = managed . pwzFullApplicationPath is null ? IntPtr . Zero : Marshal . StringToBSTR ( managed . pwzFullApplicationPath ) ;
42
+ native . pwzVirtualApplicationPath = managed . pwzVirtualApplicationPath is null ? IntPtr . Zero : Marshal . StringToBSTR ( managed . pwzVirtualApplicationPath ) ;
43
+ native . fWindowsAuthEnabled = managed . fWindowsAuthEnabled ? 1 : 0 ;
44
+ native . fBasicAuthEnabled = managed . fBasicAuthEnabled ? 1 : 0 ;
45
+ native . fAnonymousAuthEnable = managed . fAnonymousAuthEnable ? 1 : 0 ;
46
+ native . pwzBindings = managed . pwzBindings is null ? IntPtr . Zero : Marshal . StringToBSTR ( managed . pwzBindings ) ;
47
+ native . maxRequestBodySize = managed . maxRequestBodySize ;
48
+ return native ;
49
49
}
50
50
51
- public Native ToNativeValue ( ) => _native ;
52
-
53
- public void FromNativeValue ( Native value ) => _native = value ;
54
-
55
- public IISConfigurationData ToManaged ( )
51
+ public static void Free ( Native native )
56
52
{
57
- return new ( )
53
+ if ( native . pwzFullApplicationPath != IntPtr . Zero )
58
54
{
59
- pNativeApplication = _native . pNativeApplication ,
60
- pwzFullApplicationPath = _native . pwzFullApplicationPath == IntPtr . Zero ? string . Empty : Marshal . PtrToStringBSTR ( _native . pwzFullApplicationPath ) ,
61
- pwzVirtualApplicationPath = _native . pwzVirtualApplicationPath == IntPtr . Zero ? string . Empty : Marshal . PtrToStringBSTR ( _native . pwzVirtualApplicationPath ) ,
62
- fWindowsAuthEnabled = _native . fWindowsAuthEnabled != 0 ,
63
- fBasicAuthEnabled = _native . fBasicAuthEnabled != 0 ,
64
- fAnonymousAuthEnable = _native . fAnonymousAuthEnable != 0 ,
65
- pwzBindings = _native . pwzBindings == IntPtr . Zero ? string . Empty : Marshal . PtrToStringBSTR ( _native . pwzBindings ) ,
66
- maxRequestBodySize = _native . maxRequestBodySize
67
- } ;
68
- }
69
-
70
- public void FreeNative ( )
71
- {
72
- if ( _native . pwzFullApplicationPath != IntPtr . Zero )
73
- {
74
- Marshal . FreeBSTR ( _native . pwzFullApplicationPath ) ;
55
+ Marshal . FreeBSTR ( native . pwzFullApplicationPath ) ;
75
56
}
76
- if ( _native . pwzVirtualApplicationPath != IntPtr . Zero )
57
+ if ( native . pwzVirtualApplicationPath != IntPtr . Zero )
77
58
{
78
- Marshal . FreeBSTR ( _native . pwzVirtualApplicationPath ) ;
59
+ Marshal . FreeBSTR ( native . pwzVirtualApplicationPath ) ;
79
60
}
80
- if ( _native . pwzBindings != IntPtr . Zero )
61
+ if ( native . pwzBindings != IntPtr . Zero )
81
62
{
82
- Marshal . FreeBSTR ( _native . pwzBindings ) ;
63
+ Marshal . FreeBSTR ( native . pwzBindings ) ;
83
64
}
84
65
}
66
+
67
+ public static IISConfigurationData ConvertToManaged ( Native native )
68
+ {
69
+ return new ( )
70
+ {
71
+ pNativeApplication = native . pNativeApplication ,
72
+ pwzFullApplicationPath = native . pwzFullApplicationPath == IntPtr . Zero ? string . Empty : Marshal . PtrToStringBSTR ( native . pwzFullApplicationPath ) ,
73
+ pwzVirtualApplicationPath = native . pwzVirtualApplicationPath == IntPtr . Zero ? string . Empty : Marshal . PtrToStringBSTR ( native . pwzVirtualApplicationPath ) ,
74
+ fWindowsAuthEnabled = native . fWindowsAuthEnabled != 0 ,
75
+ fBasicAuthEnabled = native . fBasicAuthEnabled != 0 ,
76
+ fAnonymousAuthEnable = native . fAnonymousAuthEnable != 0 ,
77
+ pwzBindings = native . pwzBindings == IntPtr . Zero ? string . Empty : Marshal . PtrToStringBSTR ( native . pwzBindings ) ,
78
+ maxRequestBodySize = native . maxRequestBodySize
79
+ } ;
80
+ }
85
81
}
86
82
}
0 commit comments