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


C# TypeSymbol.IsEqualToOrDerivedFrom方法代码示例

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


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

示例1: IsAccessible

        static bool IsAccessible(MethodSymbol method, TypeSymbol classCtx)
        {
            if (method.DeclaredAccessibility == Accessibility.Private)
            {
                return (method.ContainingType == classCtx);
            }
            else if (method.DeclaredAccessibility == Accessibility.Protected)
            {
                return classCtx != null && (
                    method.ContainingType.IsEqualToOrDerivedFrom(classCtx) ||
                    classCtx.IsEqualToOrDerivedFrom(method.ContainingType));
            }

            return true;
        }
开发者ID:iolevel,项目名称:peachpie,代码行数:15,代码来源:OverloadsList.cs

示例2: EmitConvertToClass

        /// <summary>
        /// Emits conversion to a class object.
        /// </summary>
        /// <param name="from">Type of value on top of the evaluation stack.</param>
        /// <param name="fromHint">Hint in case of multitype value.</param>
        /// <param name="to">Target type.</param>
        private void EmitConvertToClass(TypeSymbol from, TypeRefMask fromHint, TypeSymbol to)
        {
            Contract.ThrowIfNull(from);
            Contract.ThrowIfNull(to);
            Debug.Assert(to.IsReferenceType);   // TODO: structs other than primitive types
            Debug.Assert(to != CoreTypes.PhpAlias);

            // dereference
            if (from == CoreTypes.PhpAlias)
            {
                Emit_PhpAlias_GetValue();
                from = CoreTypes.PhpValue;
            }

            if (from == to)
                return;

            Debug.Assert(to != CoreTypes.PhpArray && to != CoreTypes.PhpString && to != CoreTypes.PhpAlias);

            if (to == CoreTypes.IPhpCallable)
            {
                // (IPhpCallable)
                if (!from.IsEqualToOrDerivedFrom(CoreTypes.IPhpCallable))
                {
                    if (from.SpecialType == SpecialType.System_String)
                    {
                        EmitCall(ILOpCode.Call, CoreMethods.Operators.AsCallable_String);
                    }
                    else if (
                        from.SpecialType == SpecialType.System_Int64 ||
                        from.SpecialType == SpecialType.System_Boolean ||
                        from.SpecialType == SpecialType.System_Double)
                    {
                        throw new ArgumentException($"{from.Name} cannot be converted to a class of type {to.Name}!");  // TODO: ErrCode
                    }
                    else
                    {
                        EmitConvertToPhpValue(from, fromHint);
                        EmitCall(ILOpCode.Call, CoreMethods.Operators.AsCallable_PhpValue);
                    }
                }
                return;
            }

            switch (from.SpecialType)
            {
                case SpecialType.System_Void:
                case SpecialType.System_Int32:
                case SpecialType.System_Int64:
                case SpecialType.System_Boolean:
                case SpecialType.System_Double:
                case SpecialType.System_String:
                    if (to == CoreTypes.Object)
                    {
                        from = EmitConvertToPhpValue(from, fromHint);
                        goto default;
                    }
                    else
                    {
                        throw new ArgumentException($"{from.Name} cannot be converted to a class of type {to.Name}!");  // TODO: ErrCode
                    }
                default:
                    if (from == CoreTypes.PhpValue)
                    {
                        // Convert.ToClass( value )
                        EmitCall(ILOpCode.Call, CoreMethods.Operators.ToClass_PhpValue)
                            .Expect(SpecialType.System_Object);

                        // (T)
                        EmitCastClass(to);
                        return;
                    }
                    if (from == CoreTypes.PhpNumber)
                    {
                        // Object
                        EmitPhpNumberAddr();
                        EmitCall(ILOpCode.Call, CoreMethods.PhpNumber.ToClass)
                            .Expect(SpecialType.System_Object);

                        // (T)
                        EmitCastClass(to);
                        return;
                    }
                    else if (from.IsOfType(CoreTypes.PhpArray))
                    {
                        // (T)PhpArray.ToClass();
                        EmitCastClass(EmitCall(ILOpCode.Call, CoreMethods.PhpArray.ToClass), to);
                        return;
                    }
                    else if (from.IsOfType(CoreTypes.IPhpArray))
                    {
                        // (T)Convert.ToClass(IPhpArray)
                        EmitCastClass(EmitCall(ILOpCode.Call, CoreMethods.Operators.ToClass_IPhpArray), to);
                        return;
//.........这里部分代码省略.........
开发者ID:iolevel,项目名称:peachpie,代码行数:101,代码来源:CodeGenerator.Convert.cs

示例3: EmitCastClass

 internal void EmitCastClass(TypeSymbol from, TypeSymbol to)
 {
     if (!from.IsEqualToOrDerivedFrom(to))
     {
         EmitCastClass(to);
     }
 }
开发者ID:iolevel,项目名称:peachpie,代码行数:7,代码来源:CodeGenerator.Emit.cs


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