Example #1
0
        /// <summary>
        /// Evals the static method.
        /// </summary>
        /// <param name="dateRule">The date rule.</param>
        /// <param name="assemblyName">Name of the assembly.</param>
        /// <param name="nameSpace">The name space.</param>
        /// <param name="className">Name of the class.</param>
        /// <param name="staticMethodName">Name of the static method.</param>
        /// <param name="parameterObject">The parameter object.</param>
        /// <returns></returns>
        internal static SignificantDay[] EvalStaticMethod(DateRule dateRule, string assemblyName, string nameSpace, string className, string staticMethodName, object[] parameterObject)
        {
            SignificantDay[] sds;
            Assembly         assembly = Assembly.Load(assemblyName);
            Type             myClass  = assembly.GetType($"{nameSpace}.{className}");
            object           dteval   = myClass.InvokeMember(staticMethodName, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.FlattenHierarchy, null, null, parameterObject);
            var sd = new SignificantDay();

            if (dteval is DateTime)
            {
                sd.Date = (DateTime)dteval;
                sds     = new[] { sd };
            }
            else
            {
                if (dteval is SignificantDay day)
                {
                    sds = new[] { day };
                }
                else
                {
                    sds = (SignificantDay[])dteval;
                }
            }
            return(sds);
        }
Example #2
0
        /// <summary>
        /// Evaluates the static method.
        /// </summary>
        /// <param name="nameSpace">The name space.</param>
        /// <param name="className">Name of the class.</param>
        /// <param name="staticMethodName">Name of the static method.</param>
        /// <param name="parameterObject">The parameter object.</param>
        /// <returns></returns>
        internal static SignificantDay[] EvalStaticMethod(string nameSpace, string className, string staticMethodName, object[] parameterObject)
        {
            SignificantDay[] sds;
            var  assembly = Assembly.GetExecutingAssembly();
            Type myClass  = assembly.GetType($"{nameSpace}.{className}");

            if (myClass == null)
            {
                throw new InvalidOperationException($"Class {nameSpace}.{className} could not be loaded.");
            }
            object dateValue = myClass.InvokeMember(staticMethodName, BindingFlags.Public | BindingFlags.InvokeMethod | BindingFlags.Static | BindingFlags.FlattenHierarchy, null, null, parameterObject);
            var    sd        = new SignificantDay();

            if (dateValue is DateTime time)
            {
                sd.Date = time;
                sds     = new[] { sd };
            }
            else
            {
                if (dateValue is SignificantDay day)
                {
                    sds = new[] { day };
                }
                else
                {
                    sds = (SignificantDay[])dateValue;
                }
            }
            return(sds);
        }