Example #1
0
		public static FieldInfo GetField (Type type, FieldInfo field)
		{
			if (!type.IsGenericType)
				throw new ArgumentException ("Type is not a generic type", "type");

			if (type.IsGenericTypeDefinition)
				throw new ArgumentException ("Type cannot be a generic type definition", "type");

			if (field is FieldOnTypeBuilderInst)
				throw new ArgumentException ("The specified field must be declared on a generic type definition.", "field");

			if (field.DeclaringType != type.GetGenericTypeDefinition ())
				throw new ArgumentException ("field declaring type is not the generic type definition of type", "method");

			FieldInfo res = type.GetField (field);
			if (res == null)
				throw new System.Exception ("field not found");
			else
				return res;
		}