本文整理汇总了C#中ComposedType.AddChild方法的典型用法代码示例。如果您正苦于以下问题:C# ComposedType.AddChild方法的具体用法?C# ComposedType.AddChild怎么用?C# ComposedType.AddChild使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ComposedType
的用法示例。
在下文中一共展示了ComposedType.AddChild方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Visit
public override object Visit(ComposedCast composedCast)
{
var result = new ComposedType();
result.AddChild(ConvertToType(composedCast.Left), Roles.Type);
var spec = composedCast.Spec;
while (spec != null) {
if (spec.IsNullable) {
result.AddChild(new CSharpTokenNode(Convert(spec.Location), ComposedType.NullableRole), ComposedType.NullableRole);
} else if (spec.IsPointer) {
result.AddChild(new CSharpTokenNode(Convert(spec.Location), ComposedType.PointerRole), ComposedType.PointerRole);
} else {
var aSpec = new ArraySpecifier();
aSpec.AddChild(new CSharpTokenNode(Convert(spec.Location), Roles.LBracket), Roles.LBracket);
var location = LocationsBag.GetLocations(spec);
if (location != null)
aSpec.AddChild(new CSharpTokenNode(Convert(spec.Location), Roles.RBracket), Roles.RBracket);
result.AddChild(aSpec, ComposedType.ArraySpecifierRole);
}
spec = spec.Next;
}
return result;
}
示例2: ConvertToType
AstType ConvertToType (Mono.CSharp.Expression typeName)
{
if (typeName == null) // may happen in typeof(Generic<,,,,>)
return new SimpleType ();
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;
var memberType = new MemberType ();
memberType.Target = new SimpleType (qam.alias, Convert (qam.Location));
memberType.IsDoubleColon = true;
memberType.MemberName = qam.Name;
return memberType;
}
if (typeName is MemberAccess) {
MemberAccess ma = (MemberAccess)typeName;
var memberType = new MemberType ();
memberType.AddChild (ConvertToType (ma.LeftExpression), MemberType.TargetRole);
memberType.AddChild (new CSharpTokenNode (Convert (ma.DotLocation), 1), MemberType.Roles.Dot);
memberType.MemberNameToken = Identifier.Create (ma.Name, Convert (ma.Location));
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 };
var ccSpec = cc.Spec;
while (ccSpec != null) {
if (ccSpec.IsNullable) {
result.AddChild (new CSharpTokenNode (Convert (ccSpec.Location), 1), ComposedType.NullableRole);
} else if (ccSpec.IsPointer) {
result.AddChild (new CSharpTokenNode (Convert (ccSpec.Location), 1), ComposedType.PointerRole);
} else {
var location = LocationsBag.GetLocations (ccSpec);
var spec = new ArraySpecifier () { Dimensions = ccSpec.Dimension };
spec.AddChild (new CSharpTokenNode (Convert (ccSpec.Location), 1), FieldDeclaration.Roles.LBracket);
if (location != null)
spec.AddChild (new CSharpTokenNode (Convert (location [0]), 1), FieldDeclaration.Roles.RBracket);
result.ArraySpecifiers.Add (spec);
}
ccSpec = ccSpec.Next;
}
return result;
}
if (typeName is SpecialContraintExpr) {
var sce = (SpecialContraintExpr)typeName;
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));
}
}
System.Console.WriteLine ("Error while converting :" + typeName + " - unknown type name");
System.Console.WriteLine (Environment.StackTrace);
return new SimpleType ("unknown");
}
示例3: 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");
}
示例4: 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;
var memberType = new MonoDevelop.CSharp.Ast.MemberType ();
if (qam.LeftExpression == null) {
memberType.Target = new SimpleType ("global", Convert (qam.Location));
} else {
memberType.Target = ConvertToType (qam.LeftExpression);
}
memberType.IsDoubleColon = true;
memberType.MemberName = qam.Name;
return memberType;
}
if (typeName is MemberAccess) {
MemberAccess ma = (MemberAccess)typeName;
var memberType = new MonoDevelop.CSharp.Ast.MemberType ();
memberType.AddChild (ConvertToType (ma.LeftExpression), MonoDevelop.CSharp.Ast.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 };
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.AddChild (spec, ComposedType.ArraySpecifierRole);
}
return result;
}
System.Console.WriteLine ("Error while converting :" + typeName + " - unknown type name");
System.Console.WriteLine (Environment.StackTrace);
return new SimpleType ("unknown");
}