1
private int _i;

public int  Count
{
    get {  return _i;  }
}

如何variable _i使用 CodeRush API 获得属性“Count”。

4

1 回答 1

1

试试下面的代码,希望对你有帮助:

Variable GetPropertyVariable(Property property)
{
  if (property == null)
    return null;

  Get getter = property.Getter;
  if (getter == null)
    return null;

  Return returnStatement = getter.FindChildByElementType(LanguageElementType.Return) as Return;
  if (returnStatement == null)
    return null;

  Expression returnExpression = returnStatement.Expression;
  ElementReferenceExpression targetExpression = returnExpression as ElementReferenceExpression;
  if (targetExpression == null)
    targetExpression = returnExpression.FindChildByElementType(LanguageElementType.ElementReferenceExpression) as ElementReferenceExpression;
  if (targetExpression == null)
    return null;

  return targetExpression.GetDeclaration(true) as Variable;
}
于 2011-08-11T08:39:21.400 回答