Skip to content

Commit bd7ba72

Browse files
committed
Namespace 1 line preference
1 parent 46a72c9 commit bd7ba72

14 files changed

+2576
-2590
lines changed

Source/Attributes.cs

Lines changed: 81 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -1,112 +1,111 @@
11
using System;
22

3-
namespace Kermalis.EndianBinaryIO
3+
namespace Kermalis.EndianBinaryIO;
4+
5+
public interface IBinaryAttribute<T>
6+
{
7+
T Value { get; }
8+
}
9+
10+
[AttributeUsage(AttributeTargets.Property)]
11+
public sealed class BinaryIgnoreAttribute : Attribute, IBinaryAttribute<bool>
412
{
5-
public interface IBinaryAttribute<T>
13+
public bool Value { get; }
14+
15+
public BinaryIgnoreAttribute(bool ignore = true)
616
{
7-
T Value { get; }
17+
Value = ignore;
818
}
19+
}
20+
[AttributeUsage(AttributeTargets.Property)]
21+
public sealed class BinaryBooleanSizeAttribute : Attribute, IBinaryAttribute<BooleanSize>
22+
{
23+
public BooleanSize Value { get; }
924

10-
[AttributeUsage(AttributeTargets.Property)]
11-
public sealed class BinaryIgnoreAttribute : Attribute, IBinaryAttribute<bool>
25+
public BinaryBooleanSizeAttribute(BooleanSize booleanSize)
1226
{
13-
public bool Value { get; }
14-
15-
public BinaryIgnoreAttribute(bool ignore = true)
27+
if (booleanSize >= BooleanSize.MAX)
1628
{
17-
Value = ignore;
29+
throw new ArgumentOutOfRangeException(nameof(booleanSize), $"{nameof(BinaryBooleanSizeAttribute)} cannot be created with a size of {booleanSize}.");
1830
}
31+
Value = booleanSize;
1932
}
20-
[AttributeUsage(AttributeTargets.Property)]
21-
public sealed class BinaryBooleanSizeAttribute : Attribute, IBinaryAttribute<BooleanSize>
22-
{
23-
public BooleanSize Value { get; }
33+
}
34+
[AttributeUsage(AttributeTargets.Property)]
35+
public sealed class BinaryASCIIAttribute : Attribute, IBinaryAttribute<bool>
36+
{
37+
public bool Value { get; }
2438

25-
public BinaryBooleanSizeAttribute(BooleanSize booleanSize)
26-
{
27-
if (booleanSize >= BooleanSize.MAX)
28-
{
29-
throw new ArgumentOutOfRangeException(nameof(booleanSize), $"{nameof(BinaryBooleanSizeAttribute)} cannot be created with a size of {booleanSize}.");
30-
}
31-
Value = booleanSize;
32-
}
33-
}
34-
[AttributeUsage(AttributeTargets.Property)]
35-
public sealed class BinaryASCIIAttribute : Attribute, IBinaryAttribute<bool>
39+
public BinaryASCIIAttribute(bool ascii = true)
3640
{
37-
public bool Value { get; }
38-
39-
public BinaryASCIIAttribute(bool ascii = true)
40-
{
41-
Value = ascii;
42-
}
41+
Value = ascii;
4342
}
44-
[AttributeUsage(AttributeTargets.Property)]
45-
public sealed class BinaryStringNullTerminatedAttribute : Attribute, IBinaryAttribute<bool>
46-
{
47-
public bool Value { get; }
43+
}
44+
[AttributeUsage(AttributeTargets.Property)]
45+
public sealed class BinaryStringNullTerminatedAttribute : Attribute, IBinaryAttribute<bool>
46+
{
47+
public bool Value { get; }
4848

49-
public BinaryStringNullTerminatedAttribute(bool nullTerminated = true)
50-
{
51-
Value = nullTerminated;
52-
}
53-
}
54-
[AttributeUsage(AttributeTargets.Property)]
55-
public sealed class BinaryArrayFixedLengthAttribute : Attribute, IBinaryAttribute<int>
49+
public BinaryStringNullTerminatedAttribute(bool nullTerminated = true)
5650
{
57-
public int Value { get; }
58-
59-
public BinaryArrayFixedLengthAttribute(int length)
60-
{
61-
if (length < 0)
62-
{
63-
throw new ArgumentOutOfRangeException(nameof(length), $"{nameof(BinaryArrayFixedLengthAttribute)} cannot be created with a length of {length}. Length must be 0 or greater.");
64-
}
65-
Value = length;
66-
}
51+
Value = nullTerminated;
6752
}
68-
[AttributeUsage(AttributeTargets.Property)]
69-
public sealed class BinaryArrayVariableLengthAttribute : Attribute, IBinaryAttribute<string>
70-
{
71-
public string Value { get; }
53+
}
54+
[AttributeUsage(AttributeTargets.Property)]
55+
public sealed class BinaryArrayFixedLengthAttribute : Attribute, IBinaryAttribute<int>
56+
{
57+
public int Value { get; }
7258

73-
public BinaryArrayVariableLengthAttribute(string anchor)
74-
{
75-
Value = anchor;
76-
}
77-
}
78-
[AttributeUsage(AttributeTargets.Property)]
79-
public sealed class BinaryStringFixedLengthAttribute : Attribute, IBinaryAttribute<int>
59+
public BinaryArrayFixedLengthAttribute(int length)
8060
{
81-
public int Value { get; }
82-
83-
public BinaryStringFixedLengthAttribute(int length)
61+
if (length < 0)
8462
{
85-
if (length < 0)
86-
{
87-
throw new ArgumentOutOfRangeException(nameof(length), $"{nameof(BinaryStringFixedLengthAttribute)} cannot be created with a length of {length}. Length must be 0 or greater.");
88-
}
89-
Value = length;
63+
throw new ArgumentOutOfRangeException(nameof(length), $"{nameof(BinaryArrayFixedLengthAttribute)} cannot be created with a length of {length}. Length must be 0 or greater.");
9064
}
65+
Value = length;
9166
}
92-
[AttributeUsage(AttributeTargets.Property)]
93-
public sealed class BinaryStringVariableLengthAttribute : Attribute, IBinaryAttribute<string>
67+
}
68+
[AttributeUsage(AttributeTargets.Property)]
69+
public sealed class BinaryArrayVariableLengthAttribute : Attribute, IBinaryAttribute<string>
70+
{
71+
public string Value { get; }
72+
73+
public BinaryArrayVariableLengthAttribute(string anchor)
9474
{
95-
public string Value { get; }
75+
Value = anchor;
76+
}
77+
}
78+
[AttributeUsage(AttributeTargets.Property)]
79+
public sealed class BinaryStringFixedLengthAttribute : Attribute, IBinaryAttribute<int>
80+
{
81+
public int Value { get; }
9682

97-
public BinaryStringVariableLengthAttribute(string anchor)
83+
public BinaryStringFixedLengthAttribute(int length)
84+
{
85+
if (length < 0)
9886
{
99-
Value = anchor;
87+
throw new ArgumentOutOfRangeException(nameof(length), $"{nameof(BinaryStringFixedLengthAttribute)} cannot be created with a length of {length}. Length must be 0 or greater.");
10088
}
89+
Value = length;
10190
}
102-
[AttributeUsage(AttributeTargets.Property)]
103-
public sealed class BinaryStringTrimNullTerminatorsAttribute : Attribute, IBinaryAttribute<bool>
91+
}
92+
[AttributeUsage(AttributeTargets.Property)]
93+
public sealed class BinaryStringVariableLengthAttribute : Attribute, IBinaryAttribute<string>
94+
{
95+
public string Value { get; }
96+
97+
public BinaryStringVariableLengthAttribute(string anchor)
10498
{
105-
public bool Value { get; }
99+
Value = anchor;
100+
}
101+
}
102+
[AttributeUsage(AttributeTargets.Property)]
103+
public sealed class BinaryStringTrimNullTerminatorsAttribute : Attribute, IBinaryAttribute<bool>
104+
{
105+
public bool Value { get; }
106106

107-
public BinaryStringTrimNullTerminatorsAttribute(bool trim = true)
108-
{
109-
Value = trim;
110-
}
107+
public BinaryStringTrimNullTerminatorsAttribute(bool trim = true)
108+
{
109+
Value = trim;
111110
}
112111
}

0 commit comments

Comments
 (0)