Skip to content

Commit 77595ac

Browse files
committed
Separated UnitAttribute out into separate file and moved both into Attributes folder.
1 parent 429c25b commit 77595ac

File tree

8 files changed

+45
-46
lines changed

8 files changed

+45
-46
lines changed

Src/UnitsNet/Attributes.cs renamed to Src/UnitsNet/Attributes/Attributes.cs

Lines changed: 1 addition & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,8 @@
2121

2222
using System;
2323

24-
namespace UnitsNet
24+
namespace UnitsNet.Attributes
2525
{
26-
//[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
27-
//public class FooAttribute : UnitAttribute
28-
//{
29-
// public override Unit BaseUnit { get { return Unit.Meter; } }
30-
// public override string XmlDocSummary { get { return "Foo description"; } }
31-
32-
// public FooAttribute(double ratio, string pluralName = (string)null) : base(pluralName, ratio)
33-
// {
34-
// }
35-
//}
36-
3726
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
3827
public class AngleAttribute : UnitAttribute
3928
{
@@ -145,37 +134,4 @@ public VolumeAttribute(double ratio, string pluralName = (string)null) : base(pl
145134
{
146135
}
147136
}
148-
149-
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
150-
public abstract class UnitAttribute : Attribute
151-
{
152-
/// <summary>
153-
/// Base unit of unit class. This is the unit that unit classes store their value as internally.
154-
/// Conversions between two units go via the base unit to simplify defining the constants, requiring only N constants
155-
/// instead of N².
156-
/// </summary>
157-
public abstract Unit BaseUnit { get; }
158-
159-
/// <summary>
160-
/// Name of unit in plural form. Will be used as property name such as Force.FromNewtonmeters().
161-
/// </summary>
162-
public readonly string PluralName;
163-
164-
/// <summary>
165-
/// Ratio of unit to base unit. For example, <see cref="Unit.Kilometer" /> is 1000:1 of the base unit
166-
/// <see cref="Unit.Meter" />.
167-
/// </summary>
168-
public readonly double Ratio;
169-
170-
/// <summary>
171-
/// XML doc summary for unit class. Will be inserted when generating the class from T4 template.
172-
/// </summary>
173-
public abstract string XmlDocSummary { get; }
174-
175-
public UnitAttribute(string pluralName, double ratio)
176-
{
177-
Ratio = ratio;
178-
PluralName = pluralName;
179-
}
180-
}
181137
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
using System;
2+
3+
namespace UnitsNet.Attributes
4+
{
5+
[AttributeUsage(AttributeTargets.Field, AllowMultiple = false)]
6+
public abstract class UnitAttribute : Attribute
7+
{
8+
/// <summary>
9+
/// Base unit of unit class. This is the unit that unit classes store their value as internally.
10+
/// Conversions between two units go via the base unit to simplify defining the constants, requiring only N constants
11+
/// instead of N².
12+
/// </summary>
13+
public abstract Unit BaseUnit { get; }
14+
15+
/// <summary>
16+
/// Name of unit in plural form. Will be used as property name such as Force.FromNewtonmeters().
17+
/// </summary>
18+
public readonly string PluralName;
19+
20+
/// <summary>
21+
/// Ratio of unit to base unit. For example, <see cref="Unit.Kilometer" /> is 1000:1 of the base unit
22+
/// <see cref="Unit.Meter" />.
23+
/// </summary>
24+
public readonly double Ratio;
25+
26+
/// <summary>
27+
/// XML doc summary for unit class. Will be inserted when generating the class from T4 template.
28+
/// </summary>
29+
public abstract string XmlDocSummary { get; }
30+
31+
public UnitAttribute(string pluralName, double ratio)
32+
{
33+
Ratio = ratio;
34+
PluralName = pluralName;
35+
}
36+
}
37+
}

Src/UnitsNet/Generated Code/Includes/Shared.ttinclude

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<#@ import namespace="System.Collections.Generic" #>
77
<#@ import namespace="System.Reflection" #>
88
<#@ import namespace="UnitsNet" #>
9+
<#@ import namespace="UnitsNet.Attributes" #>
910
<#@ import namespace="UnitsNet.Extensions" #><#+
1011

1112
/// <summary>

Src/UnitsNet/Generated Code/Includes/UnitClass.ttinclude

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<#@ import namespace="System.Text" #>
66
<#@ import namespace="System.Collections.Generic" #>
77
<#@ import namespace="UnitsNet" #>
8+
<#@ import namespace="UnitsNet.Attributes" #>
89
<#@ import namespace="UnitsNet.Extensions" #>
910
<#@ include file="MultipleOutputHelper.ttinclude" once="true"#>
1011
<#@ include file="Shared.ttinclude" once="true" #>

Src/UnitsNet/Generated Code/UnitConverter.tt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<#@ import namespace="System.Text" #>
77
<#@ import namespace="System.Collections.Generic" #>
88
<#@ import namespace="UnitsNet" #>
9+
<#@ import namespace="UnitsNet.Attributes" #>
910
<#@ import namespace="UnitsNet.Extensions" #>
1011
<#@ include file="Includes\MultipleOutputHelper.ttinclude" once="true"#>
1112
<#@ include file="Includes\Shared.ttinclude" once="true"#>

Src/UnitsNet/Unit.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
// THE SOFTWARE.
2121

2222
using System;
23+
using UnitsNet.Attributes;
2324

2425
namespace UnitsNet
2526
{

Tests/Generated Code/Includes/UnitTestClass.ttinclude

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<#@ import namespace="System.Text" #>
55
<#@ import namespace="System.Collections.Generic" #>
66
<#@ import namespace="UnitsNet" #>
7+
<#@ import namespace="UnitsNet.Attributes" #>
78
<#@ import namespace="UnitsNet.Extensions" #>
89
<#@ include file="$(SolutionDir)\UnitsNet\Generated Code\Includes\MultipleOutputHelper.ttinclude" once="true"#>
910
<#@ include file="$(SolutionDir)\UnitsNet\Generated Code\Includes\Shared.ttinclude" once="true" #><#+

Tests/Generated Code/Includes/UnitValueTests.ttinclude

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
<#@ import namespace="System.Linq" #>
44
<#@ import namespace="System.Text" #>
55
<#@ import namespace="System.Collections.Generic" #>
6-
<#@ import namespace="UnitsNet" #><#+
6+
<#@ import namespace="UnitsNet" #>
7+
<#@ import namespace="UnitsNet.Attributes" #><#+
78

89
private void GenerateUnitValueTests(Dictionary<Unit, UnitAttribute> unitToAttribute)
910
{

0 commit comments

Comments
 (0)