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


C# Generators.MarshalContext类代码示例

本文整理汇总了C#中CppSharp.Generators.MarshalContext的典型用法代码示例。如果您正苦于以下问题:C# MarshalContext类的具体用法?C# MarshalContext怎么用?C# MarshalContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


MarshalContext类属于CppSharp.Generators命名空间,在下文中一共展示了MarshalContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CSharpMarshalToManaged

        public override void CSharpMarshalToManaged(MarshalContext ctx)
        {
            TemplateSpecializationType templateType = (TemplateSpecializationType) this.Type;
            QualifiedType type = templateType.Arguments[0].Type;

            TextGenerator supportBefore = ctx.SupportBefore;
            supportBefore.WriteLine("var __qlistData = new QListData({0}._0.d);", ctx.ReturnVarName);
            supportBefore.WriteLine("var __size = __qlistData.Size;");
            supportBefore.WriteLine("var __list = new System.Collections.Generic.List<{0}>(__size);", type);
            supportBefore.WriteLine("for (int i = 0; i < __size; i++)");
            supportBefore.WriteStartBraceIndent();
            // TODO: handle pointers to primitives, they cannot be used as a placeholder type and use IntPtr instead
            if (type.Type.IsPrimitiveType() || type.Type.IsEnumType())
            {
                supportBefore.WriteLine("__list.Add(*({0}*) __qlistData.At(i));", type);
            }
            else
            {
                Class @class;
                Type pointee;
                if ((type.Type.IsTagDecl(out @class) ||
                     (type.Type.IsPointerTo(out pointee) && pointee.IsTagDecl(out @class))) && @class.IsAbstract)
                {
                    supportBefore.WriteLine("__list.Add(new {0}Internal(new global::System.IntPtr(__qlistData.At(i))));", type, ctx.ReturnVarName);
                }
                else
                {
                    supportBefore.WriteLine("__list.Add(new {0}(new global::System.IntPtr(__qlistData.At(i))));", type, ctx.ReturnVarName);
                }
            }
            supportBefore.WriteCloseBraceIndent();
            ctx.Return.Write("__list");
        }
开发者ID:RodolpheFouquet,项目名称:QtSharp,代码行数:33,代码来源:QList.cs

示例2: CSharpMarshalToManaged

 public override void CSharpMarshalToManaged(MarshalContext ctx)
 {
     if (ctx.ReturnType.Type.Desugar().IsAddress())
     {
         var finalType = ctx.ReturnType.Type.GetFinalPointee() ?? ctx.ReturnType.Type;
         var enumType = GetEnumType(finalType);
         ctx.Return.Write("*({0}*) {1}", enumType, ctx.ReturnVarName);
     }
     else
     {
         ctx.Return.Write(ctx.ReturnVarName);
     }
 }
开发者ID:ymlai87416,项目名称:CppSharp,代码行数:13,代码来源:CSharp.cs

示例3: CSharpMarshalCopyCtorToManaged

 public override void CSharpMarshalCopyCtorToManaged(MarshalContext ctx)
 {
     ctx.SupportBefore.WriteLine("var __instance = new {0}.Internal();", ctx.ReturnType);
     ctx.SupportBefore.WriteLine("QListData.Data.Internal* qListData = (QListData.Data.Internal*) __instance._0.d;");
     ctx.SupportBefore.WriteLine("QListData.Data.Internal* result = (QListData.Data.Internal*) __ret._0.d;");
     ctx.SupportBefore.WriteLine("qListData->begin = result->begin;");
     ctx.SupportBefore.WriteLine("qListData->end = result->end;");
     ctx.SupportBefore.WriteLine("qListData->alloc = result->alloc;");
     ctx.SupportBefore.WriteLine("fixed (void** v = new void*[qListData->end])");
     ctx.SupportBefore.WriteStartBraceIndent();
     ctx.SupportBefore.WriteLine("for (int i = 0; i < qListData->end; i++)");
     ctx.SupportBefore.WriteStartBraceIndent();
     ctx.SupportBefore.WriteLine("v[i] = *(result->array + i);");
     ctx.SupportBefore.WriteCloseBraceIndent();
     ctx.SupportBefore.WriteLine("qListData->array = v;");
     ctx.SupportBefore.WriteCloseBraceIndent();
     ctx.SupportBefore.WriteLine("__instance._0.d = (IntPtr) qListData;");
 }
开发者ID:RodolpheFouquet,项目名称:QtSharp,代码行数:18,代码来源:QList.cs

示例4: CSharpMarshalToNative

 public override void CSharpMarshalToNative(MarshalContext ctx)
 {
     ctx.SupportBefore.WriteLine("var __qstring{0} = QString.FromUtf16((ushort*) Marshal.StringToHGlobalUni({1}).ToPointer(), {1}.Length);",
                                 ctx.ParameterIndex, ctx.Parameter.Name);
     Type type = ctx.Parameter.Type.Desugar();
     if (type.IsAddress())
     {
         ctx.Return.Write("ReferenceEquals(__qstring{0}, null) ? global::System.IntPtr.Zero : __qstring{0}.{1}",
                          ctx.ParameterIndex, Helpers.InstanceIdentifier);
         return;
     }
     Class @class;
     type.IsTagDecl(out @class);
     if (@class == null)
     {
         Type.IsTagDecl(out @class);
     }
     var qualifiedIdentifier = CSharpMarshalNativeToManagedPrinter.QualifiedIdentifier(@class.OriginalClass ?? @class);
     ctx.Return.Write("ReferenceEquals(__qstring{0}, null) ? new {1}.Internal() : *({1}.Internal*) (__qstring{0}.{2})",
                      ctx.ParameterIndex, qualifiedIdentifier, Helpers.InstanceIdentifier);
 }
开发者ID:RodolpheFouquet,项目名称:QtSharp,代码行数:21,代码来源:QString.cs

示例5: CSharpMarshalToNative

 public override void CSharpMarshalToNative(MarshalContext ctx)
 {
     ctx.SupportBefore.WriteLine("var __stringPtr{0} = (ushort*) Marshal.StringToHGlobalUni({1}).ToPointer();",
                                 ctx.ParameterIndex, ctx.Parameter.Name);
     ctx.SupportBefore.WriteLine("var __qstring{0} = QtCore.QString.FromUtf16(ref *__stringPtr{0}, {1}.Length);",
                                 ctx.ParameterIndex, ctx.Parameter.Name);
     Type type = ctx.Parameter.Type.Desugar();
     if (type.IsAddress())
     {
         ctx.Return.Write("ReferenceEquals(__qstring{0}, null) ? global::System.IntPtr.Zero : __qstring{0}.{1}",
                          ctx.ParameterIndex, Helpers.InstanceIdentifier);
         return;
     }
     Class @class;
     type.TryGetClass(out @class);
     if (@class == null)
     {
         Type.TryGetClass(out @class);
     }
     typePrinter = typePrinter ?? (typePrinter = new CSharpTypePrinter(ctx.Driver));
     var qualifiedIdentifier = (@class.OriginalClass ?? @class).Visit(typePrinter);
     ctx.Return.Write("ReferenceEquals(__qstring{0}, null) ? new {1}.Internal() : *({1}.Internal*) (__qstring{0}.{2})",
                      ctx.ParameterIndex, qualifiedIdentifier, Helpers.InstanceIdentifier);
 }
开发者ID:nanox,项目名称:QtSharp,代码行数:24,代码来源:QString.cs

示例6: CSharpMarshalToManaged

 public override void CSharpMarshalToManaged(MarshalContext ctx)
 {
     ctx.Return.Write("Marshal.PtrToStringUni(new IntPtr(new QString({0}).Utf16))", ctx.ReturnVarName);
 }
开发者ID:RodolpheFouquet,项目名称:QtSharp,代码行数:4,代码来源:QString.cs

示例7: CSharpMarshalToNative

 public override void CSharpMarshalToNative(MarshalContext ctx)
 {
     ctx.Return.Write("IntPtr.Zero");
 }
开发者ID:daxiazh,项目名称:CppSharp,代码行数:4,代码来源:Common.cs

示例8: CSharpMarshalToManaged

        public override void CSharpMarshalToManaged(MarshalContext ctx)
        {
            var templateType = Type as TemplateSpecializationType;
            var type = templateType.Arguments[0].Type;

            ctx.Return.Write("new Std.Vector<{0}>({1})", type,
                ctx.ReturnVarName);
        }
开发者ID:jijamw,项目名称:CppSharp,代码行数:8,代码来源:Stdlib.cs

示例9: CSharpMarshalCopyCtorToManaged

 public override void CSharpMarshalCopyCtorToManaged(MarshalContext ctx)
 {
     ctx.SupportBefore.WriteLine("var __instance = new {0}.Internal();", ctx.ReturnType);
     ctx.SupportBefore.WriteLine("__instance.i = {0}.i;", ctx.ReturnVarName);
 }
开发者ID:daxiazh,项目名称:CppSharp,代码行数:5,代码来源:QList.cs

示例10: CSharpMarshalToNative

 public override void CSharpMarshalToNative(MarshalContext ctx)
 {
     if (ctx.Parameter.Type.Desugar().IsAddress())
         ctx.Return.Write("new global::System.IntPtr(&{0})", ctx.Parameter.Name);
     else
         ctx.Return.Write(ctx.Parameter.Name);
 }
开发者ID:ymlai87416,项目名称:CppSharp,代码行数:7,代码来源:CSharp.cs

示例11: CLIMarshalToNative

 public override void CLIMarshalToNative(MarshalContext ctx)
 {
     var marshal = (CLIMarshalManagedToNativePrinter) ctx.MarshalToNative;
     if (!ctx.Parameter.Type.Desugar().IsPointer())
         marshal.ArgumentPrefix.Write("*");
     var marshalCtxName = string.Format("ctx_{0}", ctx.Parameter.Name);
     ctx.SupportBefore.WriteLine("msclr::interop::marshal_context {0};", marshalCtxName);
     ctx.Return.Write("{0}.marshal_as<std::ostream*>({1})",
         marshalCtxName, ctx.Parameter.Name);
 }
开发者ID:ddobrev,项目名称:CppSharp,代码行数:10,代码来源:Stdlib.cs

示例12: MarshalPrinter

 protected MarshalPrinter(MarshalContext ctx)
 {
     Context = ctx;
 }
开发者ID:kitsilanosoftware,项目名称:CppSharp,代码行数:4,代码来源:Marshal.cs

示例13: CSharpMarshalToNative

 public override void CSharpMarshalToNative(MarshalContext ctx)
 {
     TextGenerator supportBefore = ctx.SupportBefore;
     string suffix = ctx.ParameterIndex > 0 ? ctx.ParameterIndex.ToString(CultureInfo.InvariantCulture) : string.Empty;
     string qList = string.Format("__qList{0}", suffix);
     supportBefore.WriteLine(string.Format("var {0} = new QtCore.QList.Internal();", qList));
     string qListDataData = string.Format("__qlistDataData{0}", suffix);
     supportBefore.WriteLine("var {0} = (QListData.Data.Internal*) {1}._0.d;", qListDataData, qList);
     // TODO: tests with Qt shows that while alloc is not smaller than end, it's not equal, it reserves more space actually
     supportBefore.WriteLine("{0}->alloc = {1}.Count;", qListDataData, ctx.Parameter.Name);
     supportBefore.WriteLine("{0}->begin = 0;", qListDataData, ctx.Parameter.Name);
     supportBefore.WriteLine("{0}->end = {1}.Count;", qListDataData, ctx.Parameter.Name);
     supportBefore.WriteLine("fixed (void** __v = new void*[{0}.Count])", ctx.Parameter.Name);
     supportBefore.WriteStartBraceIndent();
     supportBefore.WriteLine("{0}->array = __v;", qListDataData);
     supportBefore.WriteCloseBraceIndent();
     supportBefore.WriteLine("", qListDataData, ctx.Parameter.Name);
     var parameterType = ctx.Parameter.Type.Desugar();
     TemplateSpecializationType type = parameterType as TemplateSpecializationType;
     if (type == null)
     {
         TypedefType typedef;
         if (parameterType.IsPointerTo(out typedef))
         {
             type = (TemplateSpecializationType) typedef.Desugar();
         }
         else
         {
             parameterType.IsPointerTo(out type);
         }
     }
     Type elementType = type.Arguments[0].Type.Type.Desugar();
     string instance = string.Empty;
     if (!elementType.IsPointerToPrimitiveType())
     {
         instance = string.Format(".{0}", Helpers.InstanceIdentifier);
     }
     supportBefore.WriteLine("for (int i = 0; i < {0}.Count; i++)", ctx.Parameter.Name);
     supportBefore.WriteStartBraceIndent();
     Type desugared = ctx.Parameter.Type.Desugar();
     TemplateSpecializationType templateSpecializationType = desugared as TemplateSpecializationType;
     if (templateSpecializationType == null)
     {
         Type paramType;
         desugared.IsPointerTo(out paramType);
         templateSpecializationType = (TemplateSpecializationType) paramType.Desugar();
     }
     TemplateArgument templateArgument = templateSpecializationType.Arguments[0];
     if (templateArgument.Type.ToString() == "string")
     {
         supportBefore.WriteLine("{0}->array[i] = Marshal.StringToHGlobalUni({1}[i]).ToPointer();", qListDataData, ctx.Parameter.Name, instance);
     }
     else
     {
         Class @class;
         if (templateArgument.Type.Type.IsTagDecl(out @class) && @class.IsValueType)
         {
             supportBefore.WriteLine("{0}.Internal __value = {1}[i].ToInternal();", @class.Name, ctx.Parameter.Name, instance);
             supportBefore.WriteLine("{0}->array[i] = &__value;", qListDataData, ctx.Parameter.Name, instance);
         }
         else
         {
             supportBefore.WriteLine("{0}->array[i] = (void*) {1}[i]{2};", qListDataData, ctx.Parameter.Name, instance);
         }
     }
     supportBefore.WriteCloseBraceIndent();
     ctx.Return.Write(qList);
 }
开发者ID:RodolpheFouquet,项目名称:QtSharp,代码行数:68,代码来源:QList.cs

示例14: CSharpMarshalToManaged

 public override void CSharpMarshalToManaged(MarshalContext ctx)
 {
 }
开发者ID:daxiazh,项目名称:CppSharp,代码行数:3,代码来源:QList.cs

示例15: CLIMarshalToNative

 public override void CLIMarshalToNative(MarshalContext ctx)
 {
     ctx.Return.Write("::TypeMappedIndex()");
 }
开发者ID:tritao,项目名称:CppSharp,代码行数:4,代码来源:Common.cs


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