本文整理汇总了C#中MemberType.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# MemberType.AddChild方法的具体用法?C# MemberType.AddChild怎么用?C# MemberType.AddChild使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MemberType
的用法示例。
在下文中一共展示了MemberType.AddChild方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ConvertToType
AstType ConvertToType (MemberName memberName)
{
AstType result;
if (memberName.Left != null) {
result = new MemberType () { MemberName = memberName.Name };
result.AddChild (ConvertToType (memberName.Left), MemberType.TargetRole);
} else {
result = new SimpleType () { Identifier = memberName.Name };
}
if (memberName.TypeArguments != null && !memberName.TypeArguments.IsEmpty) {
foreach (var arg in memberName.TypeArguments.Args) {
result.AddChild (ConvertToType (arg), AstType.Roles.TypeArgument);
}
}
return result;
}
示例2: GlobalFullNamespaceGenericFieldReferenceExpressionTest
public void GlobalFullNamespaceGenericFieldReferenceExpressionTest()
{
var target = new MemberType {
Target = new SimpleType("global"),
IsDoubleColon = true,
MemberName = "Namespace"
}.Member("Subnamespace").Member ("SomeClass");
target.AddChild (new PrimitiveType("string"), Roles.TypeArgument);
ParseUtilCSharp.AssertExpression(
"global::Namespace.Subnamespace.SomeClass<string>.myField",
new MemberReferenceExpression {
Target = target,
MemberName = "myField"
}
);
}
示例3: ConvertImport
AstType ConvertImport(MemberName memberName)
{
if (memberName.Left != null) {
// left.name
var t = new MemberType();
// t.IsDoubleColon = memberName.IsDoubleColon;
t.AddChild(ConvertImport(memberName.Left), MemberType.TargetRole);
var loc = LocationsBag.GetLocations(memberName);
if (loc != null)
t.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.Dot), Roles.Dot);
t.AddChild(Identifier.Create(memberName.Name, Convert(memberName.Location)), Roles.Identifier);
AddTypeArguments(t, memberName);
return t;
} else {
var t = new SimpleType();
t.AddChild(Identifier.Create(memberName.Name, Convert(memberName.Location)), Roles.Identifier);
AddTypeArguments(t, memberName);
return t;
}
}
示例4: Visit
public override object Visit(QualifiedAliasMember qualifiedAliasMember)
{
var result = new MemberType();
result.Target = new SimpleType(qualifiedAliasMember.alias, Convert(qualifiedAliasMember.Location));
result.IsDoubleColon = true;
var location = LocationsBag.GetLocations(qualifiedAliasMember);
if (location != null && location.Count > 0)
result.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.DoubleColon), Roles.DoubleColon);
AddTypeArguments(result, qualifiedAliasMember);
result.AddChild(Identifier.Create(qualifiedAliasMember.Name, location != null && location.Count > 1 ? Convert(location [1]) : TextLocation.Empty), Roles.Identifier);
return new TypeReferenceExpression { Type = result };
}
示例5: ConvertToType
AstType ConvertToType(Mono.CSharp.Expression typeName)
{
if (typeName == null) // may happen in typeof(Generic<,,,,>)
return new SimpleType();
var typeExpr = typeName as TypeExpression;
if (typeExpr != null) {
return new PrimitiveType(typeExpr.GetSignatureForError(), Convert(typeExpr.Location));
}
var qam = typeName as QualifiedAliasMember;
if (qam != null) {
var loc = LocationsBag.GetLocations(typeName);
var memberType = new MemberType();
memberType.Target = new SimpleType(qam.alias, Convert(qam.Location));
memberType.IsDoubleColon = true;
if (loc != null && loc.Count > 0)
memberType.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.DoubleColon), Roles.DoubleColon);
memberType.MemberNameToken = Identifier.Create(qam.Name, loc != null ? Convert(loc [1]) : TextLocation.Empty);
AddTypeArguments(qam, memberType);
return memberType;
}
var ma = typeName as MemberAccess;
if (ma != null) {
var memberType = new MemberType();
memberType.AddChild(ConvertToType(ma.LeftExpression), MemberType.TargetRole);
var loc = LocationsBag.GetLocations(ma);
if (loc != null)
memberType.AddChild(new CSharpTokenNode(Convert(loc [0]), Roles.Dot), Roles.Dot);
memberType.MemberNameToken = Identifier.Create(ma.Name, Convert(ma.Location));
AddTypeArguments(ma, memberType);
return memberType;
}
var sn = typeName as SimpleName;
if (sn != null) {
var result = new SimpleType(sn.Name, Convert(sn.Location));
AddTypeArguments(sn, result);
return result;
}
var cc = typeName as ComposedCast;
if (cc != null) {
var baseType = ConvertToType(cc.Left);
var result = new ComposedType { BaseType = baseType };
var ccSpec = cc.Spec;
while (ccSpec != null) {
if (ccSpec.IsNullable) {
result.AddChild(new CSharpTokenNode(Convert(ccSpec.Location), ComposedType.NullableRole), ComposedType.NullableRole);
} else if (ccSpec.IsPointer) {
result.AddChild(new CSharpTokenNode(Convert(ccSpec.Location), ComposedType.PointerRole), ComposedType.PointerRole);
} else {
var location = LocationsBag.GetLocations(ccSpec);
var spec = new ArraySpecifier { Dimensions = ccSpec.Dimension };
spec.AddChild(new CSharpTokenNode(Convert(ccSpec.Location), Roles.LBracket), Roles.LBracket);
if (location != null)
spec.AddChild(new CSharpTokenNode(Convert(location [0]), Roles.RBracket), Roles.RBracket);
result.ArraySpecifiers.Add(spec);
}
ccSpec = ccSpec.Next;
}
return result;
}
var sce = typeName as SpecialContraintExpr;
if (sce != null) {
switch (sce.Constraint) {
case SpecialConstraint.Class:
return new PrimitiveType("class", Convert(sce.Location));
case SpecialConstraint.Struct:
return new PrimitiveType("struct", Convert(sce.Location));
case SpecialConstraint.Constructor:
return new PrimitiveType("new", Convert(sce.Location));
}
}
return new SimpleType("unknown");
}
示例6: Visit
public override object Visit(QualifiedAliasMember qualifiedAliasMember)
{
var result = new MemberType ();
result.Target = new SimpleType (qualifiedAliasMember.alias, Convert (qualifiedAliasMember.Location));
result.IsDoubleColon = true;
var location = LocationsBag.GetLocations (qualifiedAliasMember);
result.AddChild (Identifier.Create (qualifiedAliasMember.Name, location != null ? Convert (location [0]) : TextLocation.Empty), Roles.Identifier);
return new TypeReferenceExpression () { Type = result };
}
示例7: ConvertToType
AstType ConvertToType (MemberName memberName)
{
AstType result;
if (memberName.Left != null) {
result = new MemberType ();
result.AddChild (ConvertToType (memberName.Left), MemberType.TargetRole);
var loc = LocationsBag.GetLocations (memberName.Left);
if (loc != null)
result.AddChild (new CSharpTokenNode (Convert (loc [0]), 1), MemberType.Roles.Dot);
result.AddChild (Identifier.Create (memberName.Name, Convert (memberName.Location)), MemberType.Roles.Identifier);
} else {
result = new SimpleType () { IdentifierToken = Identifier.Create (memberName.Name, Convert (memberName.Location)) };
}
if (memberName.TypeArguments != null && !memberName.TypeArguments.IsEmpty) {
var chevronLocs = LocationsBag.GetLocations (memberName.TypeArguments);
if (chevronLocs != null)
result.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 2]), 1), InvocationExpression.Roles.LChevron);
int i = 0;
foreach (var arg in memberName.TypeArguments.Args) {
result.AddChild (ConvertToType (arg), AstType.Roles.TypeArgument);
if (chevronLocs != null && i < chevronLocs.Count - 2)
result.AddChild (new CSharpTokenNode (Convert (chevronLocs [i++]), 1), InvocationExpression.Roles.Comma);
}
if (chevronLocs != null)
result.AddChild (new CSharpTokenNode (Convert (chevronLocs[chevronLocs.Count - 1]), 1), InvocationExpression.Roles.RChevron);
}
return result;
}
示例8: ConvertImport
AstType ConvertImport (MemberName memberName)
{
if (memberName.Left != null) {
// left.name
var t = new MemberType();
t.IsDoubleColon = memberName.IsDoubleColon;
t.AddChild (ConvertImport (memberName.Left), MemberType.TargetRole);
if (!memberName.DotLocation.IsNull)
t.AddChild (new CSharpTokenNode (Convert (memberName.DotLocation), 1), MemberType.Roles.Dot);
t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), MemberType.Roles.Identifier);
AddTypeArguments (t, memberName.TypeArguments);
return t;
} else {
SimpleType t = new SimpleType();
t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), SimpleType.Roles.Identifier);
AddTypeArguments (t, memberName.TypeArguments);
return t;
}
}
示例9: ConvertImport
AstType ConvertImport (MemberName memberName)
{
if (memberName.Left != null) {
// left.name
var t = new MemberType();
t.IsDoubleColon = memberName.IsDoubleColon;
t.AddChild (ConvertImport (memberName.Left), MemberType.TargetRole);
t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), MemberType.Roles.Identifier);
AddTypeArguments (t, (List<Location>)null, memberName.TypeArguments);
return t;
} else {
SimpleType t = new SimpleType();
t.AddChild (Identifier.Create (memberName.Name, Convert(memberName.Location)), SimpleType.Roles.Identifier);
AddTypeArguments (t, (List<Location>)null, memberName.TypeArguments);
return t;
}
}
示例10: ConvertToType
AstType ConvertToType (Mono.CSharp.Expression typeName)
{
if (typeName is TypeExpression) {
var typeExpr = (Mono.CSharp.TypeExpression)typeName;
return new PrimitiveType (typeExpr.GetSignatureForError (), Convert (typeExpr.Location));
}
if (typeName is Mono.CSharp.QualifiedAliasMember) {
var qam = (Mono.CSharp.QualifiedAliasMember)typeName;
return new SimpleType (qam.Name, Convert (qam.Location));
}
if (typeName is MemberAccess) {
MemberAccess ma = (MemberAccess)typeName;
var memberType = new MemberType ();
memberType.AddChild (ConvertToType (ma.LeftExpression), MemberType.TargetRole);
memberType.MemberName = ma.Name;
AddTypeArguments (ma, memberType);
return memberType;
}
if (typeName is SimpleName) {
var sn = (SimpleName)typeName;
var result = new SimpleType (sn.Name, Convert (sn.Location));
AddTypeArguments (sn, result);
return result;
}
if (typeName is ComposedCast) {
var cc = (ComposedCast)typeName;
var baseType = ConvertToType (cc.Left);
var result = new ComposedType () { BaseType = baseType };
if (cc.Spec.IsNullable) {
result.HasNullableSpecifier = true;
} else if (cc.Spec.IsPointer) {
result.PointerRank++;
} else {
var location = LocationsBag.GetLocations (cc.Spec);
var spec = new ArraySpecifier () { Dimensions = cc.Spec.Dimension - 1 };
spec.AddChild (new CSharpTokenNode (Convert (cc.Spec.Location), 1), FieldDeclaration.Roles.LBracket);
if (location != null)
spec.AddChild (new CSharpTokenNode (Convert (location[0]), 1), FieldDeclaration.Roles.RBracket);
result.ArraySpecifiers.Add(spec);
}
return result;
}
System.Console.WriteLine ("Error while converting :" + typeName + " - unknown type name");
return new SimpleType ("unknown");
}
示例11: ConvertImport
AstType ConvertImport (MemberName memberName)
{
if (memberName.Left != null) {
// left.name
MemberType t = new MemberType();
t.IsDoubleColon = memberName.IsDoubleColon;
t.AddChild (ConvertImport (memberName.Left), MemberType.TargetRole);
t.AddChild (new Identifier (memberName.Name, Convert(memberName.Location)), MemberType.Roles.Identifier);
return t;
} else {
SimpleType t = new SimpleType();
t.AddChild (new Identifier (memberName.Name, Convert(memberName.Location)), SimpleType.Roles.Identifier);
// TODO type arguments
return t;
}
}
示例12: Visit
public override object Visit (QualifiedAliasMember qualifiedAliasMember)
{
var result = new MemberType ();
result.Target = new SimpleType (qualifiedAliasMember.alias);
result.IsDoubleColon = true;
result.AddChild (new Identifier (qualifiedAliasMember.Name, Convert (qualifiedAliasMember.Location)), MemberReferenceExpression.Roles.Identifier);
return new TypeReferenceExpression () { Type = result };
}