Exemplo n.º 1
0
        /// <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 is 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();
                    // The second half of this if is needed because priority defaults to -1
                    // This causes the value of a HarmonyPriority attribute to be overriden by the next attribute if it is not merged last
                    // should be removed by making priority nullable and default to null at some point
                    if (val is object && (f != nameof(HarmonyMethod.priority) || (int)val != -1))
                    {
                        HarmonyMethodExtensions.SetValue(resultTrv, f, val);
                    }
                });
            });
            return(result);
        }
Exemplo n.º 2
0
        /// <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);
        }