本文整理汇总了C#中ICSharpCode.NRefactory.Ast.MethodDeclaration类的典型用法代码示例。如果您正苦于以下问题:C# MethodDeclaration类的具体用法?C# MethodDeclaration怎么用?C# MethodDeclaration使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MethodDeclaration类属于ICSharpCode.NRefactory.Ast命名空间,在下文中一共展示了MethodDeclaration类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasReturnValue_HasNone
public void HasReturnValue_HasNone()
{
var methodToTest = new MethodDeclaration();
var victim = new TestableMethodTemplate(methodToTest, null);
Assert.IsFalse(victim.HasReturnValue);
}
示例2: Equals
public void Equals()
{
string program = TestUtil.TypeMemberParse("public string Sentence(string title , string text);");
CompilationUnit cu = TestUtil.ParseProgram(program);
NamespaceDeclaration ns = (NamespaceDeclaration) cu.Children[0];
TypeDeclaration ty = (TypeDeclaration) ns.Children[0];
MethodDeclaration pgMethod = (MethodDeclaration) ty.Children[0];
ParameterDeclarationExpression p1 = new ParameterDeclarationExpression(new TypeReference("string"), "title");
p1.TypeReference.RankSpecifier = new int[] {};
ParameterDeclarationExpression p2 = new ParameterDeclarationExpression(new TypeReference("string"), "text");
p2.TypeReference.RankSpecifier = new int[] {};
List<ParameterDeclarationExpression> argList = new List<ParameterDeclarationExpression>();
argList.Add(p1);
argList.Add(p2);
MethodDeclaration exMethod = new MethodDeclaration("Sentence",
Modifiers.Public,
new TypeReference("string"),
argList, null);
Assert.IsTrue(Equals(exMethod, pgMethod));
string program2 = TestUtil.TypeMemberParse("public string Sentence(string title , string[] text);");
cu = TestUtil.ParseProgram(program2);
ns = (NamespaceDeclaration) cu.Children[0];
ty = (TypeDeclaration) ns.Children[0];
pgMethod = (MethodDeclaration) ty.Children[0];
Assert.IsFalse(Equals(exMethod, pgMethod));
}
示例3: IsMethodInExternalTypes
protected bool IsMethodInExternalTypes(TypeDeclaration typeDeclaration, MethodDeclaration methodDeclaration)
{
bool found = false;
foreach (TypeReference baseType in typeDeclaration.BaseTypes)
{
string fullName = GetFullName(baseType);
if (!found && CodeBase.Types.Contains(fullName))
{
TypeDeclaration baseTypeDeclaration = (TypeDeclaration) CodeBase.Types[fullName];
if (IsInExternalLibraries(fullName) || fullName.StartsWith("Helpers."))
{
IList methods = AstUtil.GetChildrenWithType(baseTypeDeclaration, typeof(MethodDeclaration));
if (ContainsMethod(methods, methodDeclaration))
found = true;
else
found = IsMethodInExternalTypes(baseTypeDeclaration, methodDeclaration);
}
else
found = IsMethodInExternalTypes(baseTypeDeclaration, methodDeclaration);
if (found)
break;
}
}
return found;
}
示例4: VisitMethodDeclaration
public override object VisitMethodDeclaration(MethodDeclaration declaration, object data)
{
if (!HasContainerType(declaration, ClassType.Interface) && declaration.InterfaceImplementations.Count == 0)
MakePublic(declaration);
return base.VisitMethodDeclaration(declaration, data);
}
示例5: TrackedVisitTypeDeclaration
public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
if (IsDerivedFrom(typeDeclaration, "Comparator"))
{
IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
MethodDeclaration equalsMethod = new MethodDeclaration("equals",
Modifiers.Public, AstUtil.GetTypeReference("bool", typeDeclaration), new List<ParameterDeclarationExpression>(), null);
equalsMethod.Parent = typeDeclaration;
TypeReference argTypeReference = AstUtil.GetTypeReference("java.lang.Object", equalsMethod);
argTypeReference.RankSpecifier = new int[] {};
equalsMethod.Parameters.Add(new ParameterDeclarationExpression(argTypeReference, "obj"));
if (Contains(methods, equalsMethod))
{
int index = IndexOf(methods, equalsMethod);
MethodDeclaration method = (MethodDeclaration) methods[index];
AstUtil.RemoveModifierFrom(method, Modifiers.Abstract);
method.TypeReference.Type = "bool";
CreateMethodImplementation(method);
}
else
{
CreateMethodImplementation(equalsMethod);
typeDeclaration.Children.Add(equalsMethod);
equalsMethod.Parent = typeDeclaration;
}
}
return base.TrackedVisitTypeDeclaration(typeDeclaration, data);
}
示例6: TrackedVisitTypeDeclaration
public override object TrackedVisitTypeDeclaration(TypeDeclaration typeDeclaration, object data)
{
if (IsAbstractClass(typeDeclaration))
{
IList currentClassMethods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
currentClassMethods = GetMethodsInParents(typeDeclaration, currentClassMethods, true);
IList methodsInParents = new ArrayList();
methodsInParents = GetMethodsInParents(typeDeclaration, methodsInParents, false);
methodsInParents = FilterImplementedMethods(methodsInParents);
IList abstractMethods = GetDiffList(currentClassMethods, methodsInParents);
if (abstractMethods.Count > 0)
{
TypeDeclaration replacedTypeDeclaration = typeDeclaration;
foreach (MethodDeclaration method in abstractMethods)
{
MethodDeclaration newMethod;
newMethod = new MethodDeclaration(method.Name,
Modifiers.Public | Modifiers.Abstract,
method.TypeReference,
method.Parameters,
method.Attributes);
newMethod.Parent = replacedTypeDeclaration;
replacedTypeDeclaration.Children.Add(newMethod);
}
ReplaceCurrentNode(replacedTypeDeclaration);
}
}
return base.TrackedVisitTypeDeclaration(typeDeclaration, data);
}
示例7: VisitMethodDeclaration
public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
{
if (methodDeclaration.Modifier.HasFlag(Modifiers.Abstract))
UnlockWith(methodDeclaration);
return base.VisitMethodDeclaration(methodDeclaration, data);
}
示例8: VisitMethodDeclaration
public override object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
{
if (methodDeclaration.Name.ToLower().Equals("main") && !methodDeclaration.Modifier.HasFlag(Modifiers.Constructors))
{
if (!methodDeclaration.IsExtensionMethod && !methodDeclaration.Modifier.HasFlag(Modifiers.Abstract))
{
if (methodDeclaration.Parameters.Count==1)
{
ParameterDeclarationExpression param = methodDeclaration.Parameters[0];
if(param.ParameterName.Equals("args") && param.TypeReference.ToString().Equals("System.String[]"))
{
//now check if body uses argsparam
//This is waaaaay to naive....
if(methodDeclaration.Body.ToString().Contains("args"))
{
UnlockWith(methodDeclaration);
}
}
}
}
}
return base.VisitMethodDeclaration(methodDeclaration, data);
}
示例9: VerifyMethodCondition
protected override bool VerifyMethodCondition(TypeDeclaration typeDeclaration, MethodDeclaration methodDeclaration)
{
IList methods = AstUtil.GetChildrenWithType(typeDeclaration, typeof(MethodDeclaration));
string name = methodDeclaration.Name.Substring(3);
if (Contains(methods, methodDeclaration))
{
IList innerTypes = AstUtil.GetChildrenWithType(typeDeclaration, typeof(TypeDeclaration));
foreach (TypeDeclaration innerType in innerTypes)
{
if (innerType.Name == name)
return true;
}
IList constructors = AstUtil.GetChildrenWithType(typeDeclaration, typeof(ConstructorDeclaration));
foreach (ConstructorDeclaration constructorDeclaration in constructors)
{
if (constructorDeclaration.Name == name)
return true;
}
foreach (MethodDeclaration method in methods)
{
if (method.Name == name || char.ToUpper(method.Name[0]) + method.Name.Substring(1) == name)
return true;
}
}
else
{
IList properties = AstUtil.GetChildrenWithType(typeDeclaration, typeof(PropertyDeclaration));
return Contains(properties, name);
}
return false;
}
示例10: ConvertInterfaceImplementation
void ConvertInterfaceImplementation(MethodDeclaration member)
{
// members without modifiers are already C# explicit interface implementations, do not convert them
if (member.Modifier == Modifiers.None)
return;
while (member.InterfaceImplementations.Count > 0) {
InterfaceImplementation impl = member.InterfaceImplementations[0];
member.InterfaceImplementations.RemoveAt(0);
if (member.Name != impl.MemberName) {
MethodDeclaration newMember = new MethodDeclaration {
Name = impl.MemberName,
TypeReference = member.TypeReference,
Parameters = member.Parameters,
Body = new BlockStatement()
};
InvocationExpression callExpression = new InvocationExpression(new IdentifierExpression(member.Name));
foreach (ParameterDeclarationExpression decl in member.Parameters) {
callExpression.Arguments.Add(new IdentifierExpression(decl.ParameterName));
}
if (member.TypeReference.Type == "System.Void") {
newMember.Body.AddChild(new ExpressionStatement(callExpression));
} else {
newMember.Body.AddChild(new ReturnStatement(callExpression));
}
newMember.InterfaceImplementations.Add(impl);
InsertAfterSibling(member, newMember);
}
}
}
示例11: GenerateCode
public override void GenerateCode(List<AbstractNode> nodes, IList items)
{
TypeReference stringReference = new TypeReference("System.String");
MethodDeclaration method = new MethodDeclaration("ToString",
Modifiers.Public | Modifiers.Override,
stringReference,
null, null);
method.Body = new BlockStatement();
Expression target = new FieldReferenceExpression(new TypeReferenceExpression(stringReference),
"Format");
InvocationExpression methodCall = new InvocationExpression(target);
StringBuilder formatString = new StringBuilder();
formatString.Append('[');
formatString.Append(currentClass.Name);
for (int i = 0; i < items.Count; i++) {
formatString.Append(' ');
formatString.Append(codeGen.GetPropertyName(((FieldWrapper)items[i]).Field.Name));
formatString.Append("={");
formatString.Append(i);
formatString.Append('}');
}
formatString.Append(']');
methodCall.Arguments.Add(new PrimitiveExpression(formatString.ToString(), formatString.ToString()));
foreach (FieldWrapper w in items) {
methodCall.Arguments.Add(new FieldReferenceExpression(new ThisReferenceExpression(), w.Field.Name));
}
method.Body.AddChild(new ReturnStatement(methodCall));
nodes.Add(method);
}
示例12: VisitMethodDeclaration
public override object VisitMethodDeclaration(MethodDeclaration md, object data)
{
Push();
object result = base.VisitMethodDeclaration(md, data);
Pop();
return result;
}
示例13: Equals
public bool Equals(MethodDeclaration firstMethod, MethodDeclaration secondMethod)
{
if (firstMethod.Name == secondMethod.Name)
{
if (firstMethod.Parameters.Count == secondMethod.Parameters.Count)
{
int index = 0;
foreach (ParameterDeclarationExpression parameter in firstMethod.Parameters)
{
TypeReference parameterTypeReference = ((ParameterDeclarationExpression) secondMethod.Parameters[index]).TypeReference;
string firstMethodParam = parameter.TypeReference.Type;
if (firstMethodParam.IndexOf('.') != -1)
firstMethodParam = firstMethodParam.Substring(firstMethodParam.LastIndexOf('.') + 1);
string secondMethodParam = parameterTypeReference.Type;
if (secondMethodParam.IndexOf('.') != -1)
secondMethodParam = secondMethodParam.Substring(secondMethodParam.LastIndexOf('.') + 1);
if ((firstMethodParam == secondMethodParam || AreEqualTypes(parameter.TypeReference, parameterTypeReference)) &&
parameter.TypeReference.RankSpecifier.Length == parameterTypeReference.RankSpecifier.Length)
index++;
else
return false;
}
return true;
}
}
return false;
}
示例14: TrackedVisitMethodDeclaration
public override object TrackedVisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
{
TypeDeclaration typeDeclaration = (TypeDeclaration) methodDeclaration.Parent;
if (methodDeclaration.Name.Length > 3)
{
if (IsAccessor(methodDeclaration, fields)
|| IsInterfaceOrAbstract(typeDeclaration) && ImplementInheritors(typeDeclaration, methodDeclaration)
|| ImplementSiblings(typeDeclaration, methodDeclaration))
{
string name = GetPropertyName(methodDeclaration);
TypeReference typeReference = GetAccessorTypeReference(methodDeclaration);
IList properties = AstUtil.GetChildrenWithType(typeDeclaration, typeof(PropertyDeclaration));
PropertyDeclaration propertyDeclaration = GetProperty(properties, name, methodDeclaration.Modifier, typeReference);
if (methodDeclaration.Name.StartsWith("set"))
AddSetSection(propertyDeclaration, methodDeclaration, fields);
else if (methodDeclaration.Name.StartsWith("get"))
AddGetSection(propertyDeclaration, methodDeclaration, fields);
AddToReferences(typeDeclaration, methodDeclaration.Name, propertyDeclaration.Name);
if (!HasProperty(properties, name))
ReplaceCurrentNode(propertyDeclaration);
else
RemoveCurrentNode();
}
}
return base.TrackedVisitMethodDeclaration(methodDeclaration, data);
}
示例15: VisitMethodDeclaration
public object VisitMethodDeclaration(MethodDeclaration methodDeclaration, object data)
{
B.Method m = new B.Method(GetLexicalInfo(methodDeclaration));
m.Name = methodDeclaration.Name;
m.Modifiers = ConvertModifier(methodDeclaration, B.TypeMemberModifiers.Private);
ConvertAttributes(methodDeclaration.Attributes, m.Attributes);
if (currentType != null) currentType.Members.Add(m);
if (methodDeclaration.HandlesClause.Count > 0) {
// TODO: Convert handles clauses to [Handles] attribute
AddError(methodDeclaration, "Handles-clause is not supported.");
}
m.ExplicitInfo = ConvertInterfaceImplementations(methodDeclaration.InterfaceImplementations, methodDeclaration, m);
if (methodDeclaration.Templates.Count > 0) {
AddError(methodDeclaration, "Declaring generic methods is not supported.");
}
ConvertParameters(methodDeclaration.Parameters, m.Parameters);
m.EndSourceLocation = GetEndLocation((INode)methodDeclaration.Body ?? methodDeclaration);
m.ReturnType = ConvertTypeReference(methodDeclaration.TypeReference);
m.Body = ConvertMethodBlock(methodDeclaration.Body);
if (m.Name == "Main" && m.IsStatic && m.Parameters.Count <= 1 &&
(methodDeclaration.TypeReference.Type == "System.Void" || methodDeclaration.TypeReference.Type == "System.Int32"))
{
entryPointMethod = m;
}
return m;
}