Property bag for C# class
问题 Accessing c# class properties like javascript language would make life a lot easier. How we can do it in C#? For example: someObject["Property"]="simple string"; Console.WriteLine(someObject["FirstName"]); 回答1: Here is how you can enable property-bag-like functionality in your classes by adding a few lines of code: partial class SomeClass { private static readonly PropertyDescriptorCollection LogProps = TypeDescriptor.GetProperties(typeof(SomeClass)); public object this[string propertyName] {