示例#1
0
        public static int EnumArraySpan(ArraySpan <char> str)
        {
            int x = 0;

            for (int i = 0, len = str.Length; i < len; i++)
            {
                x += str[i];
            }
            return(x);
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyAdviceContext"/> class.
 /// </summary>
 /// <param name="propertyAdvice">The property advice.</param>
 /// <param name="propertyInfo">The property information.</param>
 /// <param name="isSetter">if set to <c>true</c> [is setter].</param>
 /// <param name="adviceValues">The advice values.</param>
 /// <param name="nextAdviceContext">The next advice context.</param>
 /// <exception cref="System.InvalidOperationException">Only properties can be advised with this interface</exception>
 internal PropertyAdviceContext(IPropertyAdvice propertyAdvice, PropertyInfo propertyInfo, bool isSetter, AdviceValues adviceValues, AdviceContext nextAdviceContext)
     : base(adviceValues, nextAdviceContext)
 {
     _propertyAdvice = propertyAdvice;
     TargetProperty = propertyInfo;
     IsSetter = isSetter;
     if (IsGetter)
         Index = new ArraySpan<object>(AdviceValues.Parameters, 0, AdviceValues.Parameters.Length);
     else
         Index = new ArraySpan<object>(AdviceValues.Parameters, 1, AdviceValues.Parameters.Length - 1);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="PropertyAdviceContext"/> class.
 /// </summary>
 /// <param name="propertyAdvice">The property advice.</param>
 /// <param name="propertyInfo">The property information.</param>
 /// <param name="isSetter">if set to <c>true</c> [is setter].</param>
 /// <param name="adviceValues">The advice values.</param>
 /// <param name="nextAdviceContext">The next advice context.</param>
 internal PropertyAdviceContext(IPropertyAdvice propertyAdvice, PropertyInfo propertyInfo, bool isSetter, AdviceValues adviceValues, AdviceContext nextAdviceContext)
     : base(adviceValues, nextAdviceContext)
 {
     _propertyAdvice = propertyAdvice;
     TargetProperty  = propertyInfo;
     IsSetter        = isSetter;
     if (IsGetter)
     {
         Index = new ArraySpan <object>(AdviceValues.Arguments, 0, AdviceValues.Arguments.Length);
     }
     else
     {
         Index = new ArraySpan <object>(AdviceValues.Arguments, 1, AdviceValues.Arguments.Length - 1);
     }
 }
示例#4
0
 public static string GetSubArraySpan(ArraySpan <char> strSpan)
 {
     return(strSpan.Slice(11, 12).ToString());
 }
示例#5
0
        public static void Main(string[] args)
        {
            const string TestStr = "aaaaaaaaaa bbbbbbbbbbbb cccccccccccc dddddddddddd eeeeeeeeee ffffffffff gggggggggg";

            long y = 0;

            for (int k = 0; k < IterNum; k++)
            {
                y += EnumPureString(TestStr);
            }

            StringSpan strSpan = TestStr;

            for (int k = 0; k < IterNum; k++)
            {
                y += EnumStringSpan(strSpan);
            }

            char[] charArr = TestStr.ToCharArray();

            for (int k = 0; k < IterNum; k++)
            {
                y += EnumPureCharArr(charArr);
            }

            ArraySpan <char> arrSpan = charArr;

            for (int k = 0; k < IterNum; k++)
            {
                y += EnumArraySpan(arrSpan);
            }

            for (int k = 0; k < IterNum; k++)
            {
                var str1 = GetSubPureStr(TestStr);
                if (str1 != "bbbbbbbbbbbb")
                {
                    throw new ArgumentException("str1");
                }
                Hole(ref str1);
            }

            for (int k = 0; k < IterNum; k++)
            {
                var str2 = GetSubStrSpan(strSpan);
                if (str2 != "bbbbbbbbbbbb")
                {
                    throw new ArgumentException("str2");
                }
                Hole(ref str2);
            }

            for (int k = 0; k < IterNum; k++)
            {
                var str2 = GetSubPureCharArr(charArr);
                if (str2 != "bbbbbbbbbbbb")
                {
                    throw new ArgumentException("str2");
                }
                Hole(ref str2);
            }

            for (int k = 0; k < IterNum; k++)
            {
                var str2 = GetSubArraySpan(arrSpan);
                if (str2 != "bbbbbbbbbbbb")
                {
                    throw new ArgumentException("str2");
                }
                Hole(ref str2);
            }

            Console.WriteLine(y);
        }