背景:
我有一个属性,指示对象中字段的属性IsMagic。我还有一个Magician类可以运行在任何对象上,并MakesMagic提取每个字段和属性IsMagic并将其包装在Magic包装器中。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
namespace MagicTest
{
/// <summary>
/// An attribute that allows us to decorate a class with information that identifies which member is magic.
/// </summary>
[AttributeUsage(AttributeTargets.Property|AttributeTargets.Field, AllowMultiple = false)]
class IsMagic : Attribute { }
public class Magic
{
// Internal data storage
readonly public dynamic value;
#region My ever-growing list of constructors
public Magic(int input) { value = input; …Run Code Online (Sandbox Code Playgroud)