本文整理汇总了C#中PointerType.GetFinalPointee方法的典型用法代码示例。如果您正苦于以下问题:C# PointerType.GetFinalPointee方法的具体用法?C# PointerType.GetFinalPointee怎么用?C# PointerType.GetFinalPointee使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PointerType
的用法示例。
在下文中一共展示了PointerType.GetFinalPointee方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitPointerType
public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
{
if (!VisitType(pointer, quals))
return false;
var param = Context.Parameter;
var isRefParam = param != null && (param.IsInOut || param.IsOut);
var pointee = pointer.Pointee.Desugar();
bool marshalPointeeAsString = CSharpTypePrinter.IsConstCharString(pointee) && isRefParam;
if (CSharpTypePrinter.IsConstCharString(pointer) || marshalPointeeAsString)
{
if (param.IsOut)
{
Context.Return.Write("IntPtr.Zero");
CSharpContext.ArgumentPrefix.Write("&");
}
else if (param.IsInOut)
{
Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
CSharpContext.ArgumentPrefix.Write("&");
}
else
{
Context.Return.Write(MarshalStringToUnmanaged(Context.Parameter.Name));
CSharpContext.Cleanup.WriteLine("Marshal.FreeHGlobal({0});", Context.ArgName);
}
return true;
}
if (pointee is FunctionType)
{
var function = pointee as FunctionType;
return VisitDelegateType(function, function.ToString());
}
Class @class;
if (pointee.TryGetClass(out @class) && @class.IsValueType)
{
if (Context.Parameter.Usage == ParameterUsage.Out)
{
Context.SupportBefore.WriteLine("var {0} = new {1}.Internal();",
Generator.GeneratedIdentifier(Context.ArgName), @class.Name);
}
else
{
Context.SupportBefore.WriteLine("var {0} = {1}.{2};",
Generator.GeneratedIdentifier(Context.ArgName),
Context.Parameter.Name,
Helpers.InstanceIdentifier);
}
Context.Return.Write("new global::System.IntPtr(&{0})",
Generator.GeneratedIdentifier(Context.ArgName));
return true;
}
var finalPointee = pointer.GetFinalPointee();
PrimitiveType primitive;
if (finalPointee.IsPrimitiveType(out primitive) || finalPointee.IsEnumType())
{
// From MSDN: "note that a ref or out parameter is classified as a moveable
// variable". This means we must create a local variable to hold the result
// and then assign this value to the parameter.
if (isRefParam)
{
var typeName = Type.TypePrinterDelegate(finalPointee);
if (param.IsInOut)
Context.SupportBefore.WriteLine("{0} _{1} = {1};", typeName, param.Name);
else
Context.SupportBefore.WriteLine("{0} _{1};", typeName, param.Name);
Context.Return.Write("&_{0}", param.Name);
}
else
Context.Return.Write(Context.Parameter.Name);
return true;
}
return pointer.Pointee.Visit(this, quals);
}
示例2: VisitPointerType
public override bool VisitPointerType(PointerType pointer, TypeQualifiers quals)
{
if (!VisitType(pointer, quals))
return false;
var pointee = pointer.Pointee.Desugar();
if ((pointee.IsPrimitiveType(PrimitiveType.Char) ||
pointee.IsPrimitiveType(PrimitiveType.WideChar)) &&
pointer.QualifiedPointee.Qualifiers.IsConst)
{
Context.SupportBefore.WriteLine(
"auto _{0} = clix::marshalString<clix::E_UTF8>({1});",
Context.ArgName, Context.Parameter.Name);
Context.Return.Write("_{0}.c_str()", Context.ArgName);
return true;
}
if (pointee is FunctionType)
{
var function = pointee as FunctionType;
var cppTypePrinter = new CppTypePrinter(Context.Driver.TypeDatabase);
var cppTypeName = pointer.Visit(cppTypePrinter, quals);
return VisitDelegateType(function, cppTypeName);
}
Enumeration @enum;
if (pointee.TryGetEnum(out @enum))
{
var isRef = Context.Parameter.Usage == ParameterUsage.Out ||
Context.Parameter.Usage == ParameterUsage.InOut;
ArgumentPrefix.Write("&");
Context.Return.Write("(::{0}){1}{2}", @enum.QualifiedOriginalName,
isRef ? string.Empty : "*", Context.Parameter.Name);
return true;
}
Class @class;
if (pointee.TryGetClass(out @class) && @class.IsValueType)
{
if (Context.Function == null)
Context.Return.Write("&");
return pointee.Visit(this, quals);
}
var finalPointee = pointer.GetFinalPointee();
if (finalPointee.IsPrimitiveType())
{
var cppTypePrinter = new CppTypePrinter(Context.Driver.TypeDatabase);
var cppTypeName = pointer.Visit(cppTypePrinter, quals);
Context.Return.Write("({0})", cppTypeName);
Context.Return.Write(Context.Parameter.Name);
return true;
}
return pointer.Pointee.Visit(this, quals);
}