public void GenerateClass(Class @class) { if (@class.Ignore || @class.IsIncomplete) { return; } GenerateDeclarationCommon(@class); if (GenerateClassProlog(@class)) { return; } // Process the nested types. PushIndent(); GenerateDeclContext(@class); PopIndent(); var nativeType = string.Format("::{0}*", @class.QualifiedOriginalName); if (CSharpTextTemplate.ShouldGenerateClassNativeField(@class)) { GenerateClassNativeField(@class, nativeType); } GenerateClassConstructors(@class, nativeType); GenerateClassProperties(@class); GenerateClassEvents(@class); GenerateClassMethods(@class); if (Options.GenerateFunctionTemplates) { GenerateClassGenericMethods(@class); } GenerateClassVariables(@class); if (@class.Fields.Any()) { PushBlock(CLIBlockKind.AccessSpecifier); WriteLine("private:"); PopBlock(NewLineKind.IfNotEmpty); PushBlock(CLIBlockKind.Fields); GenerateClassFields(@class); PopBlock(); } WriteLine("};"); }
private void GenerateClassFinalizer(Class @class) { PushBlock(CLIBlockKind.Finalizer); WriteLine("{0}::!{1}()", QualifiedIdentifier(@class), @class.Name); WriteStartBraceIndent(); if (CSharpTextTemplate.ShouldGenerateClassNativeField(@class)) { WriteLine("delete NativePtr;"); } WriteCloseBraceIndent(); PopBlock(NewLineKind.BeforeNextBlock); }
public void GenerateClass(Class @class) { PushBlock(CLIBlockKind.Class); GenerateDeclContext(@class); // Output a default constructor that takes the native pointer. GenerateClassConstructor(@class, isIntPtr: false); GenerateClassConstructor(@class, isIntPtr: true); if (@class.IsRefType) { GenerateClassDestructor(@class); GenerateClassFinalizer(@class); } foreach (var method in @class.Methods) { if (ASTUtils.CheckIgnoreMethod(method)) { continue; } GenerateMethod(method, @class); } if (CSharpTextTemplate.ShouldGenerateClassNativeField(@class)) { PushBlock(CLIBlockKind.Method); WriteLine("System::IntPtr {0}::{1}::get()", QualifiedIdentifier(@class), Helpers.InstanceIdentifier); WriteStartBraceIndent(); WriteLine("return System::IntPtr(NativePtr);"); WriteCloseBraceIndent(); PopBlock(NewLineKind.BeforeNextBlock); PushBlock(CLIBlockKind.Method); WriteLine("void {0}::{1}::set(System::IntPtr object)", QualifiedIdentifier(@class), Helpers.InstanceIdentifier); WriteStartBraceIndent(); var nativeType = string.Format("::{0}*", @class.QualifiedOriginalName); WriteLine("NativePtr = ({0})object.ToPointer();", nativeType); WriteCloseBraceIndent(); PopBlock(NewLineKind.BeforeNextBlock); } GenerateClassProperties(@class, @class); foreach (var @event in @class.Events) { if (@event.Ignore) { continue; } GenerateDeclarationCommon(@event); GenerateEvent(@event, @class); } foreach (var variable in @class.Variables) { if (variable.Ignore) { continue; } if (variable.Access != AccessSpecifier.Public) { continue; } GenerateDeclarationCommon(variable); GenerateVariable(variable, @class); } PopBlock(); }
public void GenerateClass(Class @class) { PushBlock(CLIBlockKind.Class); GenerateDeclContext(@class); GenerateClassConstructors(@class); foreach (var method in @class.Methods) { if (ASTUtils.CheckIgnoreMethod(method, Options)) { continue; } // C++/CLI does not allow special member funtions for value types. if (@class.IsValueType && method.IsCopyConstructor) { continue; } GenerateMethod(method, @class); } if (CSharpTextTemplate.ShouldGenerateClassNativeField(@class)) { PushBlock(CLIBlockKind.Method); WriteLine("System::IntPtr {0}::{1}::get()", QualifiedIdentifier(@class), Helpers.InstanceIdentifier); WriteStartBraceIndent(); WriteLine("return System::IntPtr(NativePtr);"); WriteCloseBraceIndent(); PopBlock(NewLineKind.BeforeNextBlock); PushBlock(CLIBlockKind.Method); WriteLine("void {0}::{1}::set(System::IntPtr object)", QualifiedIdentifier(@class), Helpers.InstanceIdentifier); WriteStartBraceIndent(); var nativeType = string.Format("::{0}*", @class.QualifiedOriginalName); WriteLine("NativePtr = ({0})object.ToPointer();", nativeType); WriteCloseBraceIndent(); PopBlock(NewLineKind.BeforeNextBlock); } GenerateClassProperties(@class, @class); foreach (var @event in @class.Events) { if ([email protected]) { continue; } GenerateDeclarationCommon(@event); GenerateEvent(@event, @class); } foreach (var variable in @class.Variables) { if (!variable.IsGenerated) { continue; } if (variable.Access != AccessSpecifier.Public) { continue; } GenerateDeclarationCommon(variable); GenerateVariable(variable, @class); } PopBlock(); }