summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Build.Tasks/FieldReferenceExtensions.cs
blob: 3876b9c8fe2db23b4e005da62aaa4c8831f2fbfe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
using Mono.Cecil;

namespace Xamarin.Forms.Build.Tasks
{
	static class FieldReferenceExtensions
	{
		public static FieldReference ResolveGenericParameters(this FieldReference self, TypeReference declaringTypeRef)
		{
			var fieldType = self.FieldType;
			if (fieldType.IsGenericParameter)
			{
				var genericParameter = (GenericParameter)fieldType;
				fieldType = ((GenericInstanceType)declaringTypeRef).GenericArguments[genericParameter.Position];
			}
			var fieldReference = new FieldReference(self.Name, fieldType)
			{
				DeclaringType = declaringTypeRef
			};
			return fieldReference;
		}
	}
}