38 lines
1.0 KiB
C#
38 lines
1.0 KiB
C#
|
using FishNet.CodeGenerating.Extension;
|
|||
|
using MonoFN.Cecil;
|
|||
|
|
|||
|
namespace FishNet.CodeGenerating.Helping.Extension
|
|||
|
{
|
|||
|
|
|||
|
internal static class FieldReferenceExtensions
|
|||
|
{
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// Gets a Resolve favoring cached results first.
|
|||
|
/// </summary>
|
|||
|
internal static FieldDefinition CachedResolve(this FieldReference fieldRef, CodegenSession session)
|
|||
|
{
|
|||
|
return session.GetClass<GeneralHelper>().GetFieldReferenceResolve(fieldRef);
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
public static FieldReference MakeHostGenericIfNeeded(this FieldDefinition fd, CodegenSession session)
|
|||
|
{
|
|||
|
TypeReference declaringTr = fd.DeclaringType;
|
|||
|
|
|||
|
if (declaringTr.HasGenericParameters)
|
|||
|
{
|
|||
|
GenericInstanceType git = declaringTr.MakeGenericInstanceType();
|
|||
|
FieldReference result = new FieldReference(fd.Name, fd.FieldType, git);
|
|||
|
return result;
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
return session.ImportReference(fd);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|