public static IPropertyDeclaration GetPropertyDeclaration(IClassDeclaration classDeclaration, IInvocationExpression invocationExpression)
{
IPropertyDeclaration propertyDeclaration = null;
if (invocationExpression.ArgumentList.Arguments.Count >= 1)
{
string propertyName = null;
var argument = invocationExpression.ArgumentList.Arguments[0];
if (argument.Value is ILambdaExpression)
{
var lambdaExpression = argument.Value as ILambdaExpression;
var referenceExpression = lambdaExpression.BodyExpression as IReferenceExpression;
if (referenceExpression != null)
{
propertyName = referenceExpression.NameIdentifier.Name;
}
}
else if (argument.Value != null && argument.Value.ConstantValue != null)
{
propertyName = argument.Value.ConstantValue.Value.ToString();
}
if (!string.IsNullOrEmpty(propertyName) && classDeclaration.DeclaredElement != null)
{
var property = (from member in classDeclaration.DeclaredElement.GetMembers().OfType<IProperty>() where member.ShortName == propertyName select member).FirstOrDefault();
if (property != null)
{
propertyDeclaration = (IPropertyDeclaration) property.GetDeclarations().FirstOrDefault();
}
}
}
return propertyDeclaration;
}
#endregion