Moves Lint checks to Mods.Common
This commit is contained in:
41
OpenRA.Mods.Common/Lint/CheckSyncAnnotations.cs
Normal file
41
OpenRA.Mods.Common/Lint/CheckSyncAnnotations.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
#region Copyright & License Information
|
||||
/*
|
||||
* Copyright 2007-2015 The OpenRA Developers (see AUTHORS)
|
||||
* This file is part of OpenRA, which is free software. It is made
|
||||
* available to you under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation. For more information,
|
||||
* see COPYING.
|
||||
*/
|
||||
#endregion
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using OpenRA.Traits;
|
||||
|
||||
namespace OpenRA.Mods.Common.Lint
|
||||
{
|
||||
class CheckSyncAnnotations : ILintPass
|
||||
{
|
||||
public void Run(Action<string> emitError, Action<string> emitWarning, Map map)
|
||||
{
|
||||
/* first, check all the types implementing ISync */
|
||||
foreach (var t in Game.ModData.ObjectCreator.GetTypesImplementing<ISync>())
|
||||
if (!HasAnySyncFields(t))
|
||||
emitWarning("{0} has ISync but nothing marked with [Sync]".F(t.Name));
|
||||
}
|
||||
|
||||
bool HasAnySyncFields(Type t)
|
||||
{
|
||||
var flags = BindingFlags.Public | BindingFlags.NonPublic
|
||||
| BindingFlags.Instance;
|
||||
|
||||
var fs = t.GetFields(flags);
|
||||
var ps = t.GetProperties(flags);
|
||||
|
||||
return fs.Any(f => f.HasAttribute<SyncAttribute>()) ||
|
||||
ps.Any(p => p.HasAttribute<SyncAttribute>()) ||
|
||||
HasAnySyncFields(t.BaseType);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user