@ -154,16 +154,11 @@ namespace CppSharp.Generators.CLI
WriteCloseBraceIndent ( ) ;
WriteCloseBraceIndent ( ) ;
PopBlock ( NewLineKind . BeforeNextBlock ) ;
PopBlock ( NewLineKind . BeforeNextBlock ) ;
}
}
foreach ( var field in @class . Fields )
{
if ( ASTUtils . CheckIgnoreField ( @class , field ) )
continue ;
GenerateFieldProperty ( field ) ;
}
}
}
foreach ( var property in @class . Properties )
GenerateProperty ( property ) ;
foreach ( var @event in @class . Events )
foreach ( var @event in @class . Events )
{
{
if ( @event . Ignore )
if ( @event . Ignore )
@ -239,82 +234,119 @@ namespace CppSharp.Generators.CLI
printer . Context = oldCtx ;
printer . Context = oldCtx ;
}
}
private void GenerateField Property ( Field field )
private void GenerateProperty ( Property property )
{
{
var @class = field . Class ;
if ( property . Ignore ) return ;
PushBlock ( CLIBlockKind . Property ) ;
var @class = property . Namespace as Class ;
GeneratePropertyGetter ( field , @class ) ;
if ( property . Field ! = null )
GeneratePropertySetter ( field , @class ) ;
{
GeneratePropertyGetter ( property . Field , @class , property . Name , property . Type ) ;
GeneratePropertySetter ( property . Field , @class , property . Name , property . Type ) ;
}
else
{
GeneratePropertyGetter ( property . GetMethod , @class , property . Name , property . Type ) ;
GeneratePropertySetter ( property . SetMethod , @class , property . Name , property . Type ) ;
}
PopBlock ( ) ;
}
}
private void GeneratePropertySetter < T > ( T decl , Class @class )
private void GeneratePropertySetter < T > ( T decl , Class @class , string name , Type type )
where T : Declaration , ITypedDecl
where T : Declaration , ITypedDecl
{
{
if ( decl = = null )
return ;
WriteLine ( "void {0}::{1}::set({2} value)" , QualifiedIdentifier ( @class ) ,
WriteLine ( "void {0}::{1}::set({2} value)" , QualifiedIdentifier ( @class ) ,
decl . Name , decl . Type ) ;
n ame, t ype) ;
WriteStartBraceIndent ( ) ;
WriteStartBraceIndent ( ) ;
var param = new Parameter
if ( decl is Function )
{
{
Name = "value" ,
var func = decl as Function ;
QualifiedType = decl . QualifiedType
if ( func . Parameters [ 0 ] . Name ! = "value" )
} ;
WriteLine ( "auto {0} = value;" , func . Parameters [ 0 ] . Name ) ;
GenerateFunctionCall ( func , @class ) ;
}
else
{
var param = new Parameter
{
Name = "value" ,
QualifiedType = decl . QualifiedType
} ;
var ctx = new MarshalContext ( Driver )
var ctx = new MarshalContext ( Driver )
{
{
Parameter = param ,
Parameter = param ,
ArgName = param . Name ,
ArgName = param . Name ,
} ;
} ;
var marshal = new CLIMarshalManagedToNativePrinter ( ctx ) ;
var marshal = new CLIMarshalManagedToNativePrinter ( ctx ) ;
param . Visit ( marshal ) ;
param . Visit ( marshal ) ;
string variable ;
string variable ;
if ( decl is Variable )
if ( decl is Variable )
variable = string . Format ( "::{0}::{1}" ,
variable = string . Format ( "::{0}::{1}" ,
@class . QualifiedOriginalName , decl . OriginalName ) ;
@class . QualifiedOriginalName , decl . OriginalName ) ;
else
else
variable = string . Format ( "((::{0}*)NativePtr)->{1}" ,
variable = string . Format ( "((::{0}*)NativePtr)->{1}" ,
@class . QualifiedOriginalName , decl . OriginalName ) ;
@class . QualifiedOriginalName , decl . OriginalName ) ;
if ( ! string . IsNullOrWhiteSpace ( marshal . Context . SupportBefore ) )
if ( ! string . IsNullOrWhiteSpace ( marshal . Context . SupportBefore ) )
Write ( marshal . Context . SupportBefore ) ;
Write ( marshal . Context . SupportBefore ) ;
WriteLine ( "{0} = {1};" , variable , marshal . Context . Return ) ;
WriteLine ( "{0} = {1};" , variable , marshal . Context . Return ) ;
}
WriteCloseBraceIndent ( ) ;
WriteCloseBraceIndent ( ) ;
NewLine ( ) ;
NewLine ( ) ;
}
}
private void GeneratePropertyGetter < T > ( T decl , Class @class )
private void GeneratePropertyGetter < T > ( T decl , Class @class , string name , Type type )
where T : Declaration , ITypedDecl
where T : Declaration , ITypedDecl
{
{
WriteLine ( "{0} {1}::{2}::get()" , decl . Type , QualifiedIdentifier ( @class ) ,
if ( decl = = null )
decl . Name ) ;
return ;
WriteLine ( "{0} {1}::{2}::get()" , type , QualifiedIdentifier ( @class ) ,
name ) ;
WriteStartBraceIndent ( ) ;
WriteStartBraceIndent ( ) ;
string variable ;
if ( decl is Function )
if ( decl is Variable )
{
variable = string . Format ( "::{0}::{1}" ,
var func = decl as Function ;
@class . QualifiedOriginalName , decl . OriginalName ) ;
GenerateFunctionCall ( func , @class ) ;
}
else
else
variable = string . Format ( "((::{0}*)NativePtr)->{1}" ,
{
string variable ;
if ( decl is Variable )
variable = string . Format ( "::{0}::{1}" ,
@class . QualifiedOriginalName , decl . OriginalName ) ;
@class . QualifiedOriginalName , decl . OriginalName ) ;
else
variable = string . Format ( "((::{0}*)NativePtr)->{1}" ,
@class . QualifiedOriginalName , decl . OriginalName ) ;
var ctx = new MarshalContext ( Driver )
var ctx = new MarshalContext ( Driver )
{
{
ArgName = decl . Name ,
ArgName = decl . Name ,
ReturnVarName = variable ,
ReturnVarName = variable ,
ReturnType = decl . QualifiedType
ReturnType = decl . QualifiedType
} ;
} ;
var marshal = new CLIMarshalNativeToManagedPrinter ( ctx ) ;
var marshal = new CLIMarshalNativeToManagedPrinter ( ctx ) ;
decl . Visit ( marshal ) ;
decl . Visit ( marshal ) ;
if ( ! string . IsNullOrWhiteSpace ( marshal . Context . SupportBefore ) )
if ( ! string . IsNullOrWhiteSpace ( marshal . Context . SupportBefore ) )
Write ( marshal . Context . SupportBefore ) ;
Write ( marshal . Context . SupportBefore ) ;
WriteLine ( "return {0};" , marshal . Context . Return ) ;
WriteLine ( "return {0};" , marshal . Context . Return ) ;
}
WriteCloseBraceIndent ( ) ;
WriteCloseBraceIndent ( ) ;
NewLine ( ) ;
NewLine ( ) ;
@ -428,10 +460,10 @@ namespace CppSharp.Generators.CLI
private void GenerateVariable ( Variable variable , Class @class )
private void GenerateVariable ( Variable variable , Class @class )
{
{
GeneratePropertyGetter ( variable , @class ) ;
GeneratePropertyGetter ( variable , @class , variable . Name , variable . Type ) ;
if ( ! variable . QualifiedType . Qualifiers . IsConst )
if ( ! variable . QualifiedType . Qualifiers . IsConst )
GeneratePropertySetter ( variable , @class ) ;
GeneratePropertySetter ( variable , @class , variable . Name , variable . Type ) ;
}
}
private void GenerateClassConstructor ( Class @class , bool isIntPtr )
private void GenerateClassConstructor ( Class @class , bool isIntPtr )