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


C# CType.isDelegateType方法代码示例

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


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

示例1: DoesOutputTypeContain

        ////////////////////////////////////////////////////////////////////////////////
        //
        // Output types
        //
        private bool DoesOutputTypeContain(EXPR pSource, CType pDest,
            TypeParameterType pParam)
        {
            // SPEC: If E is a method group or an anonymous function and T is a delegate
            // SPEC: CType or expression tree CType then the return CType of T is an output CType
            // SPEC: of E with CType T.

            pDest = pDest.GetDelegateTypeOfPossibleExpression();
            if (!pDest.isDelegateType())
            {
                return false;
            }

            if (!pSource.isUNBOUNDLAMBDA() && !pSource.isMEMGRP())
            {
                return false;
            }

            CType pDelegateReturn = pDest.AsAggregateType().GetDelegateReturnType(GetSymbolLoader());
            if (pDelegateReturn == null)
            {
                return false;
            }
            return TypeManager.TypeContainsType(pDelegateReturn, pParam);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:29,代码来源:MethodTypeInferrer.cs

示例2: UpperBoundConstructedInference

        ////////////////////////////////////////////////////////////////////////////////

        private bool UpperBoundConstructedInference(CType pSource, CType pDest)
        {
            if (!pSource.IsAggregateType())
            {
                return false;
            }

            AggregateType pConstructedSource = pSource.AsAggregateType();
            TypeArray pSourceArgs = pConstructedSource.GetTypeArgsAll();
            if (pSourceArgs.size == 0)
            {
                return false;
            }

            // SPEC:  Otherwise, if V is a constructed CType C<V1...Vk> and U is
            // SPEC:   C<U1...Uk> then an exact inference,
            // SPEC:   lower bound inference or upper bound inference
            // SPEC:   is made from each Ui to the corresponding Vi.

            if (pDest.IsAggregateType() &&
                pConstructedSource.GetOwningAggregate() == pDest.AsAggregateType().GetOwningAggregate())
            {
                if (pDest.isInterfaceType() || pDest.isDelegateType())
                {
                    UpperBoundTypeArgumentInference(pConstructedSource, pDest.AsAggregateType());
                }
                else
                {
                    ExactTypeArgumentInference(pConstructedSource, pDest.AsAggregateType());
                }
                return true;
            }

            // SPEC:  Otherwise, if U is a class CType C<U1...Uk> and V is a class CType which
            // SPEC:   inherits directly or indirectly from C<V1...Vk> then an exact ...

            if (UpperBoundClassInference(pConstructedSource, pDest))
            {
                return true;
            }

            // SPEC:  Otherwise, if U is an interface CType C<U1...Uk> and V is a class CType
            // SPEC:   or struct CType and there is a unique set V1...Vk such that V directly 
            // SPEC:   or indirectly implements C<V1...Vk> then an exact ...
            // SPEC:  ... and U is an interface CType ...

            if (UpperBoundInterfaceInference(pConstructedSource, pDest))
            {
                return true;
            }

            return false;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:55,代码来源:MethodTypeInferrer.cs

示例3: DoesInputTypeContain

        ////////////////////////////////////////////////////////////////////////////////
        //
        // Input types
        //
        private bool DoesInputTypeContain(EXPR pSource, CType pDest,
            TypeParameterType pParam)
        {
            // SPEC: If E is a method group or an anonymous function and T is a delegate
            // SPEC: CType or expression tree CType then all the parameter types of T are
            // SPEC: input types of E with CType T.

            pDest = pDest.GetDelegateTypeOfPossibleExpression();
            if (!pDest.isDelegateType())
            {
                return false; // No input types.
            }

            if (!pSource.isUNBOUNDLAMBDA() && !pSource.isMEMGRP())
            {
                return false; // No input types.
            }

            TypeArray pDelegateParameters =
                pDest.AsAggregateType().GetDelegateParameters(GetSymbolLoader());
            if (pDelegateParameters == null)
            {
                return false;
            }
            return TypeManager.ParametersContainTyVar(pDelegateParameters, pParam);
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:30,代码来源:MethodTypeInferrer.cs

示例4: LowerBoundNullableInference

        ////////////////////////////////////////////////////////////////////////////////

        /*
        bool LowerBoundNullableInference(CType pSource, CType pDest)
        {
            // SPEC ISSUE: As noted above, the spec does not clearly call out how
            // SPEC ISSUE: to do CType inference to a nullable target. I propose the
            // SPEC ISSUE: following:
            // SPEC ISSUE:
            // SPEC ISSUE:  Otherwise, if V is nullable CType V1? and U is a 
            // SPEC ISSUE:   non-nullable struct CType then an exact inference is made from U to V1.

            if (!pDest.IsNullableType() || !pSource.isStructType() || pSource.IsNullableType())
            {
                return false;
            }
            ExactInference(pSource, pDest.AsNullableType().GetUnderlyingType());
            return true;
        }
         * */

        ////////////////////////////////////////////////////////////////////////////////

        private bool LowerBoundConstructedInference(CType pSource, CType pDest)
        {
            if (!pDest.IsAggregateType())
            {
                return false;
            }

            AggregateType pConstructedDest = pDest.AsAggregateType();
            TypeArray pDestArgs = pConstructedDest.GetTypeArgsAll();
            if (pDestArgs.size == 0)
            {
                return false;
            }

            // SPEC:  Otherwise, if V is a constructed class or struct CType C<V1...Vk> 
            // SPEC:   and U is C<U1...Uk> then an exact inference
            // SPEC:   is made from each Ui to the corresponding Vi.

            // SPEC:  Otherwise, if V is a constructed interface or delegate CType C<V1...Vk> 
            // SPEC:   and U is C<U1...Uk> then an exact inference,
            // SPEC:   lower bound inference or upper bound inference
            // SPEC:   is made from each Ui to the corresponding Vi.

            if (pSource.IsAggregateType() &&
                pSource.AsAggregateType().GetOwningAggregate() == pConstructedDest.GetOwningAggregate())
            {
                if (pSource.isInterfaceType() || pSource.isDelegateType())
                {
                    LowerBoundTypeArgumentInference(pSource.AsAggregateType(), pConstructedDest);
                }
                else
                {
                    ExactTypeArgumentInference(pSource.AsAggregateType(), pConstructedDest);
                }
                return true;
            }

            // SPEC:  Otherwise, if V is a class CType C<V1...Vk> and U is a class CType which
            // SPEC:   inherits directly or indirectly from C<U1...Uk> then an exact ...
            // SPEC:  ... and U is a CType parameter with effective base class ...
            // SPEC:  ... and U is a CType parameter with an effective base class which inherits ...

            if (LowerBoundClassInference(pSource, pConstructedDest))
            {
                return true;
            }

            // SPEC:  Otherwise, if V is an interface CType C<V1...Vk> and U is a class CType
            // SPEC:   or struct CType and there is a unique set U1...Uk such that U directly 
            // SPEC:   or indirectly implements C<U1...Uk> then an exact ...
            // SPEC:  ... and U is an interface CType ...
            // SPEC:  ... and U is a CType parameter ...

            if (LowerBoundInterfaceInference(pSource, pConstructedDest))
            {
                return true;
            }

            return false;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:83,代码来源:MethodTypeInferrer.cs

示例5: MethodGroupReturnTypeInference

        ////////////////////////////////////////////////////////////////////////////////

        private bool MethodGroupReturnTypeInference(EXPR pSource, CType pType)
        {
            // SPEC:  Otherwise, if E is a method group and T is a delegate CType or
            // SPEC:   expression tree CType with parameter types T1...Tk and return
            // SPEC:   CType Tb and overload resolution of E with the types T1...Tk
            // SPEC:   yields a single method with return CType U then a lower-bound
            // SPEC:   inference is made from U to Tb.

            if (!pSource.isMEMGRP())
            {
                return false;
            }
            pType = pType.GetDelegateTypeOfPossibleExpression();
            if (!pType.isDelegateType())
            {
                return false;
            }
            AggregateType pDelegateType = pType.AsAggregateType();
            CType pDelegateReturnType = pDelegateType.GetDelegateReturnType(GetSymbolLoader());
            if (pDelegateReturnType == null)
            {
                return false;
            }
            if (pDelegateReturnType.IsVoidType())
            {
                return false;
            }

            // At this point we are in the second phase; we know that all the input types are fixed.

            TypeArray pDelegateParameters = GetFixedDelegateParameters(pDelegateType);
            if (pDelegateParameters == null)
            {
                return false;
            }

            ArgInfos argInfo = new ArgInfos() { carg = pDelegateParameters.size, types = pDelegateParameters, fHasExprs = false, prgexpr = null };

            var argsBinder = new ExpressionBinder.GroupToArgsBinder(_binder, 0/* flags */, pSource.asMEMGRP(), argInfo, null, false, pDelegateType);

            bool success = argsBinder.Bind(false);
            if (!success)
            {
                return false;
            }

            MethPropWithInst mwi = argsBinder.GetResultsOfBind().GetBestResult();
            CType pMethodReturnType = GetTypeManager().SubstType(mwi.Meth().RetType,
                mwi.GetType(), mwi.TypeArgs);
            if (pMethodReturnType.IsVoidType())
            {
                return false;
            }

            LowerBoundInference(pMethodReturnType, pDelegateReturnType);
            return true;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:59,代码来源:MethodTypeInferrer.cs

示例6: GetBestAccessibleType

        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        // RUNTIME BINDER ONLY CHANGE
        // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

        internal bool GetBestAccessibleType(CSemanticChecker semanticChecker, BindingContext bindingContext, CType typeSrc, out CType typeDst)
        {
            // This method implements the "best accessible type" algorithm for determining the type
            // of untyped arguments in the runtime binder. It is also used in method type inference
            // to fix type arguments to types that are accessible.

            // The new type is returned in an out parameter. The result will be true (and the out param
            // non-null) only when the algorithm could find a suitable accessible type.

            Debug.Assert(semanticChecker != null);
            Debug.Assert(bindingContext != null);
            Debug.Assert(typeSrc != null);

            typeDst = null;

            if (semanticChecker.CheckTypeAccess(typeSrc, bindingContext.ContextForMemberLookup()))
            {
                // If we already have an accessible type, then use it. This is the terminal point of the recursion.
                typeDst = typeSrc;
                return true;
            }

            // These guys have no accessibility concerns.
            Debug.Assert(!typeSrc.IsVoidType() && !typeSrc.IsErrorType() && !typeSrc.IsTypeParameterType());

            if (typeSrc.IsParameterModifierType() || typeSrc.IsPointerType())
            {
                // We cannot vary these.
                return false;
            }

            CType intermediateType;
            if ((typeSrc.isInterfaceType() || typeSrc.isDelegateType()) && TryVarianceAdjustmentToGetAccessibleType(semanticChecker, bindingContext, typeSrc.AsAggregateType(), out intermediateType))
            {
                // If we have an interface or delegate type, then it can potentially be varied by its type arguments
                // to produce an accessible type, and if that's the case, then return that.
                // Example: IEnumerable<PrivateConcreteFoo> --> IEnumerable<PublicAbstractFoo>
                typeDst = intermediateType;

                Debug.Assert(semanticChecker.CheckTypeAccess(typeDst, bindingContext.ContextForMemberLookup()));
                return true;
            }

            if (typeSrc.IsArrayType() && TryArrayVarianceAdjustmentToGetAccessibleType(semanticChecker, bindingContext, typeSrc.AsArrayType(), out intermediateType))
            {
                // Similarly to the interface and delegate case, arrays are covariant in their element type and
                // so we can potentially produce an array type that is accessible.
                // Example: PrivateConcreteFoo[] --> PublicAbstractFoo[]
                typeDst = intermediateType;

                Debug.Assert(semanticChecker.CheckTypeAccess(typeDst, bindingContext.ContextForMemberLookup()));
                return true;
            }

            if (typeSrc.IsNullableType())
            {
                // We have an inaccessible nullable type, which means that the best we can do is System.ValueType.
                typeDst = this.GetOptPredefAgg(PredefinedType.PT_VALUE).getThisType();

                Debug.Assert(semanticChecker.CheckTypeAccess(typeDst, bindingContext.ContextForMemberLookup()));
                return true;
            }

            if (typeSrc.IsArrayType())
            {
                // We have an inaccessible array type for which we could not earlier find a better array type
                // with a covariant conversion, so the best we can do is System.Array.
                typeDst = this.GetReqPredefAgg(PredefinedType.PT_ARRAY).getThisType();

                Debug.Assert(semanticChecker.CheckTypeAccess(typeDst, bindingContext.ContextForMemberLookup()));
                return true;
            }

            Debug.Assert(typeSrc.IsAggregateType());

            if (typeSrc.IsAggregateType())
            {
                // We have an AggregateType, so recurse on its base class.
                AggregateType aggType = typeSrc.AsAggregateType();
                AggregateType baseType = aggType.GetBaseClass();

                if (baseType == null)
                {
                    // This happens with interfaces, for instance. But in that case, the
                    // conversion to object does exist, is an implicit reference conversion,
                    // and so we will use it.
                    baseType = this.GetReqPredefAgg(PredefinedType.PT_OBJECT).getThisType();
                }

                return GetBestAccessibleType(semanticChecker, bindingContext, baseType, out typeDst);
            }

            return false;
        }
开发者ID:ChuangYang,项目名称:corefx,代码行数:98,代码来源:TypeManager.cs

示例7: covariant

        /***************************************************************************************************

         There exists an explicit conversion ...
         * From a generic delegate type S to generic delegate type T, provided all of the follow are true:
            o Both types are constructed generic types of the same generic delegate type, D<X1,... Xk>.That is,
              S is D<S1,... Sk> and T is D<T1,... Tk>.
            o S is not compatible with or identical to T.
            o If type parameter Xi is declared to be invariant then Si must be identical to Ti.
            o If type parameter Xi is declared to be covariant ("out") then Si must be convertible 
              to Ti via an identify conversion,  implicit reference conversion, or explicit reference conversion.
            o If type parameter Xi is declared to be contravariant ("in") then either Si must be identical to Ti, 
              or Si and Ti must both be reference types.
        ***************************************************************************************************/
        public static bool HasGenericDelegateExplicitReferenceConversion(SymbolLoader loader, CType pSource, CType pTarget)
        {
            if (!pSource.isDelegateType() ||
                !pTarget.isDelegateType() ||
                pSource.getAggregate() != pTarget.getAggregate() ||
                loader.HasIdentityOrImplicitReferenceConversion(pSource, pTarget))
            {
                return false;
            }

            TypeArray pTypeParams = pSource.getAggregate().GetTypeVarsAll();
            TypeArray pSourceArgs = pSource.AsAggregateType().GetTypeArgsAll();
            TypeArray pTargetArgs = pTarget.AsAggregateType().GetTypeArgsAll();

            Debug.Assert(pTypeParams.size == pSourceArgs.size);
            Debug.Assert(pTypeParams.size == pTargetArgs.size);

            for (int iParam = 0; iParam < pTypeParams.size; ++iParam)
            {
                CType pSourceArg = pSourceArgs.Item(iParam);
                CType pTargetArg = pTargetArgs.Item(iParam);

                // If they're identical then this one is automatically good, so skip it.
                // If we have an error type, then we're in some fault tolerance. Let it through.
                if (pSourceArg == pTargetArg || pTargetArg.IsErrorType() || pSourceArg.IsErrorType())
                {
                    continue;
                }
                TypeParameterType pParam = pTypeParams.Item(iParam).AsTypeParameterType();
                if (pParam.Invariant)
                {
                    return false;
                }

                if (pParam.Covariant)
                {
                    if (!FExpRefConv(loader, pSourceArg, pTargetArg))
                    {
                        return false;
                    }
                }
                else if (pParam.Contravariant)
                {
                    if (!pSourceArg.IsRefType() || !pTargetArg.IsRefType())
                    {
                        return false;
                    }
                }
            }
            return true;
        }
开发者ID:noahfalk,项目名称:corefx,代码行数:64,代码来源:Conversions.cs

示例8: HasImplicitReferenceConversion

        public bool HasImplicitReferenceConversion(CType pSource, CType pDest)
        {
            Debug.Assert(pSource != null);
            Debug.Assert(pDest != null);

            // The implicit reference conversions are:
            // * From any reference type to Object.
            if (pSource.IsRefType() && pDest.isPredefType(PredefinedType.PT_OBJECT))
            {
                return true;
            }
            // * From any class type S to any class type T provided S is derived from T.
            if (pSource.isClassType() && pDest.isClassType() && IsBaseClass(pSource, pDest))
            {
                return true;
            }

            // ORIGINAL RULES:
            //    // * From any class type S to any interface type T provided S implements T.
            //    if (pSource.isClassType() && pDest.isInterfaceType() && IsBaseInterface(pSource, pDest))
            //    {
            //        return true;
            //    }
            //    // * from any interface type S to any interface type T, provided S is derived from T.
            //    if (pSource.isInterfaceType() && pDest.isInterfaceType() && IsBaseInterface(pSource, pDest))
            //    {
            //        return true;
            //    }

            // VARIANCE EXTENSIONS:
            // * From any class type S to any interface type T provided S implements an interface
            //   convertible to T.
            // * From any interface type S to any interface type T provided S implements an interface
            //   convertible to T.
            // * From any interface type S to any interface type T provided S is not T and S is 
            //   an interface convertible to T.

            if (pSource.isClassType() && pDest.isInterfaceType() && HasAnyBaseInterfaceConversion(pSource, pDest))
            {
                return true;
            }
            if (pSource.isInterfaceType() && pDest.isInterfaceType() && HasAnyBaseInterfaceConversion(pSource, pDest))
            {
                return true;
            }
            if (pSource.isInterfaceType() && pDest.isInterfaceType() && pSource != pDest &&
                HasInterfaceConversion(pSource.AsAggregateType(), pDest.AsAggregateType()))
            {
                return true;
            }

            // * From an array type S with an element type SE to an array type T with element type TE
            //   provided that all of the following are true:
            //   * S and T differ only in element type. In other words, S and T have the same number of dimensions.
            //   * Both SE and TE are reference types.
            //   * An implicit reference conversion exists from SE to TE.
            if (pSource.IsArrayType() && pDest.IsArrayType() &&
                HasCovariantArrayConversion(pSource.AsArrayType(), pDest.AsArrayType()))
            {
                return true;
            }
            // * From any array type to System.Array or any interface implemented by System.Array.
            if (pSource.IsArrayType() && (pDest.isPredefType(PredefinedType.PT_ARRAY) ||
                IsBaseInterface(GetReqPredefType(PredefinedType.PT_ARRAY, false), pDest)))
            {
                return true;
            }
            // * From a single-dimensional array type S[] to IList<T> and its base
            //   interfaces, provided that there is an implicit identity or reference
            //   conversion from S to T.
            if (pSource.IsArrayType() && HasArrayConversionToInterface(pSource.AsArrayType(), pDest))
            {
                return true;
            }

            // * From any delegate type to System.Delegate
            // 
            // SPEC OMISSION:
            // 
            // The spec should actually say
            //
            // * From any delegate type to System.Delegate 
            // * From any delegate type to System.MulticastDelegate
            // * From any delegate type to any interface implemented by System.MulticastDelegate
            if (pSource.isDelegateType() &&
                (pDest.isPredefType(PredefinedType.PT_MULTIDEL) ||
                pDest.isPredefType(PredefinedType.PT_DELEGATE) ||
                IsBaseInterface(GetReqPredefType(PredefinedType.PT_MULTIDEL, false), pDest)))
            {
                return true;
            }

            // VARIANCE EXTENSION:
            // * From any delegate type S to a delegate type T provided S is not T and
            //   S is a delegate convertible to T

            if (pSource.isDelegateType() && pDest.isDelegateType() &&
                HasDelegateConversion(pSource.AsAggregateType(), pDest.AsAggregateType()))
            {
                return true;
//.........这里部分代码省略.........
开发者ID:dotnet,项目名称:corefx,代码行数:101,代码来源:SymbolLoader.cs


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