提取项目可重用代码 [英] Extract project reusable code

查看:76
本文介绍了提取项目可重用代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢从我的项目中创建2个项目,这些代码是可拆分为其他项目的代码.
Visual Studio 2010能够处理多个项目的一种解决方案,因此从理论上讲是很好的.

我只是不知道哪种方法最适合我的情况:

例如,我有一个自定义网格类(ucMyGrid)

此自定义类中sub的示例:

I like to create from my project 2 projects, were the code that is reusable for other projects is split off.
Visual Studio 2010 is able to handle one solution with mutiple projects, so this is in theory fine.

I just don''t know what would be the best approach for my case:

For example i''ve a custom grid class (ucMyGrid)

Example of sub in the this custom class :

Private Sub FillGrid(ByVal sSQL As String)
	
   Try
			
     'My code is here
			
   Catch ex As Exception
     mdlMyCustomLogging.fLOG(MDIParrent1.cUser.UserID, "ucMygrid => FillGrid: " & ex.Message.ToString)
   Finally
		
End Sub



共享项目包含日志记录模块"mdlMyCustomLogging"


但是我该如何处理在日志记录中用作参数的userID?
始终不将其作为参数传递.

谢谢



The shared project contains the logging module ''mdlMyCustomLogging''


But how can i handle the userID that is used as a parameter in the logging?
Without passing this always as a parameter.

Thanks

推荐答案

userId来自哪里?除非它来自某个静态资源(例如当前登录的用户),否则您将无法逃避以某种方式将值传递给组件.如果该组件中有更多方法使用它,则可以将其存储在该类的属性中.
Where is the userId coming from? Unless it is coming from some static resource, such the current logged on user, you can''t get away from passing the value in some fashion to the component. If it is used by more methods in this component you could store it in a property of the class.


如果您的类需要以任何方式引用其父级(甚至(知道它是MDI容器的程度),则很难将其充分分离以将其分离到另一个项目中.

理想情况下,类在提取时应该是独立的,或者在同一名称空间中与一堆相关/互连的类一起存在.

如果您的控件需要了解它所处的环境,则可能需要进行大量的工作才能充分隔离它-并可能需要完全重写某些部分.
If your class needs to refer to it''s parent in any way (even to the extent of knowing it is an MDI Container) then it is difficult to divorce it sufficiently to separate it into a different project.

Ideally, a class should stand alone when you extract it, or with a bunch of related / interconnected classes in the same namespace.

If your control needs to know about the environment it is working in, it probably will need a lot of re-work to isolate it sufficiently - and may need a complete rewrite of some sections.


这篇关于提取项目可重用代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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