本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.Syntax.MethodDeclarationSyntax.GetAttribute方法的典型用法代码示例。如果您正苦于以下问题:C# MethodDeclarationSyntax.GetAttribute方法的具体用法?C# MethodDeclarationSyntax.GetAttribute怎么用?C# MethodDeclarationSyntax.GetAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.Syntax.MethodDeclarationSyntax
的用法示例。
在下文中一共展示了MethodDeclarationSyntax.GetAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: WriteIt
public static void WriteIt(OutputWriter writer, MethodDeclarationSyntax method, bool isProxy = true, IEnumerable<ITypeSymbol> virtualGenericClasses=null)
{
var methodSymbol = (IMethodSymbol) TypeProcessor.GetDeclaredSymbol(method);
var isYield = YieldChecker.HasYield(method);//method.DescendantNodes().OfType<YieldStatementSyntax>().Any();
writer.WriteLine();
var pinvokeAttributes = method.GetAttribute(Context.DllImport);
var isInternalPInvoke = pinvokeAttributes == null && method.Modifiers.Any(SyntaxKind.ExternKeyword);
//TODO: Improve partial class / method support -- partials classes work, methods need minor work ...
if (method.Modifiers.Any(SyntaxKind.PartialKeyword) && method.Body == null)
{
//We only want to render out one of the two partial methods. If there's another, skip this one.
if (Context.Instance.Partials.SelectMany(o => o.Syntax.As<ClassDeclarationSyntax>().Members)
.OfType<MethodDeclarationSyntax>()
.Except(method).Any(o => o.Identifier.Text == method.Identifier.Text))
return;
}
var accessString = "";
var isInterface = method.Parent is InterfaceDeclarationSyntax;
ITypeSymbol iface;
ISymbol[] proxies;
var methodName = MemberUtilities.GetMethodName(method, ref isInterface, out iface, out proxies); //
var originalMethodName = methodName;
var containingType = iface == null ? methodSymbol.ContainingType : iface;
if (virtualGenericClasses != null)
{
methodName = TypeProcessor.ConvertType(containingType, false, false, false).Replace(".","_") + "_"+methodName;
accessString = "public static final ";
}
else if (methodName == "Main" /*&& method.Modifiers.Any(SyntaxKind.PublicKeyword)*/&&
method.Modifiers.Any(SyntaxKind.StaticKeyword))
{
accessString = ("public ");
accessString += ("static ");
var methodCall = methodSymbol.ContainingNamespace.FullName() + "." +
methodSymbol.ContainingType.FullName() +
"." + methodName + (method.ParameterList.Parameters.Count < 1 ? "();" : "(null);");
//: "(new Array_T!(String)(args));"); // for now args not supported
Context.Instance.EntryMethod = methodCall;
}
else
{
accessString = MemberUtilities.GetAccessModifiers(method, isInterface || methodSymbol.IsAbstract);
}
var returnTypeString = TypeProcessor.ConvertType(method.ReturnType, true) + " ";
var methodSignatureString = "";
if (method.ReturnType.ToString() == "void")
returnTypeString = ("void ");
methodSignatureString += methodName;
var genericParameters = "";
if (method.TypeParameterList != null)
{
var genericArgs = method.TypeParameterList.Parameters.ToList();
// if (genericArgs.Count > 0)
// {
// writer.Write("( ");
// writer.Write(string.Join(" , ", genericArgs.Select(o => " " + o)));
// writer.Write(" )\r\n");
// }
if (genericArgs.Count > 0) // && !methodSymbol.ContainingType.IsGenericType) // doesnt matter
{
genericParameters += ("(");
genericParameters += (string.Join(",", genericArgs.Select(o => o)));
genericParameters += (")");
}
}
methodSignatureString += genericParameters;
var @params = GetParameterListAsString(method.ParameterList.Parameters,
iface: proxies == null ? iface : null, genericClass: virtualGenericClasses != null ? containingType : null);
// if (virtualGenericClasses != null)
// {
// @params = TypeProcessor.ConvertType() + ", " + @params;
// }
string constraints = GetMethodConstraints(method);
//.........这里部分代码省略.........