CSharp · Console
using System;
using System.Collections.Generic;
using System.Linq;
public class Program
{
public static void Main()
{
Program p = new Program();
p.AddOrUpdate<User>(new User(){ id = 1});
}
public class User{
public int id{get;set;}
}
public void AddOrUpdate<TEntity>(TEntity entity)
{
var key = entity.GetType().GetProperties().FirstOrDefault(p => p.Name.ToLower().Contains("id")).GetValue(entity);
Console.WriteLine(key);
if (entity == null)
throw new ArgumentNullException("entity");
}
}