build.cs里使用反射查询字段的存在性

private bool FindProperty(string ProName)
{
    Type type = typeof(ModuleRules); // 替换YourClass为具体的类名
    PropertyInfo[] properties = type.GetProperties();
    foreach (PropertyInfo property in properties)
    {
        if (property.Name == ProName)
        {
            PropertyInfo FoundProperty = type.GetProperty(ProName);
            FoundProperty.SetValue(this, WarningLevel.Off);
            return true;
        }
    }
    return false;
}

预定义宏判断引擎版本

// {UERoot}\Engine\Source\Programs\UnrealBuildTool\System\RulesAssembly.cs
public static List<string> GetPreprocessorDefinitions()
		{
			List<string> PreprocessorDefines = new List<string>();
			PreprocessorDefines.Add("WITH_FORWARDED_MODULE_RULES_CTOR");
			PreprocessorDefines.Add("WITH_FORWARDED_TARGET_RULES_CTOR");

			// Define macros for the Unreal engine version, starting with 4.17
			// Assumes the current MajorVersion is 5
			BuildVersion? Version;
			if (BuildVersion.TryRead(BuildVersion.GetDefaultFileName(), out Version))
			{
				for (int MinorVersion = 17; MinorVersion <= 30; MinorVersion++)
				{
					PreprocessorDefines.Add(String.Format("UE_4_{0}_OR_LATER", MinorVersion));
				}
				for (int MinorVersion = 0; MinorVersion <= Version.MinorVersion; MinorVersion++)
				{
					PreprocessorDefines.Add(String.Format("UE_5_{0}_OR_LATER", MinorVersion));
				}
			}
			return PreprocessorDefines;
		}