This repository has been archived on 2023-09-13. You can view files and clone it, but cannot push or open issues or pull requests.
station_obscurum_unity/Assets/FishNet/CodeGenerating/Processing/Rpc/AttributeData.cs

68 lines
1.9 KiB
C#
Raw Normal View History

2023-05-31 17:32:21 +02:00
using FishNet.CodeGenerating.Helping;
using FishNet.Object.Helping;
using MonoFN.Cecil;
using System.Collections.Generic;
namespace FishNet.CodeGenerating.Processing.Rpc
{
internal static class AttributeDataExtensions
{
/// <summary>
/// Returns RpcTypes in datas.
/// </summary>
public static List<RpcType> GetRpcTypes(this List<AttributeData> datas)
{
//RpcTypes for originalMd.
List<RpcType> rpcTypes = new List<RpcType>();
foreach (AttributeData ad in datas)
rpcTypes.Add(ad.RpcType);
return rpcTypes;
}
/// <summary>
/// Gets CustomAttribute for rpcType
/// </summary>
public static CustomAttribute GetAttribute(this List<AttributeData> datas, CodegenSession session, RpcType rpcType)
{
for (int i = 0; i < datas.Count; i++)
{
if (datas[i].RpcType == rpcType)
return datas[i].Attribute;
}
session.LogError($"RpcType {rpcType} not found in datas.");
return null;
}
/// <summary>
/// Returns RpcType as flag through combining datas.
/// </summary>
/// <param name="datas"></param>
/// <returns></returns>
public static RpcType GetCombinedRpcType(this List<AttributeData> datas)
{
RpcType result = RpcType.None;
for (int i = 0; i < datas.Count; i++)
result |= datas[i].RpcType;
return result;
}
}
internal class AttributeData
{
public readonly CustomAttribute Attribute;
public readonly RpcType RpcType;
public AttributeData(CustomAttribute attribute, RpcType rpcType)
{
Attribute = attribute;
RpcType = rpcType;
}
}
}