本文整理汇总了C#中Type.GetAllFields方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetAllFields方法的具体用法?C# Type.GetAllFields怎么用?C# Type.GetAllFields使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.GetAllFields方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: showSignatureButton
private void showSignatureButton( Type type, string memberName )
{
EditorGUILayout.BeginHorizontal();
GUILayout.Space( 105 );
if( GUILayout.Button( "Copy Event Signature", "minibutton" ) )
{
var member = type.GetAllFields().Where( x => x.Name == memberName ).FirstOrDefault();
if( member == null )
{
Debug.LogError( string.Format( "Member not found: {0}.{1}", type.Name, memberName ) );
return;
}
var invoke = member.FieldType.GetMethod( "Invoke" );
if( invoke == null )
{
Debug.LogError( "Could not retrieve event signature for " + type.Name + "." + memberName );
return;
}
var buffer = new StringBuilder();
buffer.Append( "public " );
if( invoke.ReturnType == typeof( void ) )
buffer.Append( "void" );
else
buffer.Append( invoke.ReturnType.Name );
buffer.Append( " On" + memberName );
buffer.Append( "( " );
var paramList = invoke.GetParameters();
for( int i = 0; i < paramList.Length; i++ )
{
if( i > 0 ) buffer.Append( ", " );
var param = paramList[i];
buffer.Append( param.ParameterType );
buffer.Append( " " );
buffer.Append( param.Name );
}
buffer.Append( " )\r\n{\r\n\t// Add event handler code here\r\n}\r\n" );
dfClipboardHelper.clipBoard = buffer.ToString();
Debug.Log( buffer.ToString() );
}
EditorGUILayout.EndHorizontal();
}
示例2: getField
private FieldInfo getField( Type type, string fieldName )
{
return
type.GetAllFields()
.Where( f => f.Name == fieldName )
.FirstOrDefault();
}
示例3: getField
private FieldInfo getField(Type type, string fieldName)
{
return (
from f in type.GetAllFields()
where f.Name == fieldName
select f).FirstOrDefault<FieldInfo>();
}