public static void AddMethodHandlersClass(ClassDefinition type, SourceCodeStringBuilder sb)
        {
            if (!type.HasWrapType(WrapTypes.NativeDirector))
            {
                throw new Exception("Unexpected");
            }

            if (type.IsNested)
            {
                sb.AppendIndent("public: ");
            }
            else
            {
                sb.AppendIndent("public ");
            }

            sb.Append("ref class " + type.Name + " abstract sealed\n");
            sb.AppendLine("{");
            sb.AppendLine("public:");
            sb.IncreaseIndent();

            foreach (MemberMethodDefinition f in type.PublicMethods)
            {
                if (f.IsDeclarableFunction && f.IsVirtual)
                {
                    //if (f.Parameters.Count > 0)
                    //{
                    //    AddEventArgsClass(f, sb);
                    //}

                    sb.AppendIndent("delegate static " + f.MemberTypeCLRName + " " + f.CLRName + "Handler(");
                    for (int i = 0; i < f.Parameters.Count; i++)
                    {
                        ParamDefinition param = f.Parameters[i];
                        sb.Append(" " + param.Type.GetCLRParamTypeName(param) + " " + param.Name);
                        if (i < f.Parameters.Count - 1)
                        {
                            sb.Append(",");
                        }
                    }
                    sb.Append(" );\n");
                }
            }

            sb.DecreaseIndent();
            sb.AppendLine("};");
            sb.AppendEmptyLine();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Generates the main part of the classes' code.
        /// </summary>
        protected virtual void GenerateCodeBody()
        {
            GenerateCodePreNestedTypes();
            _codeBuilder.AppendLine("//Nested Types");
            GenerateCodeAllNestedTypes();
            GenerateCodePostNestedTypes();

            _codeBuilder.AppendLine("//Private Declarations");
            GenerateCodePrivateDeclarations();
            _codeBuilder.AppendEmptyLine();

            _codeBuilder.AppendLine("//Internal Declarations");
            GenerateCodeInternalDeclarations();
            _codeBuilder.AppendEmptyLine();

            _codeBuilder.AppendLine("//Public Declarations");
            GenerateCodePublicDeclarations();
            _codeBuilder.AppendEmptyLine();

            _codeBuilder.AppendLine("//Protected Declarations");
            GenerateCodeProtectedDeclarations();
            _codeBuilder.AppendEmptyLine();
        }