user3097695
user3097695

Reputation: 1274

How to add attribute with if else C#

I have options to use both SQL Server and PostgresSQL databases. In some classes, I have the following attribute

[DatabaseGenerated(DatabaseGeneratedOption.Computed)]

used to decorate to class properties:

public class MyClass 
{
    #if define PostgresSQL
    [DatabaseGenerated(DatabaseGeneratedOption.Computed)]
    #endif
    public DateTime SysStartTime { get; set; }
}

I have this appsettings.json file:

{
    "Database": {
       "DatabaseType": "PostgresSQL"
    }
}

How do I associate the value in appsettings.json to the value in #if define directive?

Upvotes: 0

Views: 102

Answers (0)

Related Questions