コード例 #1
0
ファイル: CodeTranspiler.cs プロジェクト: ikbujnh/Harmony
		internal static IEnumerable ConvertToOurInstructions(IEnumerable instructions, Type codeInstructionType, List<object> originalInstructions, Dictionary<object, Dictionary<string, object>> unassignedValues)
		{
			var newInstructions = instructions.Cast<object>().ToList();

			var index = -1;
			foreach (var op in newInstructions)
			{
				index++;
				var elementTo = AccessTools.MakeDeepCopy(op, codeInstructionType);
				if (unassignedValues.TryGetValue(op, out var fields))
				{
					var addExceptionInfo = ShouldAddExceptionInfo(op, index, originalInstructions, newInstructions, unassignedValues);

					var trv = Traverse.Create(elementTo);
					foreach (var field in fields)
					{
						if (addExceptionInfo || field.Key != nameof(CodeInstruction.blocks))
							_ = trv.Field(field.Key).SetValue(field.Value);
					}
				}
				yield return elementTo;
			}
		}
コード例 #2
0
ファイル: HarmonyMethod.cs プロジェクト: yakiu1/Harmony
        /// <summary>Merges annotations</summary>
        /// <param name="attributes">The list of <see cref="HarmonyMethod"/> to merge</param>
        /// <returns>The merged <see cref="HarmonyMethod"/></returns>
        ///
        public static HarmonyMethod Merge(List <HarmonyMethod> attributes)
        {
            var result = new HarmonyMethod();

            if (attributes == null)
            {
                return(result);
            }
            var resultTrv = Traverse.Create(result);

            attributes.ForEach(attribute =>
            {
                var trv = Traverse.Create(attribute);
                HarmonyFields().ForEach(f =>
                {
                    var val = trv.Field(f).GetValue();
                    if (val != null)
                    {
                        HarmonyMethodExtensions.SetValue(resultTrv, f, val);
                    }
                });
            });
            return(result);
        }