@@ -3048,8 +3048,8 @@ private StructDeclarationSyntax DeclareTypeDefBOOLStruct(TypeDefinition typeDef)
30483048 MemberAccessExpressionSyntax fieldAccessExpression = MemberAccessExpression ( SyntaxKind . SimpleMemberAccessExpression , ThisExpression ( ) , IdentifierName ( "value" ) ) ;
30493049
30503050 // Add property accessor
3051- members = members . Add ( PropertyDeclaration ( PredefinedType ( Token ( SyntaxKind . BoolKeyword ) ) , "Value" )
3052- . WithExpressionBody ( ArrowExpressionClause ( BinaryExpression ( SyntaxKind . NotEqualsExpression , fieldAccessExpression , LiteralExpression ( SyntaxKind . NumericLiteralExpression , Literal ( 0 ) ) ) ) ) . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) )
3051+ members = members . Add ( PropertyDeclaration ( PredefinedType ( Token ( SyntaxKind . IntKeyword ) ) , "Value" )
3052+ . WithExpressionBody ( ArrowExpressionClause ( fieldAccessExpression ) ) . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) )
30533053 . AddModifiers ( Token ( this . Visibility ) ) ) ;
30543054
30553055 // BOOL(bool value) => this.value = value ? 1 : 0;
@@ -3061,10 +3061,17 @@ private StructDeclarationSyntax DeclareTypeDefBOOLStruct(TypeDefinition typeDef)
30613061 . WithExpressionBody ( ArrowExpressionClause ( AssignmentExpression ( SyntaxKind . SimpleAssignmentExpression , fieldAccessExpression , boolToInt ) ) )
30623062 . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ) ;
30633063
3064- // public static implicit operator bool(BOOL value) => value.Value;
3064+ // BOOL(int value) => this.value = value;
3065+ members = members . Add ( ConstructorDeclaration ( name . Identifier )
3066+ . AddModifiers ( Token ( this . Visibility ) )
3067+ . AddParameterListParameters ( Parameter ( valueParameter . Identifier ) . WithType ( PredefinedType ( Token ( SyntaxKind . IntKeyword ) ) ) )
3068+ . WithExpressionBody ( ArrowExpressionClause ( AssignmentExpression ( SyntaxKind . SimpleAssignmentExpression , fieldAccessExpression , valueParameter ) ) )
3069+ . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ) ;
3070+
3071+ // public static implicit operator bool(BOOL value) => value.value != 0 ? true : false;
30653072 members = members . Add ( ConversionOperatorDeclaration ( Token ( SyntaxKind . ImplicitKeyword ) , PredefinedType ( Token ( SyntaxKind . BoolKeyword ) ) )
30663073 . AddParameterListParameters ( Parameter ( valueParameter . Identifier ) . WithType ( name ) )
3067- . WithExpressionBody ( ArrowExpressionClause ( MemberAccessExpression ( SyntaxKind . SimpleMemberAccessExpression , valueParameter , IdentifierName ( fieldName ) ) ) )
3074+ . WithExpressionBody ( ArrowExpressionClause ( BinaryExpression ( SyntaxKind . NotEqualsExpression , MemberAccessExpression ( SyntaxKind . SimpleMemberAccessExpression , valueParameter , IdentifierName ( fieldName ) ) , LiteralExpression ( SyntaxKind . NumericLiteralExpression , Literal ( 0 ) ) ) ) )
30683075 . AddModifiers ( Token ( SyntaxKind . PublicKeyword ) , Token ( SyntaxKind . StaticKeyword ) ) // operators MUST be public
30693076 . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ) ;
30703077
@@ -3075,6 +3082,13 @@ private StructDeclarationSyntax DeclareTypeDefBOOLStruct(TypeDefinition typeDef)
30753082 . AddModifiers ( Token ( SyntaxKind . PublicKeyword ) , Token ( SyntaxKind . StaticKeyword ) ) // operators MUST be public
30763083 . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ) ;
30773084
3085+ // public static explicit operator BOOL(int value) => new BOOL(value);
3086+ members = members . Add ( ConversionOperatorDeclaration ( Token ( SyntaxKind . ExplicitKeyword ) , name )
3087+ . AddParameterListParameters ( Parameter ( valueParameter . Identifier ) . WithType ( PredefinedType ( Token ( SyntaxKind . IntKeyword ) ) ) )
3088+ . WithExpressionBody ( ArrowExpressionClause ( ObjectCreationExpression ( name ) . AddArgumentListArguments ( Argument ( valueParameter ) ) ) )
3089+ . AddModifiers ( Token ( SyntaxKind . PublicKeyword ) , Token ( SyntaxKind . StaticKeyword ) ) // operators MUST be public
3090+ . WithSemicolonToken ( Token ( SyntaxKind . SemicolonToken ) ) ) ;
3091+
30783092 StructDeclarationSyntax result = StructDeclaration ( name . Identifier )
30793093 . WithMembers ( members )
30803094 . WithModifiers ( TokenList ( Token ( this . Visibility ) , Token ( SyntaxKind . ReadOnlyKeyword ) , Token ( SyntaxKind . PartialKeyword ) ) ) ;
0 commit comments