// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Configuration; namespace F { public class SomeAttribute : Attribute { private String sv; public string SomeValue { get { return sv; } set { sv = value; } } } public class SomeService { public void Process(object o) { object[] attrs = o.GetType().GetCustomAttributes(typeof(SomeAttribute), true); if(attrs.Length > 0) { string val = ((SomeAttribute)attrs[0]).SomeValue; if(val.StartsWith("cfg:")) { val = ConfigurationManager.AppSettings[val.Substring(4)]; } Console.WriteLine("processing with SomeAttribute SomeValue=" + val); } else { Console.WriteLine("processing without SomeAttribute"); } } } }