@@ -102,6 +102,7 @@ class JsonBaseType
102102 public int MaxSimultaneous ;
103103 public JsonMethod [ ] OverrideMethods ;
104104 public JsonProperty [ ] OverrideProperties ;
105+ public JsonEvent [ ] OverrideEvents ;
105106 }
106107
107108 [ Serializable ]
@@ -6821,6 +6822,115 @@ static void AppendBaseType(
68216822 }
68226823 }
68236824
6825+ // All abstract events
6826+ foreach ( EventInfo eventInfo in type . GetEvents ( ) )
6827+ {
6828+ MethodInfo addMethodInfo = eventInfo . GetAddMethod ( ) ;
6829+ MethodInfo removeMethodInfo = eventInfo . GetRemoveMethod ( ) ;
6830+ if ( ( addMethodInfo == null || ! addMethodInfo . IsAbstract ) &&
6831+ ( removeMethodInfo == null || ! removeMethodInfo . IsAbstract ) )
6832+ {
6833+ continue ;
6834+ }
6835+ AppendBaseTypeEvent (
6836+ type ,
6837+ typeName ,
6838+ cppTypeName ,
6839+ typeParams ,
6840+ eventInfo ,
6841+ addMethodInfo ,
6842+ removeMethodInfo ,
6843+ indent ,
6844+ builders ) ;
6845+ }
6846+
6847+ // All interface events
6848+ if ( type . IsInterface )
6849+ {
6850+ foreach ( Type interfaceType in type . GetInterfaces ( ) )
6851+ {
6852+ foreach ( EventInfo eventInfo in interfaceType . GetEvents ( ) )
6853+ {
6854+ MethodInfo addMethodInfo = eventInfo . GetAddMethod ( ) ;
6855+ MethodInfo removeMethodInfo = eventInfo . GetRemoveMethod ( ) ;
6856+ if ( ( addMethodInfo == null || ! addMethodInfo . IsAbstract ) &&
6857+ ( removeMethodInfo == null || ! removeMethodInfo . IsAbstract ) )
6858+ {
6859+ continue ;
6860+ }
6861+ AppendBaseTypeEvent (
6862+ type ,
6863+ typeName ,
6864+ cppTypeName ,
6865+ typeParams ,
6866+ eventInfo ,
6867+ addMethodInfo ,
6868+ removeMethodInfo ,
6869+ indent ,
6870+ builders ) ;
6871+ }
6872+ }
6873+ }
6874+
6875+ // Specified virtual events
6876+ if ( jsonBaseType . OverrideEvents != null )
6877+ {
6878+ EventInfo [ ] events = type . GetEvents ( ) ;
6879+ foreach ( JsonEvent jsonEvent in jsonBaseType . OverrideEvents )
6880+ {
6881+ EventInfo eventInfo = null ;
6882+ foreach ( EventInfo curEventInfo in events )
6883+ {
6884+ if ( curEventInfo . Name == jsonEvent . Name )
6885+ {
6886+ eventInfo = curEventInfo ;
6887+ break ;
6888+ }
6889+ }
6890+ if ( eventInfo == null )
6891+ {
6892+ // Throw an exception so the user knows what to fix in the JSON
6893+ StringBuilder errorBuilder = new StringBuilder ( 1024 ) ;
6894+ errorBuilder . Append ( "Event \" " ) ;
6895+ AppendCsharpTypeName (
6896+ type ,
6897+ errorBuilder ) ;
6898+ errorBuilder . Append ( '.' ) ;
6899+ errorBuilder . Append ( jsonEvent . Name ) ;
6900+ errorBuilder . Append ( ")\" not found" ) ;
6901+ throw new Exception ( errorBuilder . ToString ( ) ) ;
6902+ }
6903+
6904+ MethodInfo addMethodInfo = eventInfo . GetAddMethod ( ) ;
6905+ MethodInfo removeMethodInfo = eventInfo . GetRemoveMethod ( ) ;
6906+ if ( ( addMethodInfo == null || ! addMethodInfo . IsVirtual ) &&
6907+ ( removeMethodInfo == null || ! removeMethodInfo . IsVirtual ) )
6908+ {
6909+ // Throw an exception so the user knows what to fix in the JSON
6910+ StringBuilder errorBuilder = new StringBuilder ( 1024 ) ;
6911+ errorBuilder . Append ( "Event \" " ) ;
6912+ AppendCsharpTypeName (
6913+ type ,
6914+ errorBuilder ) ;
6915+ errorBuilder . Append ( '.' ) ;
6916+ errorBuilder . Append ( jsonEvent . Name ) ;
6917+ errorBuilder . Append (
6918+ ")\" doesn't have either a virtual 'add' or 'remove' to override" ) ;
6919+ throw new Exception ( errorBuilder . ToString ( ) ) ;
6920+ }
6921+ AppendBaseTypeEvent (
6922+ type ,
6923+ typeName ,
6924+ cppTypeName ,
6925+ typeParams ,
6926+ eventInfo ,
6927+ addMethodInfo ,
6928+ removeMethodInfo ,
6929+ indent ,
6930+ builders ) ;
6931+ }
6932+ }
6933+
68246934 // C# class (ending)
68256935 builders . CsharpBaseTypes . Append ( "\t \t }\n " ) ;
68266936 builders . CsharpBaseTypes . Append ( "\t \t \n " ) ;
@@ -6929,14 +7039,18 @@ static void AppendBaseTypeProperty(
69297039 builders . CsharpBaseTypes . Append ( '\n ' ) ;
69307040 builders . CsharpBaseTypes . Append ( "\t \t \t {\n " ) ;
69317041
7042+ TypeKind propertyTypeKind = GetTypeKind (
7043+ propertyInfo . PropertyType ) ;
7044+
69327045 if ( getMethodInfo != null && getMethodInfo . IsVirtual )
69337046 {
6934- AppendBaseTypeNativeProperty (
7047+ AppendBaseTypeNativePropertyOrEvent (
69357048 type ,
69367049 typeName ,
69377050 typeParams ,
69387051 cppTypeName ,
6939- propertyInfo ,
7052+ propertyInfo . Name ,
7053+ propertyTypeKind ,
69407054 getMethodInfo ,
69417055 "Get" ,
69427056 isOverride ,
@@ -6946,12 +7060,13 @@ static void AppendBaseTypeProperty(
69467060
69477061 if ( setMethodInfo != null && setMethodInfo . IsVirtual )
69487062 {
6949- AppendBaseTypeNativeProperty (
7063+ AppendBaseTypeNativePropertyOrEvent (
69507064 type ,
69517065 typeName ,
69527066 typeParams ,
69537067 cppTypeName ,
6954- propertyInfo ,
7068+ propertyInfo . Name ,
7069+ propertyTypeKind ,
69557070 setMethodInfo ,
69567071 "Set" ,
69577072 isOverride ,
@@ -6963,12 +7078,79 @@ static void AppendBaseTypeProperty(
69637078 builders . CsharpBaseTypes . Append ( "\t \t \t \n " ) ;
69647079 }
69657080
6966- static void AppendBaseTypeNativeProperty (
7081+ static void AppendBaseTypeEvent (
7082+ Type type ,
7083+ string typeName ,
7084+ string cppTypeName ,
7085+ Type [ ] typeParams ,
7086+ EventInfo eventInfo ,
7087+ MethodInfo addMethodInfo ,
7088+ MethodInfo removeMethodInfo ,
7089+ int indent ,
7090+ StringBuilders builders )
7091+ {
7092+ bool isOverride = IsNonDelegateClass ( type ) ;
7093+
7094+ builders . CsharpBaseTypes . Append ( "\t \t \t public " ) ;
7095+ if ( isOverride )
7096+ {
7097+ builders . CsharpBaseTypes . Append ( "override " ) ;
7098+ }
7099+ builders . CsharpBaseTypes . Append ( "event " ) ;
7100+ AppendCsharpTypeName (
7101+ eventInfo . EventHandlerType ,
7102+ builders . CsharpBaseTypes ) ;
7103+ builders . CsharpBaseTypes . Append ( ' ' ) ;
7104+ builders . CsharpBaseTypes . Append ( eventInfo . Name ) ;
7105+ builders . CsharpBaseTypes . Append ( '\n ' ) ;
7106+ builders . CsharpBaseTypes . Append ( "\t \t \t {\n " ) ;
7107+
7108+ TypeKind eventHandlerTypeKind = GetTypeKind (
7109+ eventInfo . EventHandlerType ) ;
7110+
7111+ if ( addMethodInfo != null && addMethodInfo . IsVirtual )
7112+ {
7113+ AppendBaseTypeNativePropertyOrEvent (
7114+ type ,
7115+ typeName ,
7116+ typeParams ,
7117+ cppTypeName ,
7118+ eventInfo . Name ,
7119+ eventHandlerTypeKind ,
7120+ addMethodInfo ,
7121+ "Add" ,
7122+ isOverride ,
7123+ indent ,
7124+ builders ) ;
7125+ }
7126+
7127+ if ( removeMethodInfo != null && removeMethodInfo . IsVirtual )
7128+ {
7129+ AppendBaseTypeNativePropertyOrEvent (
7130+ type ,
7131+ typeName ,
7132+ typeParams ,
7133+ cppTypeName ,
7134+ eventInfo . Name ,
7135+ eventHandlerTypeKind ,
7136+ removeMethodInfo ,
7137+ "Remove" ,
7138+ isOverride ,
7139+ indent ,
7140+ builders ) ;
7141+ }
7142+
7143+ builders . CsharpBaseTypes . Append ( "\t \t \t }\n " ) ;
7144+ builders . CsharpBaseTypes . Append ( "\t \t \t \n " ) ;
7145+ }
7146+
7147+ static void AppendBaseTypeNativePropertyOrEvent (
69677148 Type type ,
69687149 string typeName ,
69697150 Type [ ] typeParams ,
69707151 string cppTypeName ,
6971- PropertyInfo propertyInfo ,
7152+ string propertyOrEventName ,
7153+ TypeKind propertyOrEventTypeKind ,
69727154 MethodInfo methodInfo ,
69737155 string operationType ,
69747156 bool isOverride ,
@@ -6977,7 +7159,7 @@ static void AppendBaseTypeNativeProperty(
69777159 {
69787160 builders . TempStrBuilder . Length = 0 ;
69797161 builders . TempStrBuilder . Append ( operationType ) ;
6980- builders . TempStrBuilder . Append ( propertyInfo . Name ) ;
7162+ builders . TempStrBuilder . Append ( propertyOrEventName ) ;
69817163 string funcName = builders . TempStrBuilder . ToString ( ) ;
69827164
69837165 AppendCsharpGetDelegateCall (
@@ -7012,8 +7194,6 @@ static void AppendBaseTypeNativeProperty(
70127194 // C# method that calls the C++ binding function
70137195 ParameterInfo [ ] invokeParamsWithThis = PrependThisParameter (
70147196 invokeParams ) ;
7015- TypeKind invokeReturnTypeKind = GetTypeKind (
7016- propertyInfo . PropertyType ) ;
70177197 builders . CsharpBaseTypes . Append ( "\t \t \t \t " ) ;
70187198 builders . CsharpBaseTypes . Append ( char . ToLower ( operationType [ 0 ] ) ) ;
70197199 builders . CsharpBaseTypes . Append (
@@ -7026,7 +7206,7 @@ static void AppendBaseTypeNativeProperty(
70267206 methodInfo ,
70277207 nativeInvokeFuncName ,
70287208 invokeParamsWithThis ,
7029- invokeReturnTypeKind ,
7209+ propertyOrEventTypeKind ,
70307210 5 ,
70317211 builders . CsharpBaseTypes ) ;
70327212 builders . CsharpBaseTypes . Append ( "\t \t \t \t }\n " ) ;
0 commit comments