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


C# Type.GetFinalPointee方法代码示例

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


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

示例1: CheckForDefaultConstruct

        private bool? CheckForDefaultConstruct(Type desugared, Expression expression,
            ref string result)
        {
            var type = desugared.GetFinalPointee() ?? desugared;

            Class decl;
            if (!type.TryGetClass(out decl))
                return false;

            var ctor = expression as CXXConstructExpr;

            TypeMap typeMap;

            var typePrinter = new CSharpTypePrinter(Context);
            typePrinter.PushMarshalKind(CSharpMarshalKind.DefaultExpression);
            var typePrinterResult = type.Visit(typePrinter).Type;
            if (TypeMaps.FindTypeMap(decl, type, out typeMap))
            {
                var typeInSignature = typeMap.CSharpSignatureType(
                    typePrinter.TypePrinterContext).SkipPointerRefs().Desugar();
                Enumeration @enum;
                if (typeInSignature.TryGetEnum(out @enum))
                {
                    if (ctor != null &&
                        (ctor.Arguments.Count == 0 ||
                         HasSingleZeroArgExpression((Function) ctor.Declaration)))
                    {
                        result = "0";
                        return true;
                    }
                    return false;
                }

                if (ctor != null && typePrinterResult == "string" && ctor.Arguments.Count == 0)
                {
                    result = "\"\"";
                    return true;
                }
            }

            if (ctor == null)
            {
                CheckForSimpleExpressions(expression, ref result, desugared);
                return decl.IsValueType ? (bool?) false : null;
            }

            var method = (Method) expression.Declaration;
            var expressionSupported = decl.IsValueType && method.Parameters.Count == 0;

            if (expression.String.Contains('('))
            {
                var argsBuilder = new StringBuilder("new ");
                argsBuilder.Append(typePrinterResult);
                argsBuilder.Append('(');
                for (var i = 0; i < ctor.Arguments.Count; i++)
                {
                    var argument = ctor.Arguments[i];
                    var argResult = argument.String;
                    expressionSupported &= PrintExpression(method.Parameters[i].Type.Desugar(),
                        argument, ref argResult) ?? false;
                    argsBuilder.Append(argResult);
                    if (i < ctor.Arguments.Count - 1)
                        argsBuilder.Append(", ");
                }
                argsBuilder.Append(')');
                result = argsBuilder.ToString();
            }
            else
            {
                if (method.Parameters.Count > 0)
                {
                    var paramType = method.Parameters[0].Type.SkipPointerRefs().Desugar();
                    Enumeration @enum;
                    if (paramType.TryGetEnum(out @enum))
                        result = TranslateEnumExpression(method, paramType, expression.String);
                }
            }
            return expressionSupported ? true : (bool?) null;
        }
开发者ID:ddobrev,项目名称:CppSharp,代码行数:79,代码来源:HandleDefaultParamValuesPass.cs

示例2: CheckForDefaultPointer

 private bool CheckForDefaultPointer(Type desugared, Parameter parameter)
 {
     if (desugared.IsPointer())
     {
         // IntPtr.Zero is not a constant
         if (desugared.IsPointerToPrimitiveType(PrimitiveType.Void))
         {
             parameter.DefaultArgument.String = "new global::System.IntPtr()";
             return true;
         }
         if (parameter.IsPrimitiveParameterConvertibleToRef())
             return false;
         Class @class;
         if (desugared.GetFinalPointee().TryGetClass(out @class) && @class.IsValueType)
         {
             parameter.DefaultArgument.String = string.Format("new {0}()",
                 new CSharpTypePrinter(Driver).VisitClassDecl(@class));
             return true;
         }
         parameter.DefaultArgument.String = "null";
         return true;
     }
     return false;
 }
开发者ID:Samana,项目名称:CppSharp,代码行数:24,代码来源:HandleDefaultParamValuesPass.cs

示例3: CheckForDefaultPointer

        private bool CheckForDefaultPointer(Type desugared, ref string result)
        {
            if (!desugared.IsPointer())
                return false;

            // IntPtr.Zero is not a constant
            if (desugared.IsPointerToPrimitiveType(PrimitiveType.Void))
            {
                result = "new global::System.IntPtr()";
                return true;
            }

            if (desugared.IsPrimitiveTypeConvertibleToRef())
                return false;

            Class @class;
            if (desugared.GetFinalPointee().TryGetClass(out @class) && @class.IsValueType)
            {
                result = string.Format("new {0}()",
                    new CSharpTypePrinter(Context).VisitClassDecl(@class));
                return true;
            }

            result = "null";
            return true;
        }
开发者ID:ddobrev,项目名称:CppSharp,代码行数:26,代码来源:HandleDefaultParamValuesPass.cs

示例4: CheckForDefaultConstruct

        private bool? CheckForDefaultConstruct(Type desugared, Statement arg,
            TypeQualifiers qualifiers)
        {
            // Unwrapping the underlying type behind a possible pointer/reference
            Type type = desugared.GetFinalPointee() ?? desugared;

            Class decl;
            if (!type.TryGetClass(out decl))
                return false;

            var ctor = arg.Declaration as Method;

            TypeMap typeMap;
            var typePrinterContext = new CSharpTypePrinterContext
            {
                CSharpKind = CSharpTypePrinterContextKind.DefaultExpression,
                Type = type
            };

            string typePrinterResult = null;
            if (Driver.TypeDatabase.FindTypeMap(decl, type, out typeMap))
            {
                var typeInSignature = typeMap.CSharpSignatureType(
                    typePrinterContext).SkipPointerRefs().Desugar();
                Enumeration @enum;
                if (typeInSignature.TryGetEnum(out @enum))
                    return false;

                if (ctor == null || !ctor.IsConstructor)
                    return false;

                typePrinterResult = typeMap.CSharpSignature(typePrinterContext);
                if (typePrinterResult == "string" && ctor.Parameters.Count == 0)
                {
                    arg.String = "\"\"";
                    return true;
                }
            }

            var match = regexCtor.Match(arg.String);
            if (match.Success)
            {
                if (ctor != null)
                {
                    var templateSpecializationType = type as TemplateSpecializationType;
                    var typePrinter = new CSharpTypePrinter(Driver);
                    typePrinterResult = typePrinterResult ?? (templateSpecializationType != null
                        ? typePrinter.VisitTemplateSpecializationType(
                            templateSpecializationType, qualifiers)
                        : typePrinter.VisitClassDecl((Class) ctor.Namespace)).Type;

                    arg.String = string.Format("new {0}{1}", typePrinterResult,
                        match.Groups[2].Value);
                    if (ctor.Parameters.Count > 0 && ctor.Parameters[0].Type.IsAddress())
                        arg.String = arg.String.Replace("(0)", "()");
                }
                else
                    arg.String = string.Format("new {0}", arg.String);
            }
            else
            {
                if (ctor != null && ctor.Parameters.Count > 0)
                {
                    var finalPointee = ctor.Parameters[0].Type.SkipPointerRefs().Desugar();
                    Enumeration @enum;
                    if (finalPointee.TryGetEnum(out @enum))
                        TranslateEnumExpression(ctor, arg, finalPointee, arg.String);
                }
            }

            return decl.IsValueType ? true : (bool?) null;
        }
开发者ID:Samana,项目名称:CppSharp,代码行数:72,代码来源:HandleDefaultParamValuesPass.cs


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