private static bool IsFirstArgumentInMethod(ILiteralExpression literal) { var argument = CSharpArgumentNavigator.GetByValue(literal as ICSharpExpression); var argumentsOwner = CSharpArgumentsOwnerNavigator.GetByArgument(argument); return(argumentsOwner != null && argumentsOwner.ArgumentsEnumerable.FirstOrDefault() == argument); }
public IReference[] GetReferences(ITreeNode element, IReference[] oldReferences) { var literal = element as ILiteralExpression; if (literal != null && literal.ConstantValue.IsString()) { var argument = CSharpArgumentNavigator.GetByValue(literal as ICSharpExpression); var argumentsOwner = CSharpArgumentsOwnerNavigator.GetByArgument(argument); if (argumentsOwner != null && argumentsOwner.ArgumentsEnumerable.FirstOrDefault() != argument) { return(EmptyArray <IReference> .Instance); } var invocationExpression = literal.GetContainingNode <IInvocationExpression>(); var invocationReference = invocationExpression?.Reference; var invokedMethod = invocationReference?.Resolve().DeclaredElement as IMethod; if (invokedMethod != null && (invokedMethod.ShortName == "Invoke" || invokedMethod.ShortName == "InvokeRepeating" || invokedMethod.ShortName == "CancelInvoke")) { var containingType = invokedMethod.GetContainingType(); if (containingType != null && Equals(containingType.GetClrName(), MonoBehaviourTypeName)) { var inMethod = literal.GetContainingNode <IMethodDeclaration>(); var currentType = inMethod?.DeclaredElement?.GetContainingType(); // TODO: Check if currentType is derived from MonoBehaviour? if (currentType != null) { IReference reference = new MonoBehaviourInvokeReference(currentType, literal); return(oldReferences != null && oldReferences.Length == 1 && Equals(oldReferences[0], reference) ? oldReferences : new[] { reference }); } } } } return(EmptyArray <IReference> .Instance); }
public IReference[] GetReferences(ITreeNode element, IReference[] oldReferences) { var literal = element as ILiteralExpression; if (literal != null && literal.ConstantValue.IsString()) { var argument = CSharpArgumentNavigator.GetByValue(literal as ICSharpExpression); var argumentsOwner = CSharpArgumentsOwnerNavigator.GetByArgument(argument); if (argumentsOwner != null && argumentsOwner.ArgumentsEnumerable.FirstOrDefault() != argument) { return(EmptyArray <IReference> .Instance); } var invocationExpression = literal.GetContainingNode <IInvocationExpression>(); var invocationReference = invocationExpression?.Reference; var invokedMethod = invocationReference?.Resolve().DeclaredElement as IMethod; if (invokedMethod != null && DoesMethodReferenceFunction(invokedMethod)) { var containingType = invokedMethod.GetContainingType(); if (containingType != null && Equals(containingType.GetClrName(), KnownTypes.MonoBehaviour)) { var targetType = invocationExpression.ExtensionQualifier?.GetExpressionType().ToIType()?.GetTypeElement() ?? literal.GetContainingNode <IMethodDeclaration>()?.DeclaredElement?.GetContainingType(); // TODO: Check if currentType is derived from MonoBehaviour? if (targetType != null) { IReference reference = new UnityEventFunctionReference(targetType, literal); return(oldReferences != null && oldReferences.Length == 1 && Equals(oldReferences[0], reference) ? oldReferences : new[] { reference }); } } } } return(EmptyArray <IReference> .Instance); }