using FishNet.CodeGenerating.Extension;
using MonoFN.Cecil;
namespace FishNet.CodeGenerating.Helping.Extension
{
internal static class FieldReferenceExtensions
{
///
/// Gets a Resolve favoring cached results first.
///
internal static FieldDefinition CachedResolve(this FieldReference fieldRef, CodegenSession session)
{
return session.GetClass().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);
}
}
}
}