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


C# TypeRef.Equals方法代码示例

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


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

示例1: TypeSigFromTypeRef

        private PE.TypeSig TypeSigFromTypeRef(DllSaveContext ctxt, TypeRef typeRef)
        {
            if (typeRef.Equals(rootEnv.Global.TypedReferenceRef))
                return new PE.PrimitiveTypeSig { PrimitiveType = PE.PrimitiveType.TypedRef };
            else
            {
                var tyconEnv = typeRef.EnterConstructor(rootEnv);

                switch (tyconEnv.Type.Flavor)
                {
                    case TypeDefFlavor.Pointer:
                        {
                            var p = (PointerTypeDef)tyconEnv.Type;
                            switch (p.PointerFlavor)
                            {
                                case PointerFlavor.Unmanaged:
                                    return new PE.UnmanagedPointerTypeSig { ElementType = TypeWithCustomModsFromTypeRef(ctxt, typeRef.Arguments[0]) };
                                case PointerFlavor.Managed:
                                    return new PE.ManagedPointerTypeSig { ElementType = TypeSigFromTypeRef(ctxt, typeRef.Arguments[0]) };
                                default:
                                    throw new ArgumentOutOfRangeException();
                            }
                        }
                    case TypeDefFlavor.CodePointer:
                        {
                            var p = (CodePointerTypeDef)tyconEnv.Type;
                            switch (p.CodePointerFlavor)
                            {
                                case CodePointerFlavor.Function:
                                    throw new NotImplementedException();
                                case CodePointerFlavor.Action:
                                    throw new NotImplementedException();
                                default:
                                    throw new ArgumentOutOfRangeException();
                            }
                            break;
                        }
                    case TypeDefFlavor.Array:
                        return new PE.ArrayTypeSig { ElementType = TypeWithCustomModsFromTypeRef(ctxt, typeRef.Arguments[0]) };
                    case TypeDefFlavor.MultiDimArray:
                        {
                            var a = (MultiDimArrayTypeDef)tyconEnv.Type;
                            return new PE.MultiDimArrayTypeSig
                                   {
                                       ElementType = TypeSigFromTypeRef(ctxt, typeRef.Arguments[0]),
                                       Rank = a.Rank,
                                       LoBounds = a.Bounds.LoBounds(),
                                       Sizes = a.Bounds.Sizes()
                                   };
                        }
                    case TypeDefFlavor.Box:
                        throw new InvalidOperationException("unexpected box type");
                    case TypeDefFlavor.Null:
                        throw new InvalidOperationException("unexpected null type");
                    case TypeDefFlavor.Parameter:
                        {
                            var p = (ParameterTypeDef)tyconEnv.Type;
                            switch (p.ParameterFlavor)
                            {
                                case ParameterFlavor.Type:
                                    return new PE.TypeParameterTypeSig { Index = p.Index };
                                case ParameterFlavor.Method:
                                    return new PE.MethodParameterTypeSig { Index = p.Index };
                                default:
                                    throw new ArgumentOutOfRangeException();
                            }
                        }
                    case TypeDefFlavor.Handle:
                    case TypeDefFlavor.Nullable:
                    case TypeDefFlavor.Enum:
                    case TypeDefFlavor.Struct:
                        {
                            var applicand = new PE.TypeDefOrRefSig
                                            {
                                                IsValueType = true,
                                                TypeDefOrRef = { Value = TypeDefOrRefRowFromQualifiedTypeName(ctxt, typeRef.QualifiedTypeName) }
                                            };
                            if (typeRef.Arguments.Count > 0)
                                return new PE.ApplicationTypeSig
                                       {
                                           Applicand = applicand,
                                           Arguments = typeRef.Arguments.Select(t => TypeSigFromTypeRef(ctxt, t)).ToSeq()
                                       };
                            else
                                return applicand;
                        }
                    case TypeDefFlavor.Void:
                        return new PE.PrimitiveTypeSig { PrimitiveType = PE.PrimitiveType.Void };
                    case TypeDefFlavor.Number:
                        {
                            var n = (NumberTypeDef)tyconEnv.Type;
                            var p = default(PE.PrimitiveType);
                            switch (n.NumberFlavor)
                            {
                                case NumberFlavor.Int8:
                                    p = PE.PrimitiveType.Int8;
                                    break;
                                case NumberFlavor.Int16:
                                    p = PE.PrimitiveType.Int16;
                                    break;
//.........这里部分代码省略.........
开发者ID:modulexcite,项目名称:IL2JS,代码行数:101,代码来源:PESaver.cs

示例2: ValueParametersFromCCIMethod

        private AList<ParameterOrLocal> ValueParametersFromCCIMethod(CCI.Method method, out TypeRef resultType)
        {
            // If the (possibly polymorphic) method is within an instance of a user-defined higher-kinded type, 
            // follow the template chain one more step to get to the true definition, from which we can extract
            // the argument and result types w.r.t. the type and method type parameters.
            // SPECIAL CASE: Built-in array types have constructors for higher-ranked array instances.
            //               We don't need to do any template following for those.
            var isPolyMethod = false;
            var declType = method.DeclaringType;
            do
            {
                if (declType.TemplateArguments != null && declType.TemplateArguments.Count > 0 &&
                    !(declType is CCI.ArrayType))
                {
                    isPolyMethod = true;
                    break;
                }
                declType = declType.DeclaringType;
            }
            while (declType != null);
            if (isPolyMethod)
            {
                if (method.Template == null)
                    throw new InvalidOperationException("invalid method");
                method = method.Template;
            }
            else
            {
                if (method.Template != null)
                    throw new InvalidOperationException("invalid method");
            }

            resultType = TypeRefFromCCIType(method.ReturnType);
            if (resultType.Equals(global.VoidRef))
                resultType = null;

            var valueParameters = default(AList<ParameterOrLocal>);
            if (!method.IsStatic)
            {
                // Method takes an instance of it's defining type as first argument
                // This may be a self-reference to a higher-kinded type
                var selfType = TypeRefFromCCIType(method.DeclaringType);
                if (IsCCIValueType(method.DeclaringType))
                    selfType = new BuiltinTypeRef(global.ManagedPointerTypeConstructorDef, selfType);
                valueParameters = new AList<ParameterOrLocal>();
                valueParameters.Add(new ParameterOrLocal(null, null, selfType));
            }

            // SPECIAL CASE: Replace int pointer second argument of delegate constructor with function pointer
            var declDelegate = method.DeclaringType as CCI.DelegateNode;
            if (declDelegate != null && method is CCI.InstanceInitializer && method.Parameters != null && method.Parameters.Count == 2)
            {
                if (valueParameters == null)
                    valueParameters = new AList<ParameterOrLocal>();
                valueParameters.Add(new ParameterOrLocal(null, null, TypeRefFromCCIType(method.Parameters[0].Type))); // object
                var ps = new List<CCI.TypeNode>();
                foreach (var p in declDelegate.Parameters)
                    ps.Add(p.Type);
                valueParameters.Add(new ParameterOrLocal(null, null, CodePointerFromParameters(ps, declDelegate.ReturnType)));
            }
            else if (method.Parameters != null && method.Parameters.Count > 0)
            {
                if (valueParameters == null)
                    valueParameters = new AList<ParameterOrLocal>();
                for (var i = 0; i < method.Parameters.Count; i++)
                    valueParameters.Add(new ParameterOrLocal(null, null, TypeRefFromCCIType(method.Parameters[i].Type)));
            }
            return valueParameters;
        }
开发者ID:modulexcite,项目名称:IL2JS,代码行数:69,代码来源:CCILoader.cs


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