Необходимо добавить свойства внутри интерфейсов:
public interface IAttributeInterface<T>
{
T Key { get; set; }
T Value { get; set; }
}
Затем нам нужно реализовать этот универсальный c интерфейс в классе, чтобы иметь возможность создавать экземпляр объекта:
public class Attribute<T> : IAttributeInterface<T>
{
public T Key { get; set ; }
public T Value { get ; set; }
public Attribute(T key, T value)
{
this.Key = key;
this.Value = value;
}
}
и ваш метод будет выглядеть следующим образом:
public List<IAttributeInterface<string>> attributes =
new List<IAttributeInterface<string>>();
public void AddAttribute<T>(T attribute, T value) where T: IAttributeInterface<string>
{
for (int i = 0; i < attributes.Count; i++)
{
if (attributes[i].Key == attribute.Key)
{
attributes[i].Value = value.Value;
return;
}
}
attributes.Add(new Attribute<string>("key", "value"));
}
, и его можно использовать так:
AddAttribute(new Attribute<string>("foo key 0", "foo value 0"),
new Attribute<string>("foo key 1", "foo value 1"));