diff --git a/.editorconfig b/.editorconfig index d05ad1af27..7b3f63dc7c 100644 --- a/.editorconfig +++ b/.editorconfig @@ -616,6 +616,9 @@ dotnet_code_quality.api_surface = all #dotnet_code_quality.CA1010.additional_required_generic_interfaces = dotnet_diagnostic.CA1010.severity = warning +# Abstract types should not have public constructors. +dotnet_diagnostic.CA1012.severity = warning + # Mark attributes with 'AttributeUsageAttribute'. dotnet_diagnostic.CA1018.severity = warning diff --git a/OpenRA.Game/Activities/Activity.cs b/OpenRA.Game/Activities/Activity.cs index 63b87e39cc..b4a31d33b4 100644 --- a/OpenRA.Game/Activities/Activity.cs +++ b/OpenRA.Game/Activities/Activity.cs @@ -86,7 +86,7 @@ namespace OpenRA.Activities bool firstRunCompleted; bool lastRun; - public Activity() + protected Activity() { IsInterruptible = true; ChildHasPriority = true; diff --git a/OpenRA.Game/Map/CellLayerBase.cs b/OpenRA.Game/Map/CellLayerBase.cs index 1c2e7a9972..00ce5d7c13 100644 --- a/OpenRA.Game/Map/CellLayerBase.cs +++ b/OpenRA.Game/Map/CellLayerBase.cs @@ -24,10 +24,10 @@ namespace OpenRA protected readonly T[] Entries; protected readonly Rectangle Bounds; - public CellLayerBase(Map map) + protected CellLayerBase(Map map) : this(map.Grid.Type, new Size(map.MapSize.X, map.MapSize.Y)) { } - public CellLayerBase(MapGridType gridType, Size size) + protected CellLayerBase(MapGridType gridType, Size size) { Size = size; Bounds = new Rectangle(0, 0, Size.Width, Size.Height); diff --git a/OpenRA.Game/Scripting/ScriptContext.cs b/OpenRA.Game/Scripting/ScriptContext.cs index 2cbabd774c..84c50f8746 100644 --- a/OpenRA.Game/Scripting/ScriptContext.cs +++ b/OpenRA.Game/Scripting/ScriptContext.cs @@ -50,7 +50,8 @@ namespace OpenRA.Scripting { protected readonly Actor Self; protected readonly ScriptContext Context; - public ScriptActorProperties(ScriptContext context, Actor self) + + protected ScriptActorProperties(ScriptContext context, Actor self) { Self = self; Context = context; @@ -61,7 +62,8 @@ namespace OpenRA.Scripting { protected readonly Player Player; protected readonly ScriptContext Context; - public ScriptPlayerProperties(ScriptContext context, Player player) + + protected ScriptPlayerProperties(ScriptContext context, Player player) { Player = player; Context = context; @@ -87,7 +89,8 @@ namespace OpenRA.Scripting protected override string MemberNotFoundError(string memberName) { return $"Table '{Name}' does not define a property '{memberName}'"; } public readonly string Name; - public ScriptGlobal(ScriptContext context) + + protected ScriptGlobal(ScriptContext context) : base(context) { // GetType resolves the actual (subclass) type diff --git a/OpenRA.Game/Scripting/ScriptObjectWrapper.cs b/OpenRA.Game/Scripting/ScriptObjectWrapper.cs index 4b1153c504..17c8fb00dd 100644 --- a/OpenRA.Game/Scripting/ScriptObjectWrapper.cs +++ b/OpenRA.Game/Scripting/ScriptObjectWrapper.cs @@ -28,7 +28,7 @@ namespace OpenRA.Scripting readonly List membersToRemove = new List(); #endif - public ScriptObjectWrapper(ScriptContext context) + protected ScriptObjectWrapper(ScriptContext context) { Context = context; } diff --git a/OpenRA.Game/Support/VariableExpression.cs b/OpenRA.Game/Support/VariableExpression.cs index 6b00eecfcc..41714ec522 100644 --- a/OpenRA.Game/Support/VariableExpression.cs +++ b/OpenRA.Game/Support/VariableExpression.cs @@ -576,7 +576,7 @@ namespace OpenRA.Support } } - public VariableExpression(string expression) + protected VariableExpression(string expression) { Expression = expression; } diff --git a/OpenRA.Game/Widgets/Widget.cs b/OpenRA.Game/Widgets/Widget.cs index 5d44abe8d7..6c0472e510 100644 --- a/OpenRA.Game/Widgets/Widget.cs +++ b/OpenRA.Game/Widgets/Widget.cs @@ -204,9 +204,10 @@ namespace OpenRA.Widgets public Rectangle Bounds; public Widget Parent = null; public Func IsVisible; - public Widget() { IsVisible = () => Visible; } - public Widget(Widget widget) + protected Widget() { IsVisible = () => Visible; } + + protected Widget(Widget widget) { Id = widget.Id; X = widget.X; diff --git a/OpenRA.Mods.Common/Activities/Move/Move.cs b/OpenRA.Mods.Common/Activities/Move/Move.cs index 8fb081cebc..dc488982c6 100644 --- a/OpenRA.Mods.Common/Activities/Move/Move.cs +++ b/OpenRA.Mods.Common/Activities/Move/Move.cs @@ -372,7 +372,7 @@ namespace OpenRA.Mods.Common.Activities readonly int terrainOrientationMargin; protected int progress; - public MovePart(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacing, + protected MovePart(Move move, WPos from, WPos to, WAngle fromFacing, WAngle toFacing, WRot? fromTerrainOrientation, WRot? toTerrainOrientation, int terrainOrientationMargin, int carryoverProgress, bool shouldArc, bool movingOnGroundLayer) { diff --git a/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs b/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs index 26fa1ce75f..4213b1555e 100644 --- a/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs +++ b/OpenRA.Mods.Common/Orders/GlobalButtonOrderGenerator.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Orders { readonly string order; - public GlobalButtonOrderGenerator(string order) + protected GlobalButtonOrderGenerator(string order) { this.order = order; } diff --git a/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs b/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs index 0f1245a9cf..8b241da1c3 100644 --- a/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs +++ b/OpenRA.Mods.Common/Orders/UnitOrderTargeter.cs @@ -20,7 +20,7 @@ namespace OpenRA.Mods.Common.Orders readonly string cursor; readonly bool targetEnemyUnits, targetAllyUnits; - public UnitOrderTargeter(string order, int priority, string cursor, bool targetEnemyUnits, bool targetAllyUnits) + protected UnitOrderTargeter(string order, int priority, string cursor, bool targetEnemyUnits, bool targetAllyUnits) { OrderID = order; OrderPriority = priority; diff --git a/OpenRA.Mods.Common/Traits/AffectsShroud.cs b/OpenRA.Mods.Common/Traits/AffectsShroud.cs index fd07c9d1cd..a0e152dc60 100644 --- a/OpenRA.Mods.Common/Traits/AffectsShroud.cs +++ b/OpenRA.Mods.Common/Traits/AffectsShroud.cs @@ -54,7 +54,7 @@ namespace OpenRA.Mods.Common.Traits protected abstract void AddCellsToPlayerShroud(Actor self, Player player, PPos[] uv); protected abstract void RemoveCellsFromPlayerShroud(Actor self, Player player); - public AffectsShroud(AffectsShroudInfo info) + protected AffectsShroud(AffectsShroudInfo info) : base(info) { if (Info.Type == VisibilityType.Footprint) diff --git a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs index 86f5e8d385..f0db64c6f8 100644 --- a/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs +++ b/OpenRA.Mods.Common/Traits/Attack/AttackBase.cs @@ -85,7 +85,7 @@ namespace OpenRA.Mods.Common.Traits bool wasAiming; - public AttackBase(Actor self, AttackBaseInfo info) + protected AttackBase(Actor self, AttackBaseInfo info) : base(info) { this.self = self; diff --git a/OpenRA.Mods.Common/Traits/Conditions/ConditionalTrait.cs b/OpenRA.Mods.Common/Traits/Conditions/ConditionalTrait.cs index 87c14094e2..d85958a7e8 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/ConditionalTrait.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/ConditionalTrait.cs @@ -52,7 +52,7 @@ namespace OpenRA.Mods.Common.Traits [Sync] public bool IsTraitDisabled { get; private set; } - public ConditionalTrait(InfoType info) + protected ConditionalTrait(InfoType info) { Info = info; diff --git a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnLayer.cs b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnLayer.cs index 3c7c3377ae..447b63c105 100644 --- a/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnLayer.cs +++ b/OpenRA.Mods.Common/Traits/Conditions/GrantConditionOnLayer.cs @@ -26,7 +26,7 @@ namespace OpenRA.Mods.Common.Traits protected readonly byte ValidLayerType; protected int conditionToken = Actor.InvalidConditionToken; - public GrantConditionOnLayer(InfoType info, byte validLayer) + protected GrantConditionOnLayer(InfoType info, byte validLayer) : base(info) { ValidLayerType = validLayer; diff --git a/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs b/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs index 3dd52d3c9c..c4cc242ed8 100644 --- a/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs +++ b/OpenRA.Mods.Common/Traits/Render/SelectionDecorationsBase.cs @@ -31,7 +31,7 @@ namespace OpenRA.Mods.Common.Traits.Render DeveloperMode developerMode; - public SelectionDecorationsBase(SelectionDecorationsBaseInfo info) + protected SelectionDecorationsBase(SelectionDecorationsBaseInfo info) { Info = info; } diff --git a/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs b/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs index 1798f4555c..6e5e6aca8e 100644 --- a/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs +++ b/OpenRA.Mods.Common/Traits/Render/WithDecorationBase.cs @@ -61,7 +61,7 @@ namespace OpenRA.Mods.Common.Traits.Render int2 conditionalOffset; BlinkState[] blinkPattern; - public WithDecorationBase(Actor self, InfoType info) + protected WithDecorationBase(Actor self, InfoType info) : base(info) { Self = self; diff --git a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs index 67b41e2e64..a5ca13b3ea 100644 --- a/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs +++ b/OpenRA.Mods.Common/Traits/SupportPowers/SupportPower.cs @@ -141,7 +141,7 @@ namespace OpenRA.Mods.Common.Traits [Desc("Sort order for the support power palette. Smaller numbers are presented earlier.")] public readonly int SupportPowerPaletteOrder = 9999; - public SupportPowerInfo() { OrderName = GetType().Name + "Order"; } + protected SupportPowerInfo() { OrderName = GetType().Name + "Order"; } } public class SupportPower : PausableConditionalTrait diff --git a/OpenRA.Mods.Common/TraitsInterfaces.cs b/OpenRA.Mods.Common/TraitsInterfaces.cs index 3d18bbd579..423928baf2 100644 --- a/OpenRA.Mods.Common/TraitsInterfaces.cs +++ b/OpenRA.Mods.Common/TraitsInterfaces.cs @@ -569,7 +569,7 @@ namespace OpenRA.Mods.Common.Traits public readonly string Name; public readonly int DisplayOrder; - public EditorActorOption(string name, int displayOrder) + protected EditorActorOption(string name, int displayOrder) { Name = name; DisplayOrder = displayOrder; diff --git a/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs index 088efa780f..f0206ea8d0 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/Editor/CommonSelectorLogic.cs @@ -46,7 +46,7 @@ namespace OpenRA.Mods.Common.Widgets.Logic protected string[] allCategories; protected string searchFilter; - public CommonSelectorLogic(Widget widget, ModData modData, World world, WorldRenderer worldRenderer, string templateListId, string previewTemplateId) + protected CommonSelectorLogic(Widget widget, ModData modData, World world, WorldRenderer worldRenderer, string templateListId, string previewTemplateId) { Widget = widget; ModData = modData;