本文整理汇总了C#中Type.GetNestedTypes方法的典型用法代码示例。如果您正苦于以下问题:C# Type.GetNestedTypes方法的具体用法?C# Type.GetNestedTypes怎么用?C# Type.GetNestedTypes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Type
的用法示例。
在下文中一共展示了Type.GetNestedTypes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddType
private void AddType (Type t, TreeNode parent)
{
TreeNode node = new TreeNode (t.FullName);
node.ImageIndex = 1;
parent.Nodes.Add (node);
foreach (Type nt in t.GetNestedTypes ()) {
AddType (nt, node);
}
}
示例2: GetNestedTypes
public static Type[] GetNestedTypes(Type type, BindingFlags bindingAttr)
{
Requires.NotNull(type, "type");
return type.GetNestedTypes(bindingAttr);
}
示例3: ParseNestedType
// Parse nested types.
private Type ParseNestedType(ParserContext parserContext, Type currentType)
{
System.Diagnostics.Debug.Assert(parserContext.CurrentToken.TokenID == TokenID.Dot);
Type nestedType = null;
while (parserContext.CurrentToken.TokenID == TokenID.Dot)
{
// Save the state of the scanner. Since we can't tell if we're parsing a nested
// type or a member, we'll need to backtrack if we go too far.
int savedTokenState = parserContext.SaveCurrentToken();
Token token = parserContext.NextToken();
if (token.TokenID != TokenID.Identifier)
{
if (parserContext.provideIntellisense && token.TokenID == TokenID.EndOfInput)
{
parserContext.SetTypeMemberCompletions(currentType, validation.ThisType, true, validation);
return null;
}
else
{
throw new RuleSyntaxException(ErrorNumbers.Error_MissingIdentifierAfterDot, Messages.Parser_MissingIdentifierAfterDot, parserContext.CurrentToken.StartPosition);
}
}
string name = (string)token.Value;
BindingFlags bindingFlags = BindingFlags.Public;
if (currentType.Assembly == validation.ThisType.Assembly)
bindingFlags |= BindingFlags.NonPublic;
if (parserContext.NextToken().TokenID == TokenID.Less)
{
// Might be a generic type.
List<Type> candidateGenericTypes = new List<Type>();
Type[] nestedTypes = currentType.GetNestedTypes(bindingFlags);
string prefix = name + "`";
for (int i = 0; i < nestedTypes.Length; ++i)
{
Type candidateType = nestedTypes[i];
if (candidateType.Name.StartsWith(prefix, StringComparison.Ordinal))
candidateGenericTypes.Add(candidateType);
}
if (candidateGenericTypes.Count == 0)
{
// It wasn't a generic type. Reset the scanner to the saved state.
parserContext.RestoreCurrentToken(savedTokenState);
// Also reset the deepenst nested type.
nestedType = currentType;
break;
}
nestedType = ParseGenericType(parserContext, candidateGenericTypes, name);
currentType = nestedType;
}
else
{
// Might be a non-generic type.
MemberInfo[] mi = currentType.GetMember(name, bindingFlags);
if (mi == null || mi.Length != 1 || (mi[0].MemberType != MemberTypes.NestedType && mi[0].MemberType != MemberTypes.TypeInfo))
{
// We went too far, reset the state.
parserContext.RestoreCurrentToken(savedTokenState);
// Also reset the deepest nested type.
nestedType = currentType;
break;
}
nestedType = (Type)mi[0];
if (currentType.IsGenericType && nestedType.IsGenericTypeDefinition)
{
// The outer type was generic (and bound), but the nested type is not. We have
// to re-bind the generic arguments.
nestedType = nestedType.MakeGenericType(currentType.GetGenericArguments());
}
currentType = nestedType;
}
}
return nestedType;
}