Exemple #1
0
        private void TriggerCctor(TypeDesc type)
        {
            // TODO: Before field init

            MethodDesc cctor = type.GetStaticConstructor();
            if (cctor == null)
                return;

            // TODO: Thread safety

            string ctorHasRun = "__statics.__cctor_" + _writer.GetCppTypeName(type).Replace("::", "__");
            AppendLine();
            Append("if (!" + ctorHasRun + ") {");
            Indent();
            AppendLine();
            Append(ctorHasRun + " = true;");
            AppendLine();
            Append(_writer.GetCppTypeName(cctor.OwningType));
            Append("::");
            Append(_writer.GetCppMethodName(cctor));
            Append("();");
            Exdent();
            AppendLine();
            Append("}");

            AddMethodReference(cctor);
        }