简体   繁体   English

使用System.Version进行通用版本控制

[英]Using System.Version for general purpose versioning

Scenario: I needed to keep track of a few random version numbers for a few random things in my code. 场景:我需要在代码中跟踪几个随机版本的随机版本号。 I wanted to define a class in order to keep track of them and put them into a form in which I can easily call and manipulate. 我想定义一个类,以便跟踪它们并将它们放入一个我可以轻松调用和操作的表单中。 I considered using System.Version but it was described as a class for versioning specific things: 我考虑过使用System.Version,但它被描述为一个用于版本化特定事物的类:

Represents the version number of an assembly, operating system, or the common language runtime. 表示程序集,操作系统或公共语言运行库的版本号。

Question: Is it acceptable to use the System.Version class for things other than "an assembly, operating system, or the common language runtime"? 问题:将System.Version类用于“程序集,操作系统或公共语言运行库”之外的其他内容是否可以接受?

The System.Version class is very simple, with just a few properties; System.Version类非常简单,只有几个属性; Build, Major, MajorRevision, ... and not much else. Build,Major,MajorRevision,......而不是其他。 If this fits your needs, and you do not find yourself wth redundant properties on your interface I guess you could use it. 如果这符合您的需求,并且您没有发现自己在界面上有多余的属性,我想您可以使用它。 However, one thing to watch out for is that System.Version is sealed, so if at any point you find it does not fit your needs and you wish to extend it, you will not be able to. 但是,有一点需要注意的是System.Version是密封的,所以如果在任何时候你发现它不符合你的需求并且你想扩展它,你将无法做到。

Personally, with System.Version being such a simple class, and the lack of future extensibility, I would create my own type. 就个人而言,System.Version是一个如此简单的类,并且缺乏未来的可扩展性,我会创建自己的类型。

值得注意的是,即使微软在所有情况下都不使用System.Version ......它并不是像DateTime那样设计成一个全能的版本控制类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 System.Version未序列化 - System.Version not serialized sql server中System.Version的数据类型 - Datatype for System.Version in sql server 使用被套。 Net Framework 生成错误:无法评估表达式“[System.Version]::Parse('')” - Using coverlet with. Net Framework generates an error: The expression "[System.Version]::Parse('')" canot be evaluated System.Version 的序列化和反序列化使用 Newtonsoft,dotnet core 2.2 vs dot net core 3.1 - Serialization and Deserialization of System.Version using Newtonsoft, dotnet core 2.2 vs dot net core 3.1 使用Entity Framework Code First将System.Version存储在数据库中 - Storing System.Version in database with Entity Framework Code First 为什么.NET System.Version "2.0" 与 "2.0.0.0" 不同? - Why is .NET System.Version "2.0" different from "2.0.0.0"? 如何在实体框架6中将System.Version映射为复杂类型 - How to map System.Version as Complex Type in Entity Framework 6 为什么JSON字符串中的System.Version没有正确反序列化? - Why System.Version in JSON string does not deserialize correctly? system.version超过3个小数点C# - system.version more than 3 decimal points c# 无法将类型'System.Version'隐式转换为'System.Net.HttpVersion' - Cannot implicitly convert type 'System.Version' to 'System.Net.HttpVersion'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM