本文整理汇总了C#中INamedTypeSymbol.StaticConstructor方法的典型用法代码示例。如果您正苦于以下问题:C# INamedTypeSymbol.StaticConstructor方法的具体用法?C# INamedTypeSymbol.StaticConstructor怎么用?C# INamedTypeSymbol.StaticConstructor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类INamedTypeSymbol
的用法示例。
在下文中一共展示了INamedTypeSymbol.StaticConstructor方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Generate
public static CompleterResult Generate(SemanticModel model, INamedTypeSymbol type)
{
//TODO error or skip if null
var cctor = type.StaticConstructor();
if(cctor == null || cctor.IsImplicitlyDeclared)
return default(string);
var syntax = (ConstructorDeclarationSyntax)cctor.Node();
var properties = syntax.Body.Statements
.Select(statement => {
return (statement as ExpressionStatementSyntax)?.Expression as InvocationExpressionSyntax;
})
.Where(invocation => invocation != null)
.Select(invocation => LinqExtensions.Unfold(
invocation,
x => (x.Expression as MemberAccessExpressionSyntax)?.Expression as InvocationExpressionSyntax
)
.ToArray()
)
.Where(chain => {
var lastMemberAccess = chain.Last().Expression as MemberAccessExpressionSyntax;
return (lastMemberAccess?.Expression as GenericNameSyntax)?.Identifier.ValueText == "DependencyPropertyRegistrator" //TODO check real type from model
&& lastMemberAccess?.Name.Identifier.ValueText == "New";
})
.Select(chain => GenerateProperties(model, type, chain));
return properties
.AggregateEither(
errors => errors.SelectMany(x => x).ToImmutableArray(),
values => {
var conctenated = values.ConcatStringsWithNewLines();
if(string.IsNullOrEmpty(conctenated))
return null;
return
[email protected]"partial class {type.ToString().Split('.').Last()} {{
{conctenated.AddTabs(1)}
}}";
});
}