             templatePrefix = className
         }
         let templateName = templatePrefix + "T"
-        let typeName = isNullable ? (templateName + "?") : templateName
-        return typeName
-    }
-
-    /// return the swift (known) type of the receiver when passed as an argument
-    /// Returns a reference name in case of a known record with a default value
-    @inlinable
-    var defaultRefTemplateTypeName: String {
-        guard let record = knownRecordReference else {
-            return argumentTypeName
-        }
-        let templateName: String
-        if allowNone {
-            let refName = record.structName
-            templateName = record.typeRef.type.prefixedWhereNecessary(refName)
-        } else {
-            let className = record.className
-            let prefix = typeRef.type.dottedPrefix
-            let normalisedPrefix = prefix.asNormalisedPrefix
-            let templatePrefix: String
-            if GIR.dottedPrefix != prefix && GIR.dottedPrefix != normalisedPrefix {
-                templatePrefix = typeRef.type.namespace + className.capitalised
-            } else {
-                templatePrefix = className
-            }
-            templateName = templatePrefix + "T"
-        }
-        let typeName = isNullable ? (templateName + "?") : templateName
+        return templateName
+    }
+
+    /// Append a question mark if the receiver is nullable
+    /// - Parameter templateName: The string to optionally turn into an optional
+    /// - Returns: The original string, with or without a `?` appended
+    @inlinable func optionalIfNullableOrOptional(_ typeName: String) -> String {
+        let typeName = isNullable || isOptional ? (typeName + "?") : typeName
         return typeName
     }
 }

    }

    /// return the swift (known) type of the receiver when passed as an argument
    /// for a `@convention(c)` callback
    @inlinable
    var callbackArgumentTypeName: String {

        guard let record = knownRecordReference else {
            return argumentTypeName
        }
        let typeName = optionalIfNullableOrOptional(templateName(for: record))
        return typeName
    }

    /// return the swift (known) type of the receiver when passed as an argument
    /// Returns a reference name in case of a known record with a default value
    @inlinable
    var defaultRefTemplateTypeName: String {
        guard let record = knownRecordReference else {
            return argumentTypeName
        }
        let templateName: String
        if allowNone {
            templateName = record.structNamePrefixedIfNecessary
        } else {
            templateName = self.templateName(for: record)
        }
        let typeName = optionalIfNullableOrOptional(templateName)
        return typeName
    }

    /// Return the name of a templated type correspondingg to a given record
    /// - Note this gets prefixed if the record is in a different namespace
    /// - Parameter record: A record for which to create a template name
    /// - Returns: A string representing a template type for the given record
    @inlinable
    func templateName(for record: GIR.Record) -> String {
        let className = record.className
        let prefix = typeRef.type.dottedPrefix
        let normalisedPrefix = prefix.asNormalisedPrefix
