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;
 }
Example #2
0
        public override bool VisitParameterDecl(Parameter parameter)
        {
            if (parameter.Usage == ParameterUsage.Unknown || parameter.IsIn)
                return base.VisitParameterDecl(parameter);

            var ctx = new CSharpMarshalContext(Context.Driver)
            {
                ReturnType = Context.ReturnType,
                ReturnVarName = Context.ReturnVarName
            };

            var marshal = new CSharpMarshalNativeToManagedPrinter(ctx);
            parameter.Type.Visit(marshal);

            if (!string.IsNullOrWhiteSpace(ctx.SupportBefore))
                Context.SupportBefore.WriteLine(ctx.SupportBefore);

            if (!string.IsNullOrWhiteSpace(ctx.Return) && !parameter.IsPrimitiveParameterConvertibleToRef())
            {
                Context.SupportBefore.WriteLine("var _{0} = {1};", parameter.Name,
                    ctx.Return);
            }

            Context.Return.Write("{0}{1}",
                parameter.IsPrimitiveParameterConvertibleToRef() ? "ref *" : "_", parameter.Name);
            return true;
        }