private void GenerateWrapperMethods(NodeJSTypeReference classToWrapTypeReference, string classNameWrap, NodeJSTypeReferenceCollector typeReferenceCollector) { // Find class to wrap Class classToWrap = classToWrapTypeReference.Declaration as Class; // Loop over all public methods foreach (string methodName in methodsProcessed) { PushBlock(BlockKind.Method); WriteLine("NAN_METHOD({0}::{1})", classNameWrap, methodName); WriteStartBraceIndent(); // Generate class object wrap string classNameNorm = NamingHelper.GenerateTrimmedClassName(classToWrap.Name); string classNameWrapper = NamingHelper.GenerateWrapperClassName(classToWrap.Name); string classNameNormLower = classNameNorm.Substring(0, 1).ToLower() + classNameNorm.Substring(1); PushBlock(BlockKind.MethodBody); WriteLine("{0}* {1} = ObjectWrap::Unwrap<{0}>(info.This());", classNameWrap, classNameWrapper); WriteLine("{0}* {1} = {2}->GetWrapped();", classToWrap.Name, classNameNormLower, classNameWrapper); PopBlock(NewLineKind.BeforeNextBlock); // Find overloaded methods IEnumerable <Method> overloadMethods = classToWrap.Methods .Where(s => s.Name == methodName) .OrderByDescending(s => s.Parameters.Count); bool firstMethodCreated = false; foreach (Method overloadMethod in overloadMethods) { // Generate other constructors than default string generatedIfStatement = (firstMethodCreated ? "else " : string.Empty); generatedIfStatement += "if " + nodeJSTypeCheckPrinter.GenerateCheckStatement(overloadMethod.Parameters); // Output arguments checker PushBlock(BlockKind.MethodBody); WriteLine(generatedIfStatement); WriteStartBraceIndent(); // Generate wrapper for parameter arguments string generatedArgumentsWrapped = nodeJSTypePrinter.GenerateParameterWrapper(this, overloadMethod.Parameters); if (!string.IsNullOrEmpty(generatedArgumentsWrapped)) { WriteLine(""); } // Call wrapped method WriteLine("// Call wrapped method"); nodeJSTypePrinter.GenerateReturnTypeWrapper(this, overloadMethod.ReturnType, string.Format("{0}->{1}({2})", classNameNormLower, overloadMethod.Name, generatedArgumentsWrapped)); WriteCloseBraceIndent(); PopBlock(NewLineKind.Never); // Remember that we have created an method firstMethodCreated = true; } WriteCloseBraceIndent(); PopBlock(NewLineKind.BeforeNextBlock); } }