コード例 #1
0
ファイル: BitArrayTests.cs プロジェクト: sperling/cskarp
        private void CheckRandomData(Random r1, Random r2, int capacity)
        {
            BitArray d = BitArray.Create(capacity);

            Assert.Equal(capacity, d.Capacity);
            for (int i1 = 0; i1 < capacity; i1++)
            {
                d[i1] = r1.NextBool();
            }
            Assert.Equal(capacity, d.Capacity);

            for (int i2 = 0; i2 < capacity; i2++)
            {
                Assert.Equal(d[i2], r2.NextBool());
            }
        }
コード例 #2
0
ファイル: BitArrayTests.cs プロジェクト: sperling/cskarp
        private void CheckTrueBits(int capacity, Random r1, Random r2)
        {
            BitArray b = BitArray.Create(capacity);

            for (int i = 0; i < capacity; i++)
            {
                b[i] = r1.NextBool();
            }

            IEnumerable <int> i1 = b.TrueBits();
            IEnumerator <int> i2 = i1.GetEnumerator();

            for (int i = 0; i < capacity; i++)
            {
                if (r2.NextBool())
                {
                    Assert.True(i2.MoveNext());
                    Assert.Equal(i2.Current, i);
                }
            }

            Assert.False(i2.MoveNext());
            i2.Dispose();
        }
コード例 #3
0
        internal NamedTypeSymbol GetDelegateType(
            BoundExpression loweredReceiver,
            RefKind receiverRefKind,
            ImmutableArray <BoundExpression> loweredArguments,
            ImmutableArray <RefKind> refKinds,
            BoundExpression loweredRight,
            TypeSymbol resultType)
        {
            Debug.Assert(refKinds.IsDefaultOrEmpty || refKinds.Length == loweredArguments.Length);

            var callSiteType = factory.WellKnownType(WellKnownType.System_Runtime_CompilerServices_CallSite);

            if (callSiteType.IsErrorType())
            {
                return(null);
            }

            var  delegateSignature = MakeCallSiteDelegateSignature(callSiteType, loweredReceiver, loweredArguments, loweredRight, resultType);
            bool returnsVoid       = resultType.SpecialType == SpecialType.System_Void;
            bool hasByRefs         = receiverRefKind != RefKind.None || !refKinds.IsDefaultOrEmpty;

            if (!hasByRefs)
            {
                var wkDelegateType = returnsVoid ?
                                     WellKnownTypes.GetWellKnownActionDelegate(invokeArgumentCount: delegateSignature.Length) :
                                     WellKnownTypes.GetWellKnownFunctionDelegate(invokeArgumentCount: delegateSignature.Length - 1);

                if (wkDelegateType != WellKnownType.Unknown)
                {
                    var delegateType = factory.Compilation.GetWellKnownType(wkDelegateType);
                    if (!delegateType.HasUseSiteError)
                    {
                        return(delegateType.Construct(delegateSignature));
                    }
                }
            }

            BitArray byRefs;

            if (hasByRefs)
            {
                byRefs = BitArray.Create(1 + (loweredReceiver != null ? 1 : 0) + loweredArguments.Length + (loweredRight != null ? 1 : 0));

                int j = 1;
                if (loweredReceiver != null)
                {
                    byRefs[j++] = receiverRefKind != RefKind.None;
                }

                if (!refKinds.IsDefault)
                {
                    for (int i = 0; i < refKinds.Length; i++, j++)
                    {
                        if (refKinds[i] != RefKind.None)
                        {
                            byRefs[j] = true;
                        }
                    }
                }
            }
            else
            {
                byRefs = default(BitArray);
            }

            int parameterCount = delegateSignature.Length - (returnsVoid ? 0 : 1);

            return(factory.Compilation.AnonymousTypeManager.SynthesizeDelegate(parameterCount, byRefs, returnsVoid).Construct(delegateSignature));
        }