本文介绍了VB.NET类生成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 好的,现在我真的疯了......可能是为什么我没有广泛使用VB6中的Class Builder。 但是,作为我应该的''正确的程序员',我正试图咬住 子弹并为我在内运作的每个''实体'建立课程。 程序,即乘客,车辆等。然后分开链接到这些的的UI类。 (部分原因是因为最终几个附加组件将能够重用 数据类中的代码)。 我的问题是这个.... 是否有任何SHORTER方法来定义类中的属性.... 公共类乘客 私有sFirstName为字符串 公共属性FirstName为字符串 获取 FirstName = iFirstName 结束获取 设置 iFirstName = FirstName 结束集 结束物业 ... 结束班级 显然,在课堂上有10到20个字段,你最终会得到100行$ 代码......只需设置和检索变量。哪个,如果是这样的话,那么就可以了,但是我也想设置一个脏标志 如果它们中的任何一个被重置一些业务逻辑将在某些领域等等。 那么,是否存在属性的短形式,或者,有没有办法伪造 ' 属性,这与反射库有关,可以模拟 属性,但只有几个属性函数才能为它们提供服务 (即,使用集合来存储值,以及一个属性服务函数 来检查它们/分配它们/执行其他逻辑)。 这个可能听起来很懒,但我很害怕经历并创建了每个20-30个字段的20-30个数据类库 - 只是告诉我它不是 所以。 解决方案 重用 如果是这样的话,哪个会好的,但我也想设置''脏'' 标志 模拟 函数 创建 不是 Ok, now I am truely going nuts... probably why I didn''t use the ClassBuilder in VB6 extensively.But, being the ''proper programmer'' that I should, I''m trying to bite thebullet and build classes for each of my ''entities'' that operate within theprogram, ie, passenger, vehicle, etc. Then seperate UI classes that link tothese. (Partially, because eventually several add-ons will be able to reusethe code in the data classes).My question is this....Is there any SHORTER way to define properties in a class than....Public Class PassengerPrivate sFirstName As StringPublic Property FirstName As StringGetFirstName = iFirstNameEnd GetSetiFirstName = FirstNameEnd SetEnd Property...End ClassObviously, with 10-20 fields in the class, you end up with, oh 100 lines ofcode... doing not much more than setting and retrieving variables. Which,if that was the case, would be fine, but I''d also like to set a ''dirty'' flagif any of them are reset, some business logic will be in some fields, etc.So, is there a ''short-form'' for properties, OR, is there a way to ''fake''properties, that is something to do with the reflection library to simulateproperties, but have them all serviced by only a couple property functions(ie, use a collection to store the values, and one property service functionto check them/assign them/perform other logic).This probably sounds lazy of me, but Im dreading going through and creating20-30 data class libraries with 20-30 fields each ---- just tell me it isn''tso. 解决方案 reuse ofWhich, if that was the case, would be fine, but I''d also like to set a ''dirty'' flag simulate function creating isn''t 这篇关于VB.NET类生成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-20 19:47