Exemplo n.º 1
0
        protected virtual string GetNativeDirectorName(ClassDefinition type)
        {
            if (!type.HasWrapType(WrapTypes.NativeDirector))
            {
                throw new Exception("Unexpected");
            }

            string name = (type.IsNested) ? type.SurroundingClass.Name + "_" + type.Name : type.Name;

            return(name + "_Director");
        }
        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();
        }