Example #1
0
        public void NullRefPredicate()
        {
            int[] source = { 1, 3, 5 };
            RefFunc <int, bool> Predicate = null;

            Assert.Throws <ArgumentNullException>(() => source.TryGetFirstIndexOf(out _, Predicate));
        }
Example #2
0
        /// <summary>
        /// 更新对象,返回非空字符串终止更新
        /// </summary>
        /// <param name="where"></param>
        /// <param name="handler"></param>
        /// <returns></returns>
        public string UpdateSingleEntity(Expression <Func <T, bool> > where, RefFunc <T, string> handler)
        {
            var list = _DalBase.GetList(where, 2);

            if (!ValidateHelper.IsPlumpList(list))
            {
                return("数据不存在");
            }
            if (list.Count() > 1)
            {
                return("当前条件下有多条记录");
            }
            var model = list[0];
            var err   = handler.Invoke(ref model);

            if (ValidateHelper.IsPlumpString(err))
            {
                return(err);
            }
            err = CheckModel(model);
            if (ValidateHelper.IsPlumpString(err))
            {
                return(err);
            }
            return(_DalBase.Update(model) > 0 ? SUCCESS : "更新失败");
        }
        /// <summary>
        /// Computes a list of adjacent windowed hysteron operators that fit into a given period sampled at a given interval.
        /// </summary>
        /// <param name="hysteronCount">Identifies the desired number of adjacent windowed hysteron operators</param>
        /// <param name="period">Identifies the size of the adjacent windowed hysteron list</param>
        /// <param name="interval">Identifies the sampling interval</param>
        /// <param name="minHysteronWidth">Identifies the minimum hysteron width in normalized coordinates</param>
        /// <param name="minEndpointWidth">Identifies the minimum width of the left margin of the first template and the right margin of the last template in normalized coordinates</param>
        /// <returns>A list of hysteron operators</returns>
        public static IEnumerable <Func <int, int> > CreateFunctions(int hysteronCount, int period, int interval = 1, int minHysteronWidth = 2, int minEndpointWidth = 1)
        {
            int pos = 0;

            foreach (var template in CreateTemplates(period / interval, hysteronCount, minHysteronWidth, minEndpointWidth))
            {
                var delay = interval * (pos + template[0]);
                var width = interval * template[1];
                RefFunc <int, int, int> hf = (ref int state, int x) => MathEx.Hysteron(ref state, x - delay, width);
                yield return(new Int32StateFunctionAdaptor(hf).F);

                pos += template.Sum();
            }
        }
Example #4
0
    static void Main()
    {
        MethodInfo method = typeof(Foo).GetMethod
                                ("DemoMethod", BindingFlags.Instance | BindingFlags.Public,
                                null, new Type[] {}, null);
        RefFunc <Foo, string> func = (RefFunc <Foo, string>)
                                     Delegate.CreateDelegate(typeof(RefFunc <Foo, string>),
                                                             null,
                                                             method);

        Foo    y = new Foo("hello");
        string x = func(ref y);

        Console.WriteLine(x);
    }
Example #5
0
        public static void DoCellByCell <TTarget, TSource>
        (
            this TensorOld <TTarget> target,
            TensorOld <TSource> source,
            RefFunc <TTarget, TSource> operation)
        {
            target.CheckEqualDimensions(source);
            TTarget t = default(TTarget);

            for (int i = 0; i < target.TheSpan.NumberSubArrays; i++)
            {
                operation(ref t, source.TheSpan[i]);
                target.TheSpan[i] = t;
            }
        }
Example #6
0
        public static void RemoveAllWithRef <T>(this IList <T> self, RefFunc <T, bool> func)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }

            for (int i = 0; i < self.Count; ++i)
            {
                var item = self[i];
                if (func(ref item))
                {
                    self.Remove(item);
                    --i;
                }
            }
        }
Example #7
0
        /// <summary>
        /// 構造体で保存されているリストに対して参照を渡して条件を見て削除する
        /// </summary>
        public static void RemoveOnceWithRef <T>(this IList <T> self, RefFunc <T, bool> func)
        {
            if (func == null)
            {
                throw new ArgumentNullException(nameof(func));
            }

            for (int i = 0; i < self.Count; ++i)
            {
                var item = self[i];
                if (func(ref item))
                {
                    // 削除して終わり
                    self.RemoveAt(i);
                    return;
                }
            }
        }
Example #8
0
		/// <summary>
		/// Passes an "out" parameter to a function taking a "ref" parameter.
		/// </summary>
		/// <param name="r">"out" reference.</param>
		/// <param name="func">The function taking the reference.</param>
		/// <returns>The value returned by <paramref name="func"/>.</returns>
		public static TRet OutToRef<T, TRet>(out T r, RefFunc<T, TRet> func)
		{
			return RefToOutFunc<T, TRet>(func)(out r);
		}
Example #9
0
    // Updates time, checks if over and applies correct behaviour
    void BehaviourChecks(RefFunc BehaveFunc, float _maxTime, float _minTime, float _randChance)
    {
        _counter += Time.deltaTime;

        if(_counter >= _maxTime)
        {
            _currentBehaviour = _behaviourPattern;
            _counter = 0f;
        }
        else
        {
            if(ChangeBCheck(_randChance) && _counter >= _minTime)
            {
                ToggleIdleBehaviour();
            }
            else
            {
                BehaveFunc();
            }
        }
    }
Example #10
0
		/// <summary>
		/// Obtains the reference to a boxed value.
		/// </summary>
		/// <param name="boxed">The boxed value.</param>
		/// <param name="func">The function to receive the reference.</param>
		/// <returns>The value returned by <paramref name="func"/></returns>
		public static TRet GetBoxedData<T, TRet>(ValueType boxed, RefFunc<T, TRet> func) where T : struct
		{
			return CacheHelper<T>.WithRet<TRet>.Unbox(boxed, func);
		}
Example #11
0
		/// <summary>
		/// Creates a null reference.
		/// </summary>
		/// <param name="func">The function to receive the reference.</param>
		/// <returns>The value returned by <paramref name="func"/></returns>
		public static TRet Null<T, TRet>(RefFunc<T, TRet> func)
		{
			return CacheHelper<T>.WithRet<TRet>.LoadNull(func);
		}
Example #12
0
		/// <summary>
		/// Converts a function taking an "ref" parameter to a function taking a "out" parameter.
		/// </summary>
		/// <param name="func">The function to be converted.</param>
		/// <returns>The converted function.</returns>
		public static OutFunc<T, TRet> RefToOutFunc<T, TRet>(RefFunc<T, TRet> func)
		{
			return (OutFunc<T, TRet>)Delegate.CreateDelegate(TypeOf<OutFunc<T, TRet>>.TypeID, func.Target, func.Method);
		}
Example #13
0
		/// <summary>
		/// Pins a "ref" reference, so its internal address doesn't change.
		/// </summary>
		/// <param name="variable">The reference.</param>
		/// <param name="func">The function to receive the pinned reference.</param>
		/// <returns></returns>
		/// <returns>The value returned by <paramref name="func"/></returns>
		public static TRet Pin<T, TRet>(ref T variable, RefFunc<T, TRet> func)
		{
			return CacheHelper<T>.WithRet<TRet>.Pin(out variable, func);
		}
Example #14
0
 public DelegateRefFuncToStructOperatorFunc(RefFunc <T0, T1> func) => Func = func;
Example #15
0
 public static TReturn Invoker <T1, TReturn>(RefFunc <T1, TReturn> action, T1 value)
 {
     return(action(value));
 }
Example #16
0
 private static void RefFunc_Method <T, R>(RefFunc <T, R> refFunc)
 {
 }
Example #17
0
 public Int32StateFunctionAdaptor(RefFunc <int, int, int> f, int state = 0)
 {
     _f     = f;
     _state = state;
 }
Example #18
0
#pragma warning restore CS0246 // The type or namespace name 'RefFunc<,,>' could not be found (are you missing a using directive or an assembly reference?)

#pragma warning disable CS0246 // The type or namespace name 'RefFunc<,,>' could not be found (are you missing a using directive or an assembly reference?)
        public Int32StateFunctionAdaptor(RefFunc <int, int, int> f, int state = 0)
#pragma warning restore CS0246 // The type or namespace name 'RefFunc<,,>' could not be found (are you missing a using directive or an assembly reference?)
        {
            this._f     = f;
            this._state = state;
        }