本文整理汇总了C#中Generator.ResolveType方法的典型用法代码示例。如果您正苦于以下问题:C# Generator.ResolveType方法的具体用法?C# Generator.ResolveType怎么用?C# Generator.ResolveType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Generator
的用法示例。
在下文中一共展示了Generator.ResolveType方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EmitCode
public override void EmitCode(Generator generator, int depth, int ident)
{
if ( String.IsNullOrEmpty( GetName() ) )
return;
INode returntype;
bool constness, pointer;
string types = base.ResolveType( 1, out returntype, out constness, out pointer );
types = generator.ResolveType( types, constness, pointer, true, false );
generator.EmitLine( "public enum " + name + " : " + EnumShortCodes[types], depth );
generator.EmitLine( "{", depth );
foreach( INode child in children )
{
if ( child is EnumConstantNode )
{
generator.EmitLine( String.Format( "{0} = {1},", child.GetName(), child.GetAttribute( "value" ) ), depth + 1 );
}
}
generator.EmitLine( "};", depth );
generator.EmitLine( "", depth );
}
示例2: EmitCodeInnerStructCallback
public int EmitCodeInnerStructCallback(Generator generator, int depth)
{
// don't emit an anonymous enum reference, the real enum is attached through the context
if (typeNode is EnumNode)
return -1;
INode returntype;
bool constness, pointer;
string types = base.ResolveType(1, out returntype, out constness, out pointer);
types = generator.ResolveType(types, constness, pointer, true, false);
foreach (INode child in children)
{
if (child is EnumConstantNode)
{
generator.EmitLine(String.Format("public const {0} {1} = {2};", EnumShortCodes[types], child.GetName(), child.GetAttribute("value")), depth);
return Convert.ToInt32(child.GetAttribute("value"));
}
}
return -1;
}
示例3: EmitCode
public override void EmitCode(Generator generator, int depth, int ident)
{
bool genericwrapper = false, returnbystack = false, returnbystack_special = false;
int sidarg_count = 0;
List<int> maskedparams = new List<int>();
INode returntype;
bool constness, pointer;
string returns_base = base.ResolveType( 0, out returntype, out constness, out pointer );
Debug.Assert(returns_base != null);
if ( returns_base == null )
{
returns_base = "(null)";
}
string returns = returns_base;
if ( pointer )
{
if ((returntype is RecordNode && returntype.GetAttribute("kind") == "class" && returntype.GetName().StartsWith("I") ) ||
(returntype is FundamentalTypeNode && returns == "void"))
{
genericwrapper = true;
returns = "IntPtr";
}
}
else if ( returntype is RecordNode )
{
returnbystack = true;
if (returntype.GetName() == "CSteamID" || returntype.GetName() == "CGameID")
{
returnbystack_special = true;
}
}
returns = generator.ResolveType( returns, constness, pointer, true, false );
/*if (returns == "UInt64" || returns == "Int64")
{
returnbystack = true;
}
*/
List<INode> args = new List<INode>();
foreach( INode child in children )
{
if ( child is ParmVarNode )
{
args.Add( child );
}
}
List<string> arg = new List<string>();
List<string> arg_native = new List<string>();
List<string> arg_native_pure = new List<string>();
arg_native.Add( "IntPtr thisptr" );
if (returnbystack)
{
if (returnbystack_special)
arg_native.Add("ref UInt64 retarg");
else
arg_native.Add("ref " + returns + " retarg");
}
bool prevarg_sb = false;
for (int i = 0; i < args.Count; i++)
{
INode argtype;
bool argconst, argpointer;
string argname = args[i].GetName();
string argtypes = args[i].ResolveType(0, out argtype, out argconst, out argpointer);
Debug.Assert(argtypes != null);
argtypes = generator.ResolveType(argtypes, argconst, argpointer, false, true);
if ( argtypes == "StringBuilder" || argtypes == "Byte[]" )
{
prevarg_sb = true;
}
else if ((argtypes == "Int32" || argtypes == "UInt32")
&& prevarg_sb
&& (argname.StartsWith("c") || argname.StartsWith("u") || argname.StartsWith("i") )
)
{
maskedparams.Add(i);
prevarg_sb = false;
//.........这里部分代码省略.........
示例4: EmitCodeStruct
private void EmitCodeStruct(Generator generator, int depth, int ident)
{
generator.EmitLine("[StructLayout(LayoutKind.Sequential,Pack=8)]", depth);
int attribMarker = generator.GetMarker();
generator.EmitLine("public struct " + GetName(), depth);
generator.EmitLine("{", depth);
foreach (INode child in children)
{
if ( child is FieldNode && !String.IsNullOrEmpty( child.GetName() ) )
{
INode basetype;
bool constness, pointer;
bool arraytype = false;
string size = "";
string types = child.ResolveType( 0, out basetype, out constness, out pointer );
if ( basetype is ArrayTypeNode )
{
size = basetype.GetAttribute("size");
types = basetype.ResolveType(1, out basetype, out constness, out pointer);
pointer = true;
arraytype = true;
}
types = generator.ResolveType( types, constness, pointer, true, false );
if ( types == "bool" )
{
generator.EmitLine( "[MarshalAs(UnmanagedType.I1)]", depth + 1 );
}
else if ( types == "string" )
{
if (arraytype)
{
generator.EmitLine("[MarshalAs(UnmanagedType.ByValTStr, SizeConst = " + size + ")]", depth + 1);
}
else
{
types = "string";
}
}
else if ( types == "Byte[]" )
{
if (arraytype)
{
generator.EmitLine("[MarshalAs(UnmanagedType.ByValArray, SizeConst = " + size + ")]", depth + 1);
}
else
{
types = "IntPtr";
}
}
else if ( types == "CSteamID" || types == "CGameID" )
{
types = "UInt64";
}
else if (pointer)
{
types = "IntPtr";
}
else if (types == child.GetName())
{
continue;
}
generator.EmitLine( String.Format( "public {0} {1};", types, child.GetName() ), depth + 1 );
}
else if(child is EnumNode)
{
// anonymous enum declaration
EnumNode innerEnum = child as EnumNode;
int callback = innerEnum.EmitCodeInnerStructCallback(generator, depth + 1);
if(callback > 0)
{
generator.InsertLine("[InteropHelp.CallbackIdentity(" + callback + ")]", attribMarker, depth);
}
}
else if(child is FieldNode)
{
// anonymous field like union
// not implemented!
}
}
generator.EmitLine("};", depth);
generator.EmitLine("", depth);
}
示例5: EmitCode
public override void EmitCode(Generator generator, int depth, int ident)
{
bool genericwrapper = false;
List<int> maskedparams = new List<int>();
INode returntype;
bool constness, pointer;
string returns_base = base.ResolveType( 0, out returntype, out constness, out pointer );
Debug.Assert(returns_base != null);
if ( returns_base == null )
{
returns_base = "(null)";
}
string returns = returns_base;
if ( pointer )
{
if ((returntype is RecordNode && returntype.GetAttribute("kind") == "class" && returntype.GetName().StartsWith("I") ) ||
(returntype is FundamentalTypeNode && returns == "void"))
{
genericwrapper = true;
returns = "IntPtr";
}
}
returns = generator.ResolveType( returns, constness, pointer, true, false );
/*if (returns == "UInt64" || returns == "Int64")
{
returnbystack = true;
}
*/
List<INode> args = new List<INode>();
foreach( INode child in children )
{
if ( child is ParmVarNode )
{
args.Add( child );
}
}
List<string> arg = new List<string>();
List<string> arg_native = new List<string>();
List<string> arg_native_pure = new List<string>();
arg_native.Add( "IntPtr thisptr" );
for (int i = 0; i < args.Count; i++)
{
INode argtype;
bool argconst, argpointer;
string argname = args[i].GetName();
string argtypes = args[i].ResolveType(0, out argtype, out argconst, out argpointer);
Debug.Assert(argtypes != null);
argtypes = generator.ResolveType(argtypes, argconst, argpointer, false, true);
if ( genericwrapper && argtypes == "string" )
{
maskedparams.Add( i );
}
if ( String.IsNullOrEmpty( argname ) )
{
argname = "arg" + i;
}
if ( !maskedparams.Contains( i ) )
arg.Add( argtypes + " " + argname );
}
string methodname = GetName();
string extra = "";
if ( genericwrapper )
{
returns = "TClass";
methodname = methodname + "<TClass>";
extra = " where TClass : class";
}
generator.EmitLine( String.Format( "[VTableSlot({0})]", ident ), depth );
generator.EmitLine( String.Format( "{0} {1}({2}){3};", returns, methodname, String.Join(", ", arg.ToArray() ), extra), depth );
}