@@ -256,61 +256,65 @@ public string FormatTypeUsedIn (string? usedInNamespace, Type? type)
256256
257257 public string ? RenderType ( Type t , ICustomAttributeProvider ? provider = null )
258258 {
259+ var nullable = string . Empty ;
260+ if ( provider is not null && ! t . IsValueType && AttributeManager . HasAttribute < NullAllowedAttribute > ( provider ) )
261+ nullable = "?" ;
262+
259263 if ( ! t . IsEnum ) {
260264 switch ( Type . GetTypeCode ( t ) ) {
261265 case TypeCode . Char :
262- return "char" ;
266+ return "char" + nullable ;
263267 case TypeCode . String :
264- return "string" ;
268+ return "string" + nullable ;
265269 case TypeCode . Int32 :
266- return "int" ;
270+ return "int" + nullable ;
267271 case TypeCode . UInt32 :
268- return "uint" ;
272+ return "uint" + nullable ;
269273 case TypeCode . Int64 :
270- return "long" ;
274+ return "long" + nullable ;
271275 case TypeCode . UInt64 :
272- return "ulong" ;
276+ return "ulong" + nullable ;
273277 case TypeCode . Single :
274- return "float" ;
278+ return "float" + nullable ;
275279 case TypeCode . Double :
276- return "double" ;
280+ return "double" + nullable ;
277281 case TypeCode . Decimal :
278- return "decimal" ;
282+ return "decimal" + nullable ;
279283 case TypeCode . SByte :
280- return "sbyte" ;
284+ return "sbyte" + nullable ;
281285 case TypeCode . Byte :
282- return "byte" ;
286+ return "byte" + nullable ;
283287 case TypeCode . Boolean :
284- return "bool" ;
288+ return "bool" + nullable ;
285289 }
286290 }
287291
288292 if ( t == TypeCache . System_Void )
289293 return "void" ;
290294
291295 if ( t == TypeCache . System_IntPtr ) {
292- return AttributeManager . HasNativeAttribute ( provider ) ? "nint" : "IntPtr" ;
296+ return ( AttributeManager . HasNativeAttribute ( provider ) ? "nint" : "IntPtr" ) + nullable ;
293297 } else if ( t == TypeCache . System_UIntPtr ) {
294- return AttributeManager . HasNativeAttribute ( provider ) ? "nuint" : "UIntPtr" ;
298+ return ( AttributeManager . HasNativeAttribute ( provider ) ? "nuint" : "UIntPtr" ) + nullable ;
295299 }
296300
297301 if ( t . Namespace is not null ) {
298302 string ns = t . Namespace ;
299303 if ( NamespaceCache . ImplicitNamespaces . Contains ( ns ) || t . IsGenericType ) {
300304 var targs = t . GetGenericArguments ( ) ;
301305 if ( targs . Length == 0 )
302- return t . Name ;
303- return $ "global::{ t . Namespace } ." + t . Name . RemoveArity ( ) + "<" + string . Join ( ", " , targs . Select ( l => FormatTypeUsedIn ( null , l ) ) . ToArray ( ) ) + ">" ;
306+ return t . Name + nullable ;
307+ return $ "global::{ t . Namespace } ." + t . Name . RemoveArity ( ) + "<" + string . Join ( ", " , targs . Select ( l => FormatTypeUsedIn ( null , l ) ) . ToArray ( ) ) + ">" + nullable ;
304308 }
305309 if ( NamespaceCache . NamespacesThatConflictWithTypes . Contains ( ns ) )
306- return "global::" + t . FullName ;
310+ return "global::" + t . FullName + nullable ;
307311 if ( t . Name == t . Namespace )
308- return "global::" + t . FullName ;
312+ return "global::" + t . FullName + nullable ;
309313 else
310- return t . FullName ;
314+ return t . FullName + nullable ;
311315 }
312316
313- return t . FullName ;
317+ return t . FullName + nullable ;
314318 }
315319
316320 // TODO: If we ever have an API with nested properties of the same name more than
0 commit comments