Ну, вы не действительно дали достаточно информации, но я укушу ... Предполагая, что все ваши таблицы / код следуют той же схеме, это довольно просто:
// You'll want to whitelist the tables, so you are not
// trusting user input for the table name
var tables = new List<String>() { "Source", ... };
foreach(var table in tables){
if (Context.Request.UrlReferrer.ToString().ToLower().Contains(table)){
AccessControlRule(
$"{table}ID",
"select {table}ID from {table} where IsDelete = 0",
AccessPermission.Allow
);
} else {
AccessControlRule(
$"{table}ID",
"select {table}ID from {table} where IsDelete = 1 OR IsDelete = null",
AccessPermission.Allow
);
}
}
НО - вы, вероятно, не хотите на самом деле настраивать что-либо вроде AccessRules или Security, используя значение Referrer, поскольку оно может быть тривиально подделано ... Вы не полагаетесь на этот код для какой-либо формы безопасности, не так ли?
Изменить, если ваши ключи разные, вы можете просто использовать карту имени таблицы -> имя ключа (через словарь, вероятно, проще всего) вместо списка:
// You'll want to whitelist the tables, so you are not
// trusting user input for the table name
var tables = new Dictionary<String, String>() {
{"Source", "SourceId" },
...
};
foreach(var table in tables){
if (Context.Request.UrlReferrer.ToString().ToLower().Contains(table.Key)){
AccessControlRule(
$"{table.Value}",
"select {table.Value} from {table.Key} where IsDelete = 0",
AccessPermission.Allow
);
} else {
AccessControlRule(
$"{table.Value}",
"select {table.Value} from {table.Key} where IsDelete = 1 OR IsDelete = null",
AccessPermission.Allow
);
}
}