PageRenderTime 23ms CodeModel.GetById 17ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 1ms

/Main/src/Xbap/DynamicDataDisplay.Xbap.Samples/Internals/VersionTypeConverter.cs

#
C# | 36 lines | 31 code | 5 blank | 0 comment | 3 complexity | 7b9a94bfc890b81bc7f5caaf5096493d MD5 | raw file
 1using System;
 2using System.Collections.Generic;
 3using System.Linq;
 4using System.Text;
 5using System.ComponentModel;
 6using System.Globalization;
 7using Microsoft.Research.DynamicDataDisplay.Samples.Internals.Models;
 8
 9namespace Microsoft.Research.DynamicDataDisplay.Samples.Internals
10{
11	public class VersionTypeConverter : TypeConverter
12	{
13		public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
14		{
15			if (sourceType == typeof(string))
16				return true;
17
18			return base.CanConvertFrom(context, sourceType);
19		}
20
21		public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
22		{
23			string str = (string)value;
24
25			string[] parts = str.Split('.');
26
27			int major = Int32.Parse(parts[0], culture);
28			int minor = Int32.Parse(parts[1], culture);
29			int revision = 0;
30			if (parts.Length >= 3)
31				revision = Int32.Parse(parts[2], culture);
32			ReleaseVersion result = new ReleaseVersion(major, minor, revision);
33			return result;
34		}
35	}
36}