public static string GetNullableAnnotationTypeName(this ITypeModel typeModel, FlatBufferSchemaType context) { var typeName = typeModel.GetCompilableTypeName(); if (typeModel.ClassifyContextually(context).IsOptionalReference()) { typeName += "?"; } return(typeName); }
/// <summary> /// Indicates if the given type model is a nullable reference in the given context. /// </summary> /// <param name="typeModel">The type model.</param> /// <param name="context">The context (ie, table, struct, vector, etc)</param> public static ContextualTypeModelClassification ClassifyContextually(this ITypeModel typeModel, FlatBufferSchemaType context) { var flags = ContextualTypeModelClassification.Undefined; if (typeModel.ClrType.IsValueType) { flags |= ContextualTypeModelClassification.ValueType; if (Nullable.GetUnderlyingType(typeModel.ClrType) == null) { flags |= ContextualTypeModelClassification.Required; } else { flags |= ContextualTypeModelClassification.Optional; } } else { flags |= ContextualTypeModelClassification.ReferenceType; if (context == FlatBufferSchemaType.Table) { flags |= ContextualTypeModelClassification.Optional; } else { flags |= ContextualTypeModelClassification.Required; } } return(flags); }
public static string GetNullableAnnotationTypeName(this ItemMemberModel memberModel, FlatBufferSchemaType context) { var typeName = memberModel.ItemTypeModel.GetCompilableTypeName(); if (memberModel.ItemTypeModel.ClassifyContextually(context).IsOptionalReference() && !memberModel.IsRequired) { typeName += "?"; } return(typeName); }