Skip to content

Commit

Permalink
Apply C# coding style for Indentation and braces from https://learn.m…
Browse files Browse the repository at this point in the history
  • Loading branch information
wfowler1 committed Jun 11, 2023
1 parent c279ed9 commit 0f0b1f2
Show file tree
Hide file tree
Showing 58 changed files with 22,975 additions and 18,399 deletions.
46 changes: 24 additions & 22 deletions LibBSP/Source/Attributes/CountAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
using System;
using System.Collections.Generic;

namespace LibBSP {
/// <summary>
/// Custom Attribute class to mark a member of a struct as an count for another lump. The
/// member this Attribute is applied to should always be paired with a member with an
/// <see cref="IndexAttribute"/> applied to it. The two attributes can the be used to grab a
/// range of objects from the specified lump through the
/// <see cref="BSP.GetReferencedObjects&lt;T&gt;(object, string)"/> method.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class CountAttribute : Attribute {
namespace LibBSP
{
/// <summary>
/// Custom Attribute class to mark a member of a struct as an count for another lump. The
/// member this Attribute is applied to should always be paired with a member with an
/// <see cref="IndexAttribute"/> applied to it. The two attributes can the be used to grab a
/// range of objects from the specified lump through the
/// <see cref="BSP.GetReferencedObjects&lt;T&gt;(object, string)"/> method.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class CountAttribute : Attribute
{

public string lumpName;

/// <summary>
/// Constructs a new instance of a <see cref="CountAttribute"/> object. The member this Attribute
/// is applied to will be used as a count of objects in the lump referenced by <paramref name="lumpName"/>.
/// </summary>
/// <param name="lumpName">The lump the member is an count for. Corresponds to the public properties in the <see cref="BSP"/> class.</param>
public CountAttribute(string lumpName) {
this.lumpName = lumpName;
}
}
public string lumpName;

/// <summary>
/// Constructs a new instance of a <see cref="CountAttribute"/> object. The member this Attribute
/// is applied to will be used as a count of objects in the lump referenced by <paramref name="lumpName"/>.
/// </summary>
/// <param name="lumpName">The lump the member is an count for. Corresponds to the public properties in the <see cref="BSP"/> class.</param>
public CountAttribute(string lumpName)
{
this.lumpName = lumpName;
}
}
}
44 changes: 23 additions & 21 deletions LibBSP/Source/Attributes/IndexAttribute.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
using System;
using System.Collections.Generic;

namespace LibBSP {
/// <summary>
/// Custom Attribute class to mark a member of a struct as an index into another lump. The
/// member this Attribute is applied to can be paired with a member with a <see cref="CountAttribute"/>
/// applied to it. The two attributes can the be used to grab a range of objects
/// from the specified lump through the
/// <see cref="BSP.GetReferencedObjects&lt;T&gt;(object, string)"/> method.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class IndexAttribute : Attribute {
namespace LibBSP
{
/// <summary>
/// Custom Attribute class to mark a member of a struct as an index into another lump. The
/// member this Attribute is applied to can be paired with a member with a <see cref="CountAttribute"/>
/// applied to it. The two attributes can the be used to grab a range of objects
/// from the specified lump through the
/// <see cref="BSP.GetReferencedObjects&lt;T&gt;(object, string)"/> method.
/// </summary>
[AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
public class IndexAttribute : Attribute
{

public string lumpName;
public string lumpName;

/// <summary>
/// Constructs a new instance of an <see cref="IndexAttribute"/> object. The member this Attribute
/// is applied to will be used as an index into the lump referenced by <paramref name="lumpName"/>.
/// </summary>
/// <param name="lumpName">The lump the member is an index into. Corresponds to the public properties in the <see cref="BSP"/> class.</param>
public IndexAttribute(string lumpName) {
this.lumpName = lumpName;
}
}
/// <summary>
/// Constructs a new instance of an <see cref="IndexAttribute"/> object. The member this Attribute
/// is applied to will be used as an index into the lump referenced by <paramref name="lumpName"/>.
/// </summary>
/// <param name="lumpName">The lump the member is an index into. Corresponds to the public properties in the <see cref="BSP"/> class.</param>
public IndexAttribute(string lumpName)
{
this.lumpName = lumpName;
}
}
}
196 changes: 102 additions & 94 deletions LibBSP/Source/Extensions/ColorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,140 +2,148 @@
#define UNITY
#endif

namespace LibBSP {
namespace LibBSP
{
#if UNITY
using Color = UnityEngine.Color32;
using Color = UnityEngine.Color32;
#elif GODOT
using Color = Godot.Color;
using Color = Godot.Color;
#elif NEOAXIS
using Color = NeoAxis.ColorByte;
using Color = NeoAxis.ColorByte;
#else
using Color = System.Drawing.Color;
using Color = System.Drawing.Color;
#endif

/// <summary>
/// Static class containing helper methods for <c>Color</c> objects.
/// </summary>
public static partial class ColorExtensions {

/// <summary>
/// Constructs a new <c>Color</c> from the passed values.
/// </summary>
/// <param name="a">Alpha component of the color.</param>
/// <param name="r">Red component of the color.</param>
/// <param name="g">Green component of the color.</param>
/// <param name="b">Blue component of the color.</param>
/// <returns>The resulting <c>Color</c> object.</returns>
public static Color FromArgb(int a, int r, int g, int b) {
/// <summary>
/// Static class containing helper methods for <c>Color</c> objects.
/// </summary>
public static partial class ColorExtensions
{

/// <summary>
/// Constructs a new <c>Color</c> from the passed values.
/// </summary>
/// <param name="a">Alpha component of the color.</param>
/// <param name="r">Red component of the color.</param>
/// <param name="g">Green component of the color.</param>
/// <param name="b">Blue component of the color.</param>
/// <returns>The resulting <c>Color</c> object.</returns>
public static Color FromArgb(int a, int r, int g, int b)
{
#if UNITY
return new Color((byte)r, (byte)g, (byte)b, (byte)a);
return new Color((byte)r, (byte)g, (byte)b, (byte)a);
#elif GODOT
return new Color((byte)r << 24 | (byte)g << 16 | (byte)b << 8 | (byte)a);
return new Color((byte)r << 24 | (byte)g << 16 | (byte)b << 8 | (byte)a);
#elif NEOAXIS
return new Color(r, g, b, a);
return new Color(r, g, b, a);
#else
return Color.FromArgb(a, r, g, b);
return Color.FromArgb(a, r, g, b);
#endif
}
}

/// <summary>
/// Gets this <c>Color</c> as R8G8B8A8 (RGBA32).
/// </summary>
/// <param name="color">This <c>Color</c>.</param>
/// <returns>A <c>byte</c> array with four members, RGBA.</returns>
public static byte[] GetBytes(this Color color) {
byte[] bytes = new byte[4];
/// <summary>
/// Gets this <c>Color</c> as R8G8B8A8 (RGBA32).
/// </summary>
/// <param name="color">This <c>Color</c>.</param>
/// <returns>A <c>byte</c> array with four members, RGBA.</returns>
public static byte[] GetBytes(this Color color)
{
byte[] bytes = new byte[4];
#if UNITY
bytes[0] = color.r;
bytes[1] = color.g;
bytes[2] = color.b;
bytes[3] = color.a;
bytes[0] = color.r;
bytes[1] = color.g;
bytes[2] = color.b;
bytes[3] = color.a;
#elif GODOT
bytes[0] = (byte)color.r8;
bytes[1] = (byte)color.g8;
bytes[2] = (byte)color.b8;
bytes[3] = (byte)color.a8;
bytes[0] = (byte)color.r8;
bytes[1] = (byte)color.g8;
bytes[2] = (byte)color.b8;
bytes[3] = (byte)color.a8;
#elif NEOAXIS
bytes[0] = color.Red;
bytes[1] = color.Green;
bytes[2] = color.Blue;
bytes[3] = color.Alpha;
bytes[0] = color.Red;
bytes[1] = color.Green;
bytes[2] = color.Blue;
bytes[3] = color.Alpha;
#else
bytes[0] = color.R;
bytes[1] = color.G;
bytes[2] = color.B;
bytes[3] = color.A;
bytes[0] = color.R;
bytes[1] = color.G;
bytes[2] = color.B;
bytes[3] = color.A;
#endif
return bytes;
}
return bytes;
}

/// <summary>
/// Gets the alpha component of this <see cref="Color"/>.
/// </summary>
/// <param name="color">This <see cref="Color"/>.</param>
/// <returns>The alpha component of this <see cref="Color"/>.</returns>
public static byte A(this Color color) {
/// <summary>
/// Gets the alpha component of this <see cref="Color"/>.
/// </summary>
/// <param name="color">This <see cref="Color"/>.</param>
/// <returns>The alpha component of this <see cref="Color"/>.</returns>
public static byte A(this Color color)
{
#if UNITY
return color.a;
return color.a;
#elif GODOT
return (byte)color.a8;
return (byte)color.a8;
#elif NEOAXIS
return color.Alpha;
return color.Alpha;
#else
return color.A;
return color.A;
#endif
}
}

/// <summary>
/// Gets the red component of this <see cref="Color"/>.
/// </summary>
/// <param name="color">This <see cref="Color"/>.</param>
/// <returns>The red component of this <see cref="Color"/>.</returns>
public static byte R(this Color color) {
/// <summary>
/// Gets the red component of this <see cref="Color"/>.
/// </summary>
/// <param name="color">This <see cref="Color"/>.</param>
/// <returns>The red component of this <see cref="Color"/>.</returns>
public static byte R(this Color color)
{
#if UNITY
return color.r;
return color.r;
#elif GODOT
return (byte)color.r8;
return (byte)color.r8;
#elif NEOAXIS
return color.Red;
return color.Red;
#else
return color.R;
return color.R;
#endif
}
}

/// <summary>
/// Gets the green component of this <see cref="Color"/>.
/// </summary>
/// <param name="color">This <see cref="Color"/>.</param>
/// <returns>The green component of this <see cref="Color"/>.</returns>
public static byte G(this Color color) {
/// <summary>
/// Gets the green component of this <see cref="Color"/>.
/// </summary>
/// <param name="color">This <see cref="Color"/>.</param>
/// <returns>The green component of this <see cref="Color"/>.</returns>
public static byte G(this Color color)
{
#if UNITY
return color.g;
return color.g;
#elif GODOT
return (byte)color.g8;
return (byte)color.g8;
#elif NEOAXIS
return color.Green;
return color.Green;
#else
return color.G;
return color.G;
#endif
}
}

/// <summary>
/// Gets the blue component of this <see cref="Color"/>.
/// </summary>
/// <param name="color">This <see cref="Color"/>.</param>
/// <returns>The blue component of this <see cref="Color"/>.</returns>
public static byte B(this Color color) {
/// <summary>
/// Gets the blue component of this <see cref="Color"/>.
/// </summary>
/// <param name="color">This <see cref="Color"/>.</param>
/// <returns>The blue component of this <see cref="Color"/>.</returns>
public static byte B(this Color color)
{
#if UNITY
return color.b;
return color.b;
#elif GODOT
return (byte)color.b8;
return (byte)color.b8;
#elif NEOAXIS
return color.Blue;
return color.Blue;
#else
return color.B;
return color.B;
#endif
}
}

}
}
}
35 changes: 19 additions & 16 deletions LibBSP/Source/Extensions/CustomAttributeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,22 +1,25 @@
using System;
using System.Reflection;

namespace LibBSP {
namespace LibBSP
{

/// <summary>
/// Contains static methods for retrieving custom attributes.
/// </summary>
public static partial class CustomAttributeExtensions {

/// <summary>
/// Retrieves a custom attribute of a specified type that is applied to a specified member.
/// </summary>
/// <param name="element">The member to inspect.</param>
/// <returns>A custom attribute that matches <typeparamref name="T"/>, or <c>null</c> if no such attribute is found.</returns>
/// <typeparam name="T">The type of attribute to search for.</typeparam>
public static T GetCustomAttribute<T>(this MemberInfo element) where T : Attribute {
return Attribute.GetCustomAttribute(element, typeof(T)) as T;
}
/// <summary>
/// Contains static methods for retrieving custom attributes.
/// </summary>
public static partial class CustomAttributeExtensions
{

}
/// <summary>
/// Retrieves a custom attribute of a specified type that is applied to a specified member.
/// </summary>
/// <param name="element">The member to inspect.</param>
/// <returns>A custom attribute that matches <typeparamref name="T"/>, or <c>null</c> if no such attribute is found.</returns>
/// <typeparam name="T">The type of attribute to search for.</typeparam>
public static T GetCustomAttribute<T>(this MemberInfo element) where T : Attribute
{
return Attribute.GetCustomAttribute(element, typeof(T)) as T;
}

}
}
Loading

0 comments on commit 0f0b1f2

Please sign in to comment.