课堂活动 [英] Class events

查看:84
本文介绍了课堂活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经生成了一个类,其中包含我的

应用程序的配置数据。


不幸的是我不能使用类的静态实现,因为它

需要一个构造函数。


我在其他几个类中生成这个类的实例(无论我在哪里
需要检索配置详细信息)。


我希望任何类生成一个事件,对于所有实例

在任何实例发生更改时重新加载底层xml文件

属性。


类实例是否可以生成一个事件,以便所有其他实例都能收到活动?


问候,


Dave

I have generated a class, which contains configuration data for my
application.

Unfortunately I cannot use a static implementation of the class, as it
requires a constructor.

I generate instances of this class in several other classes (wherever I
need to retrieve the config details).

I would like any of the classes to generate an event, for all instances
to reload the underlying xml file whenever any of the instances change
the properties.

Is it possible for a class instance to generate an event so that all
other instances will receive the event?

Regards,

Dave

推荐答案

Dave,


你可能想在这里使用单例模式。不要创建新的

实例,而是拥有一个实例,然后让所有类连接到该实例的
事件处理程序。


希望这会有所帮助。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Dave Kelly" < DK **** @ memco.co.uk>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...
Dave,

You might want to use a singleton pattern here. Instead of creating new
instances, have one instance, and then have all of your classes hook up
event handlers to that instance.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Dave Kelly" <dk****@memco.co.uk> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
我已经生成了一个类,其中包含我的
应用程序的配置数据。

不幸的是我不能使用类的静态实现,因为它需要一个构造函数。

我在其他几个类中生成了这个类的实例(无论我需要检索配置详细信息)。

我想要任何类来为所有实例生成一个事件,以便在任何实例更改属性时重新加载底层的xml文件。

类实例是否可以生成事件所有
其他实例都会收到活动吗?

问候,

戴夫
I have generated a class, which contains configuration data for my
application.

Unfortunately I cannot use a static implementation of the class, as it
requires a constructor.

I generate instances of this class in several other classes (wherever I
need to retrieve the config details).

I would like any of the classes to generate an event, for all instances
to reload the underlying xml file whenever any of the instances change
the properties.

Is it possible for a class instance to generate an event so that all
other instances will receive the event?

Regards,

Dave



添加到尼古拉斯的答案:


如果你使用单身人士,你不必担心一个

实例的变化不是存在反映在另一个,因为每个人都使用相同的

实例。


http://www.yoda.arachsys.com/csharp/singleton.html


-

--- Nick Malik [微软]

MCSD,CFPS,认证Scrummaster
http://blogs.msdn.com/nickmalik


免责声明:本论坛发表的意见均为我的意见拥有,而不是

代表我的雇主。

我不代表我的雇主回答问题。我只是一个帮助程序员的
程序员。

-

Dave Kelly < DK **** @ memco.co.uk>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...
to add to Nicolas'' answer:

If you use a singleton, you don''t need to worry about a change in one
instance not being reflected in another, since everyone is using the same
instance.

See http://www.yoda.arachsys.com/csharp/singleton.html

--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster
http://blogs.msdn.com/nickmalik

Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I''m just a
programmer helping programmers.
--
"Dave Kelly" <dk****@memco.co.uk> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
我已经生成了一个类,其中包含我的
应用程序的配置数据。

不幸的是我不能使用类的静态实现,因为它需要一个构造函数。

我在其他几个类中生成了这个类的实例(无论我需要检索配置详细信息)。

我想要任何类来为所有实例生成一个事件,以便在任何实例更改属性时重新加载底层的xml文件。

类实例是否可以生成事件所有
其他实例都会收到活动吗?

问候,

戴夫
I have generated a class, which contains configuration data for my
application.

Unfortunately I cannot use a static implementation of the class, as it
requires a constructor.

I generate instances of this class in several other classes (wherever I
need to retrieve the config details).

I would like any of the classes to generate an event, for all instances
to reload the underlying xml file whenever any of the instances change
the properties.

Is it possible for a class instance to generate an event so that all
other instances will receive the event?

Regards,

Dave



感谢您的回复。


我最初是以Singleton模式开始的,但它没有工作

out。

机智我的类我有属性,用于属性网格,

Hastable和用于存储配置数据的XMLSerializer。


我已设法满足所有要求,因为例如

XMLSerializer需要基类的公共构造函数。

Thanks for the replies.

I originally started with a Singleton pattern, but it wasn''t working
out.

Within my class I have properties, which are used in a property grid, a
Hastable and an XMLSerializer to store the config data.

I have managed to satisfy all the requirements, since for example the
XMLSerializer requires a public constructor of the base class.


这篇关于课堂活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆