本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax.HasInitializableMembers方法的典型用法代码示例。如果您正苦于以下问题:C# ClassDeclarationSyntax.HasInitializableMembers方法的具体用法?C# ClassDeclarationSyntax.HasInitializableMembers怎么用?C# ClassDeclarationSyntax.HasInitializableMembers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.ClassDeclarationSyntax
的用法示例。
在下文中一共展示了ClassDeclarationSyntax.HasInitializableMembers方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitClassDeclaration
public override void VisitClassDeclaration(ClassDeclarationSyntax node)
{
// generate empty ctor if necessary
if (node.HasInitializableMembers(model) && !node.HasDefaultConstructor())
{
cb.AppendWithIndent(node.Identifier.ToString())
.Append("::")
.Append(node.Identifier.ToString())
.AppendLine("() :");
//cb.Indent(() =>
//{
// AppendFieldInitializers(node);
//});
cb.AppendLine("{}").AppendLine();
}
// generate static initialization
foreach (var fields in node.ChildNodes().OfType<FieldDeclarationSyntax>())
{
foreach (var v in fields.Declaration.Variables)
{
var z = (IFieldSymbol)model.GetDeclaredSymbol(v);
if (z.IsStatic && v.Initializer != null)
{
cb.AppendWithIndent("extern ")
.Append(node.Identifier.ToString())
.Append("::")
.Append(v.Identifier.ToString())
.Append(" = ")
.Append(v.Initializer.Value.ToString())
.AppendLine(";").AppendLine();
}
}
}
base.VisitClassDeclaration(node);
}
示例2: VisitClassDeclaration
public override void VisitClassDeclaration(ClassDeclarationSyntax node)
{
// be sure to add the includes
cb.AppendLine($"#include <{node.Identifier.Text}.h>")
.AppendLine();
// generate empty ctor if necessary
if (node.HasInitializableMembers(model) && !node.HasDefaultConstructor())
{
cb.AppendWithIndent(node.Identifier.ToString())
.Append("::")
.Append(node.Identifier.ToString())
.AppendLine("() :");
//cb.Indent(() =>
//{
// AppendFieldInitializers(node);
//});
cb.AppendLine("{}").AppendLine();
}
// generate static initialization
foreach (var fields in node.ChildNodes().OfType<FieldDeclarationSyntax>())
{
foreach (var v in fields.Declaration.Variables)
{
var z = (IFieldSymbol)model.GetDeclaredSymbol(v);
if (z.IsStatic && v.Initializer != null)
{
var cppType = z.Type.ToCppType();
string initExpression;
if (cppType.Contains("shared_ptr"))
{
var argumentList = new StringBuilder();
var evcs = v.Initializer as EqualsValueClauseSyntax;
if (evcs != null)
{
var oces = evcs.Value as ObjectCreationExpressionSyntax;
if (oces != null)
{
var count = oces.ArgumentList.Arguments.Count;
for (int i = 0; i < count; i++)
{
var a = oces.ArgumentList.Arguments[i];
argumentList.Append(a.ToFullString());
if (i + 1 != count)
argumentList.Append(",");
}
}
}
initExpression = $"std::make_shared<{z.Type.Name}>({argumentList})";
}
else
{
initExpression = v.Initializer.Value.ToString();
}
cb.AppendWithIndent("extern ")
.Append(node.Identifier.ToString())
.Append("::")
.Append(v.Identifier.ToString())
.Append(" = ")
.Append(initExpression)
.AppendLine(";").AppendLine();
}
}
}
base.VisitClassDeclaration(node);
}