Example #1
0
 private static void WriteTemplateSpecializationCheck(CSharpSources gen,
                                                      Class @class, ClassTemplateSpecialization specialization)
 {
     gen.WriteLine("if ({0})", string.Join(" && ",
                                           Enumerable.Range(0, @class.TemplateParameters.Count).Select(
                                               i =>
     {
         CppSharp.AST.Type type = specialization.Arguments[i].Type.Type;
         return(type.IsPointerToPrimitiveType() && !type.IsConstCharString() ?
                $"__{@class.TemplateParameters[i].Name}.FullName == \"System.IntPtr\"" :
                $"__{@class.TemplateParameters[i].Name}.IsAssignableFrom(typeof({type}))");
     })));
 }
Example #2
0
        public override bool VisitTemplateParameterSubstitutionType(TemplateParameterSubstitutionType param, TypeQualifiers quals)
        {
            Type returnType = Context.ReturnType.Type.Desugar();
            Type finalType  = (returnType.GetFinalPointee() ?? returnType).Desugar();

            if (finalType.IsDependent)
            {
                Context.Return.Write($"({param.ReplacedParameter.Parameter.Name}) (object) ");
            }
            Type replacement = param.Replacement.Type.Desugar();

            if (replacement.IsPointerToPrimitiveType() && !replacement.IsConstCharString())
            {
                Context.Return.Write($"({typePrinter.IntPtrType}) ");
            }
            return(base.VisitTemplateParameterSubstitutionType(param, quals));
        }