当前位置: 首页>>代码示例>>C#>>正文


C# Func.ShouldNotBeNull方法代码示例

本文整理汇总了C#中Func.ShouldNotBeNull方法的典型用法代码示例。如果您正苦于以下问题:C# Func.ShouldNotBeNull方法的具体用法?C# Func.ShouldNotBeNull怎么用?C# Func.ShouldNotBeNull使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Func的用法示例。


在下文中一共展示了Func.ShouldNotBeNull方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Integrate

        /// <summary>
        /// 함수의 [a,b] 구간을 적분합니다.
        /// </summary>
        /// <param name="func">적분할 함수</param>
        /// <param name="a">적분 시작 위치</param>
        /// <param name="b">적분 끝 위치</param>
        /// <returns>적분 값</returns>
        public override double Integrate(Func<double, double> func, double a, double b) {
            func.ShouldNotBeNull("func");

            if(IsDebugEnabled)
                log.Debug(@"사다리꼴 적분법(Trapizoidal)을 이용하여 적분을 수행합니다. func=[{0}], a=[{1}], b=[{2}]", func, a, b);

            func.ShouldNotBeNull("func");

            if(a > b) MathTool.Swap<double>(ref a, ref b);

            double result = 0;

            int n = GetSteps(a, b);
            double h = (b - a) / n;
            double x = a;

            Parallel.For(1, n, () => 0.0, (i, loopState, local) => local + func(a + h * i),
                         local => { lock(_syncLock) result += local; });

            //for(int i = 1; i < n; i++)
            //{
            //    x += h;
            //    result += func(x);
            //}

            result = h * ((func(a) + func(b)) / 2 + result);

            if(IsDebugEnabled)
                log.Debug(@"적분결과=[{0}]", result);

            return result;
        }
开发者ID:debop,项目名称:NFramework,代码行数:39,代码来源:TrapizoidalIntegrator.cs

示例2: Mapping

        /// <summary>
        /// 컬럼명=속성명 매핑함수를 이용하여 지정된 DataReader의 컬럼명을 속성명으로 매핑한다.
        /// </summary>
        /// <param name="reader">instance of IDataReader</param>
        /// <param name="mappingFunc">mapping function</param>
        /// <param name="propertyNamesToExclude">매핑에서 제외할 속성명</param>
        /// <returns>instance of <see cref="INameMap"/></returns>
        public static INameMap Mapping(this IDataReader reader, Func<string, string> mappingFunc, params string[] propertyNamesToExclude) {
            reader.ShouldNotBeNull("reader");
            mappingFunc.ShouldNotBeNull("mappingFunc");

            if(IsDebugEnabled)
                log.Debug("지정된 DataReader의 컬럼명을 속성명으로 매핑합니다...");

            var nameMap = new NameMap();
            var excludeNames = (propertyNamesToExclude != null) ? propertyNamesToExclude.ToList() : new List<string>();

            for(int i = 0; i < reader.FieldCount; i++) {
                var columnName = reader.GetName(i);

                if(columnName.IsNotWhiteSpace()) {
                    var propertyName = mappingFunc(columnName);

                    if(propertyName.IsNotWhiteSpace() && excludeNames.Contains(propertyName, StringComparer.Ordinal) == false)
                        nameMap.Add(columnName, propertyName);
                }
            }

            if(IsDebugEnabled)
                log.Debug("컬럼명-속성명 매핑 결과 = " + nameMap.CollectionToString());

            return nameMap;
        }
开发者ID:debop,项目名称:NFramework,代码行数:33,代码来源:NameMappingUtil.cs

示例3: FindRoot

        /// <summary>
        /// y = func(x) 함수의 [lower, upper] 구간에 대해, 근을 찾는다 ( func(x) = 0 인 x 값 )
        /// </summary>
        /// <param name="func">근을 찾을 함수</param>
        /// <param name="lower">근을 찾을 구간의 하한</param>
        /// <param name="upper">근을 찾을 구간의 상한</param>
        /// <param name="tryCount">시도 횟수</param>
        /// <param name="tolerance">근의 오차허용범위</param>
        /// <returns>근에 해당하는 x 값. 해를 못찾으면 <see cref="double.NaN"/>을 반환한다.</returns>
        public override double FindRoot(Func<double, double> func,
                                        double lower,
                                        double upper,
                                        int tryCount = MathTool.DefaultTryCount,
                                        double tolerance = MathTool.Epsilon) {
            func.ShouldNotBeNull("func");
            tolerance = Math.Abs(tolerance);

            if(IsDebugEnabled)
                log.Debug(@"Find root by NewtonRapson... func=[{0}], lower=[{1}], upper=[{2}], tryCount=[{3}], tolerance=[{4}]",
                          func, lower, upper, tryCount, tolerance);

            if(tryCount < DefaultTryCount)
                tryCount = DefaultTryCount;

            double x = (lower + upper) / 2;

            if(Math.Abs(func(x).Clamp(RootY, tolerance) - RootY) < double.Epsilon)
                return x;

            for(int i = 0; i < tryCount; i++) {
                double prevX = x;
                x -= func(x) / gfunc(func, x);

                if(IsDebugEnabled)
                    log.Debug(@"root value=[{0}]", x);

                if(Math.Abs(x - prevX) < Math.Abs(prevX) * tolerance)
                    return x;
            }
            return double.NaN;
        }
开发者ID:debop,项目名称:NFramework,代码行数:41,代码来源:NewtonRapsonRootFinder.cs

示例4: FindRoot

        /// <summary>
        /// 이분법으로 y = func(x) 함수의 [lower, upper] 구간에 대해, 근을 찾는다 (y=0 이되는 x 값)
        /// </summary>
        /// <param name="func">근을 찾을 함수</param>
        /// <param name="lower">근을 찾을 구간의 하한</param>
        /// <param name="upper">근을 찾을 구간의 상한</param>
        /// <param name="tryCount">시도 횟수</param>
        /// <param name="tolerance">근의 오차허용범위</param>
        /// <returns>근에 해당하는 x 값. 해를 못찾으면 <see cref="double.NaN"/>을 반환한다.</returns>
        public override double FindRoot(Func<double, double> func,
                                        double lower,
                                        double upper,
                                        int tryCount = MathTool.DefaultTryCount,
                                        double tolerance = MathTool.Epsilon) {
            func.ShouldNotBeNull("func");
            tolerance = Math.Abs(tolerance);

            if(IsDebugEnabled)
                log.Debug("Bisection을 이용하여, root 값을 찾습니다... func=[{0}], lower=[{1}], upper=[{2}], tryCount=[{3}], tolerance=[{4}]",
                          func, lower, upper, tryCount, tolerance);

            if(lower > upper)
                MathTool.Swap(ref lower, ref upper);

            var fa = func(lower);
            var fb = func(upper);

            if(Math.Abs(fa - RootY) < tolerance)
                return lower;
            if(Math.Abs(fb - RootY) < tolerance)
                return upper;

            Guard.Assert(Math.Abs(lower - upper) > tolerance, "상하한이 같은 값을 가지면 근을 구할 수 없습니다.");

            if(tryCount < DefaultTryCount)
                tryCount = DefaultTryCount;

            for(var k = 0; k < tryCount; k++) {
                var x = (lower + upper) / 2.0;

                if(Math.Abs(upper - x) < tolerance || Math.Abs(lower - x) < tolerance)
                    return x;

                var y = func(x);

                if(IsDebugEnabled)
                    log.Debug(@"Find root...  x=[{0}], y=[{1}]", x, y);

                // 해를 만족하던가, upper-lower의 변화가 매우 작던가..
                if(Math.Abs(y - RootY) < tolerance) {
                    if(IsDebugEnabled)
                        log.Debug("Iteration count=[{0}]", k);

                    return x;
                }

                if(fa * y > 0) {
                    lower = x;
                    fa = y;
                }
                else {
                    upper = x;
                    fb = y;
                }
            }

            return double.NaN;
        }
开发者ID:debop,项目名称:NFramework,代码行数:68,代码来源:BisectionRootFinder.cs

示例5: Weibull

        /// <summary>
        /// Initializes a new instance of the Weibull class.
        /// </summary>
        /// <param name="shape">The shape of the Weibull distribution.</param>
        /// <param name="scale">The scale of the Weibull distribution.</param>
        /// <param name="randomFactory">난수발생기 Factory</param>
        public Weibull(double shape, double scale, Func<Random> randomFactory = null) {
            randomFactory.ShouldNotBeNull("randomFactory");

            if(IsDebugEnabled)
                log.Debug(@"Weibull 분포를 표현하는 인스턴스를 생성했습니다. shape=[{0}], scale=[{1}]", shape, scale);

            SetParameters(shape, scale);
            _random = (randomFactory != null) ? randomFactory() : MathTool.GetRandomFactory().Invoke();
        }
开发者ID:debop,项目名称:NFramework,代码行数:15,代码来源:Weibull.cs

示例6: FindRoot

        /// <summary>
        /// y = func(x) 함수의 [lower, upper] 구간에 대해, 근을 찾는다 ( func(x) = 0 인 x 값 )
        /// </summary>
        /// <param name="func">근을 찾을 함수</param>
        /// <param name="lower">근을 찾을 구간의 하한</param>
        /// <param name="upper">근을 찾을 구간의 상한</param>
        /// <param name="tryCount">시도 횟수</param>
        /// <param name="tolerance">근의 오차허용범위</param>
        /// <returns>근에 해당하는 x 값. 해를 못찾으면 <see cref="double.NaN"/>을 반환한다.</returns>
        public override double FindRoot(Func<double, double> func,
                                        double lower,
                                        double upper,
                                        int tryCount = MathTool.DefaultTryCount,
                                        double tolerance = MathTool.Epsilon) {
            func.ShouldNotBeNull("func");
            tolerance = Math.Abs(tolerance);

            if(IsDebugEnabled)
                log.Debug(@"Find root by Secant... func=[{0}], lower=[{1}], upper=[{2}], tryCount=[{3}], tolerance=[{4}]",
                          func, lower, upper, tryCount, tolerance);

            if(lower > upper)
                MathTool.Swap(ref lower, ref upper);

            if(Math.Abs(func(lower).Clamp(RootY, tolerance) - RootY) < double.Epsilon)
                return lower;
            if(Math.Abs(func(upper).Clamp(RootY, tolerance) - RootY) < double.Epsilon)
                return upper;

            if(tryCount < DefaultTryCount)
                tryCount = DefaultTryCount;

            double root, xt;
            var y1 = func(lower);
            var y2 = func(upper);

            if(Math.Abs(y1) < Math.Abs(y2)) {
                root = lower;
                xt = upper;

                MathTool.Swap(ref y1, ref y2);
            }
            else {
                xt = lower;
                root = upper;
            }

            for(var i = 0; i < tryCount; i++) {
                var dx = (xt - root) * y2 / (y2 - y1);
                xt = root;
                y1 = y2;
                root += dx;
                y2 = func(root);

                if(IsDebugEnabled)
                    log.Debug(@"Secant root=[{0}]", root);

                if((Math.Abs(dx - RootY) < double.Epsilon) || (Math.Abs((y2 - y1) - RootY) < double.Epsilon))
                    return root;
                // if(Math.Abs(Math.Abs(dx).Clamp(RootY, tolerance) - RootY) < double.Epsilon || Math.Abs(Math.Abs(y2 - y1).Clamp(RootY, tolerance) - RootY) < double.Epsilon)
                //		return root;
            }

            return double.NaN;
        }
开发者ID:debop,项目名称:NFramework,代码行数:65,代码来源:SecantRootFinder.cs

示例7: FindMiminum

        /// <summary>
        /// y = func(x) 함수의 [lower, upper] 구간에서 f(x)의 최소 값이 되는 x를 구합니다.
        /// </summary>
        /// <param name="func">함수</param>
        /// <param name="lower">구간의 하한</param>
        /// <param name="upper">구간의 상한</param>
        /// <param name="tryCount">시도횟수</param>
        /// <param name="tolerance">허용 오차</param>
        /// <returns>f(x)가 최소값이 되는 x 값, 검색 실패시에는 double.NaN을 반환한다</returns>
        public override double FindMiminum(Func<double, double> @func,
                                           double lower,
                                           double upper,
                                           int tryCount = MathTool.DefaultTryCount,
                                           double tolerance = MathTool.Epsilon) {
            @func.ShouldNotBeNull("func");
            tolerance = Math.Abs(tolerance);

            if(IsDebugEnabled)
                log.Debug("Find root by GoldenSectionMinimumFinder... " +
                          "func=[{0}], lower=[{1}], upper=[{2}], tryCount=[{3}], tolerance=[{4}]",
                          func, lower, upper, tryCount, tolerance);

            if(tryCount < MathTool.DefaultTryCount)
                tryCount = MathTool.DefaultTryCount;

            if(lower > upper)
                MathTool.Swap(ref lower, ref upper);

            var t = GodenRatio * (upper - lower);
            var c = lower + t;
            var d = upper - t;

            var fc = @func(c);
            var fd = @func(d);

            for(var i = 0; i < tryCount; i++) {
                if(fc > fd) {
                    lower = c;
                    c = d;
                    fc = fd;
                    d = upper - GodenRatio * (upper - lower);

                    if(Math.Abs(d - c) <= tolerance)
                        return c;

                    fd = @func(d);
                }
                else {
                    upper = d;
                    d = c;
                    fd = fc;
                    c = lower + GodenRatio * (upper - lower);

                    if(Math.Abs(d - c) <= tolerance)
                        return d;

                    fc = @func(c);
                }
            }

            return double.NaN;
        }
开发者ID:debop,项目名称:NFramework,代码行数:62,代码来源:GoldenSectionMinimumFinder.cs

示例8: Integrate

        /// <summary>
        /// 함수의 [a,b] 구간을 적분합니다.
        /// </summary>
        /// <param name="func">적분할 함수</param>
        /// <param name="a">적분 시작 위치</param>
        /// <param name="b">적분 끝 위치</param>
        /// <returns>적분 값</returns>
        public override double Integrate(Func<double, double> func, double a, double b) {
            func.ShouldNotBeNull("func");

            if(IsDebugEnabled)
                log.Debug(@"Simpson 적분법을 이용하여 적분을 수행합니다. func=[{0}], a=[{1}], b=[{2}]", func, a, b);

            func.ShouldNotBeNull("unaryFunc");

            if(a > b)
                return Integrate(func, b, a);

            _steps = GetSteps(a, b, _steps);

            double h = (b - a) / (2.0 * _steps);
            double hdiv3 = h / 3;

            double fo = 0;
            double fe = 0;

            double N = 2 * _steps - 3;

            ParallelTool.ForWithStep(1, (int)N + 1, 2, () => 0.0, (i, loopState, local) => local + func(a + h * i),
                                     local => { lock(_syncLock) fo += local; });
            ParallelTool.ForWithStep(1, (int)N + 1, 2, () => 0.0, (i, loopState, local) => local + func(a + h * (i + 1)),
                                     local => { lock(_syncLock) fe += local; });

            //for(int i = 1; i <= N; i += 2)
            //{
            //    fo += func(a + h * i); // 홀수항 (odd)
            //    fe += func(a + h * (i + 1)); // 짝수항 (even)
            //}

            var result = (func(a) + func(b) + 4.0 * (fo + func(b - h)) + 2.0 * fe) * hdiv3;

            if(IsDebugEnabled)
                log.Debug(@"적분결과=[{0}]", result);

            return result;
        }
开发者ID:debop,项目名称:NFramework,代码行数:46,代码来源:SimpsonIntegrator.cs

示例9: Integrate

        /// <summary>
        /// 함수의 [a,b] 구간을 적분합니다.
        /// </summary>
        /// <param name="func">적분할 함수</param>
        /// <param name="a">적분 시작 위치</param>
        /// <param name="b">적분 끝 위치</param>
        /// <returns>적분 값</returns>
        public override double Integrate(Func<double, double> func, double a, double b) {
            func.ShouldNotBeNull("func");

            if(IsDebugEnabled)
                log.Debug(@"중점접(MidValue)를 이용하여 적분을 수행합니다. func=[{0}], a=[{1}], b=[{2}]", func, a, b);

            func.ShouldNotBeNull("f");

            if(a > b)
                MathTool.Swap(ref a, ref b);

            int n = GetSteps(a, b, Steps);
            double h = (b - a) / n;
            double hdiv2 = h / 2;
            double n2 = n * 2;
            double result = 0;

            ParallelTool.ForWithStep(1,
                                     (int)(n2 + 1),
                                     2,
                                     () => 0.0,
                                     (i, loopState, local) => local + func(a + i * hdiv2),
                                     local => {
                                         lock(_syncLock)
                                             result += local;
                                     });

            //for(int i = 1; i < n2; i += 2)
            //    result += func(a + i * hdiv2);

            result *= h;
            if(IsDebugEnabled)
                log.Debug(@"적분 결과=[{0}]", result);

            return result;
        }
开发者ID:debop,项目名称:NFramework,代码行数:43,代码来源:MidValueIntegrator.cs

示例10: Integrate

        /// <summary>
        /// 함수의 [a,b] 구간을 적분합니다.
        /// </summary>
        /// <param name="func">적분할 함수</param>
        /// <param name="a">적분 시작 위치</param>
        /// <param name="b">적분 끝 위치</param>
        /// <returns>적분 값</returns>
        public override double Integrate(Func<double, double> func, double a, double b) {
            func.ShouldNotBeNull("func");

            if(IsDebugEnabled)
                log.Debug(@"Romberg 적분법을 이용하여 적분을 수행합니다. func=[{0}], a=[{1}], b=[{2}]", func, a, b);

            if(a > b)
                MathTool.Swap(ref a, ref b);

            if((_rom == null) || (_rom.GetLength(1) == _order))
                _rom = new double[2,_order];

            double h = (b - a);
            _rom[0, 0] = 0.5d * h * (func(a) + func(b));

            for(int i = 2, ipower = 1; i <= _order; i++, ipower *= 2, h /= 2) {
                // approximation using the trapezoid rule.
                double sum = 0;
                for(var j = 1; j <= ipower; j++)
                    sum += func(a + h * (j - 0.5));

                // Richardson extrapolation 
                _rom[1, 0] = 0.5 * (_rom[0, 0] + (h * sum));

                for(int k = 1, kpower = 4; k < i; k++, kpower *= 4)
                    _rom[1, k] = (kpower * _rom[1, k - 1] - _rom[0, k - 1]) / (kpower - 1);

                // save the extrapolated value for the next integration
                for(int j = 0; j < i; j++)
                    _rom[0, j] = _rom[1, j];
            }

            if(IsDebugEnabled)
                log.Debug(@"적분결과=[{0}]", _rom[0, _order - 1]);

            return _rom[0, _order - 1];
        }
开发者ID:debop,项目名称:NFramework,代码行数:44,代码来源:RombergIntegrator.cs

示例11: Map

        /// <summary>
        /// 원본 속성명-속성값 정보를 대상 인스턴스의 속성명에 값을 설정한다.
        /// </summary>
        /// <param name="source">원본 정보 (Name-Value)</param>
        /// <param name="targetFactory">복사 대상 인스턴스 생성 델리게이트</param>
        /// <param name="mapOptions">매핑 옵션</param>
        /// <param name="propertyNamesToExclude">복사 제외 속성 명</param>
        public static object Map(IDictionary source, Func<object> targetFactory, MapPropertyOptions mapOptions,
                                 params string[] propertyNamesToExclude) {
            targetFactory.ShouldNotBeNull("targetFactory");

            var target = targetFactory();

            if(IsDebugEnabled)
                log.Debug("원본의 속성-값을 대상 인스턴스의 속성 값으로 복사합니다... " +
                          @"source=[{0}], target=[{1}], mapOptions=[{2}], propertyNamesToExclude=[{3}]",
                          source, target, mapOptions, propertyNamesToExclude.CollectionToString());

            var excludes = new List<string>(propertyNamesToExclude);
            var accessor = DynamicAccessorFactory.CreateDynamicAccessor(target.GetType(), mapOptions.SuppressException);
            var targetPropertyNames = accessor.GetPropertyNames().Except(excludes).ToList();

            foreach(string name in source.Keys) {
                var sourceName = name;
                if(excludes.Any(epn => StringTool.EqualTo(epn, sourceName)))
                    continue;

                var canSetPropertyValue = targetPropertyNames.Any(tpn => StringTool.EqualTo(tpn, sourceName));

                if(canSetPropertyValue) {
                    if(mapOptions.IgnoreCase) {
                        var targetPropertyName = targetPropertyNames.FirstOrDefault(tpn => StringTool.EqualTo(tpn, sourceName));

                        if(targetPropertyName.IsNotWhiteSpace())
                            accessor.SetPropertyValue(target, targetPropertyName, source[sourceName]);
                    }
                    else {
                        accessor.SetPropertyValue(target, sourceName, source[sourceName]);
                    }
                }
            }
            return target;
        }
开发者ID:debop,项目名称:NFramework,代码行数:43,代码来源:ObjectMapper.Map.cs

示例12: GoldenSection

        // Methods
        public GoldenSection(Func<double, double> func, double a, double b, int n) {
            func.ShouldNotBeNull("func");

            int num = 0;
            double num2 = 0.0;
            double num3 = 0.0;
            double x = 0.0;
            double num5 = 0.0;
            double num6 = 0.0;
            double num7 = 0.0;

            num2 = (3.0 - Math.Sqrt(5.0)) / 2.0;
            num3 = (Math.Sqrt(5.0) - 1.0) / 2.0;
            x = a + (num2 * (b - a));
            num5 = a + (num3 * (b - a));
            num6 = func(x);
            num7 = func(num5);
            for(num = 1; num <= n; num++) {
                if(num6 <= num7) {
                    b = num5;
                    num5 = x;
                    num7 = num6;
                    x = a + (num2 * (b - a));
                    num6 = func(x);
                }
                else {
                    a = x;
                    x = num5;
                    num6 = num7;
                    num5 = a + (num3 * (b - a));
                    num7 = func(num5);
                }
            }
            resultA = a;
            resultB = b;
        }
开发者ID:debop,项目名称:NFramework,代码行数:37,代码来源:GoldenSection.cs

示例13: Pareto

        public Pareto(double scale, double shape, Func<Random> randomFactory = null) {
            SetParameters(scale, shape);

            randomFactory.ShouldNotBeNull("randomFactory");
            _random = randomFactory();
        }
开发者ID:debop,项目名称:NFramework,代码行数:6,代码来源:Pareto.cs

示例14: Enqueue

 /// <summary>
 /// 지정한 작업 생성 함수로 생성되는 작업을 순차 수행을 위한 작업 큐에 넣습니다.
 /// </summary>
 /// <param name="taskFactory"></param>
 public void Enqueue(Func<Task> taskFactory) {
     taskFactory.ShouldNotBeNull("taskFactory");
     EnqueueInternal(taskFactory);
 }
开发者ID:debop,项目名称:NFramework,代码行数:8,代码来源:SerialTaskQueue.cs

示例15: CompressAdapter

 public CompressAdapter(Func<ICompressor> @compressorFactory) {
     @compressorFactory.ShouldNotBeNull("compressorFactory");
     @_compressorFactory = @compressorFactory;
 }
开发者ID:debop,项目名称:NFramework,代码行数:4,代码来源:CompressAdapter.cs


注:本文中的Func.ShouldNotBeNull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。