English 中文(简体)
获取具有共同基类物体的最佳松散方式
原标题:Best loose way to get objects with common base class

我为解决这一问题而奋斗,因此建议值得欢迎。

让我们说,我们有一个抽象的基类行动基础,看着这样的情况:

public abstract class ActionBase
{
    public abstract string Name { get; }
    public abstract string Description { get; }

    // rest of declaration follows
}

而且,我们有一套不同的行动,如行动、写作行动等。 这些行动附属于工人目标:

public class Worker
{
    private IList<ActionBase> _actions = new List<ActionBase>();
    public IList<ActionBase> Actions { get { return _actions; } }

    // worker stuff ...
}

至今,只是直截了当。 现在,我要提出成立工人、分派行动、确定财产等等的“倡议”。 在这项调查中,我要提出一个清单,列出所有可采取的行动及其性质,因为我想首先把现有行动的所有名称和描述(加上类型)归纳为以下类型的项目:

public class ActionDescriptor
{
    public string Name { get; }
    public string Description { get; }
    poblic Type Type { get; }
}

当然,我能够利用思考来做到这一点,但是否有更好的办法? “行动基础”的名词和描述(而不是衍生物上的静态)具有比照,但C#中则没有抽象的静态。

谢谢!

最佳回答

你再次谈到的是,为你的具体行动班子提供元数据,以描述这些课堂。 关于姓名和说明的简单例子,我建议显示Name和描述属性,如:

[DisplayName("MyAction Name")]
[Description("My description goes here")]
public class MyAction : ActionBase
{
    //Declaration goes here
}

这些属性在<代码>System.ComponentModel中界定。

问题回答

你们可以为行动基础增添一个抽象的方法,把行动介绍者归来,然后,你可以就每项行动向行动说明者提出疑问。





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签