private MemberResult ProcessSimpleName(CsSimpleName name) { var result = new MemberResult(); var fieldInfo = itemType.GetField(name.identifier.original_text, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField); if (fieldInfo != null) { result.MemberInfo = fieldInfo; result.IsPublic = fieldInfo.IsPublic; } else { var propertyInfo = itemType.GetProperty(name.identifier.original_text, BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetProperty); if (propertyInfo != null) { var getMethod = propertyInfo.GetGetMethod(); result.MemberInfo = propertyInfo; if (getMethod == null) { getMethod = propertyInfo.GetGetMethod(true); } result.IsPublic = getMethod.IsPublic; } else { Debugger.Break(); } } return(result); }
public static Expression ParseSimpleName(CsExpression pStatement, bool pForce, bool pGetSetter) { CsSimpleName ex = (CsSimpleName)pStatement; bool isInternal = false; string val; if (ex.ec == expression_classification.ec_property_access) { CsAssignmentExpression parent = pStatement.parent as CsAssignmentExpression; if (!pForce) { pGetSetter = parent != null && parent.lhs.Equals(pStatement); } isInternal = true; CsEntityProperty property = (CsEntityProperty)ex.entity; val = pGetSetter ? string.Format("{0}({{0}})", property.setter.name) : string.Format("{0}()", property.getter.name); } else { //val = ex.identifier.identifier; Helpers.GetRealName(ex, ex.identifier.identifier, out val); } return(new Expression( val, ex.entity_typeref, isInternal)); }
public static bool GetRealName(object pExpression, string pName, out string pRealName) { if (pExpression == null) { pRealName = pName; return(false); } CsEntityClass csEntityClass = pExpression as CsEntityClass; if (csEntityClass != null) { return(getRealName(csEntityClass.attributes, pName, out pRealName)); } CsEntityEnum csEntityEnum = pExpression as CsEntityEnum; if (csEntityEnum != null) { return(getRealName(csEntityEnum.attributes, pName, out pRealName)); } CsEntityStruct csEntityStruct = pExpression as CsEntityStruct; if (csEntityStruct != null) { return(getRealName(csEntityStruct.attributes, pName, out pRealName)); } CsEntityInterface csEntityInterface = pExpression as CsEntityInterface; if (csEntityInterface != null) { return(getRealName(csEntityInterface.attributes, pName, out pRealName)); } CsPrimaryExpressionMemberAccess csPrimaryExpressionMemberAccess = pExpression as CsPrimaryExpressionMemberAccess; if (csPrimaryExpressionMemberAccess != null) { return(GetRealName(csPrimaryExpressionMemberAccess.expression.entity, pName, out pRealName)); } CsEntityLocalVariable csEntityLocalVariable = pExpression as CsEntityLocalVariable; if (csEntityLocalVariable != null) { CsLocalVariableDeclaration v = (csEntityLocalVariable.decl.parent) as CsLocalVariableDeclaration; if (v != null) { GetRealName(v.type.entity_typeref.u, pName, out pRealName); //get new name but do not replace expression, as this is a local accessor... return(false); } } CsEntityVariable csEntityVariable = pExpression as CsEntityVariable; if (csEntityVariable != null) { return(GetRealName(csEntityVariable.type.u, pName, out pRealName)); } CsEntityConstant csEntityConstant = pExpression as CsEntityConstant; if (csEntityConstant != null) { return(GetRealName(csEntityConstant.type.u, pName, out pRealName)); } CsEntityMethod csEntityMethod = pExpression as CsEntityMethod; if (csEntityMethod != null) { return(GetRealName(csEntityMethod.parent, pName, out pRealName)); } CsSimpleName csSimpleName = pExpression as CsSimpleName; if (csSimpleName != null) { return(GetRealName(csSimpleName.entity_typeref == null ? csSimpleName.entity : csSimpleName.entity_typeref.u, pName, out pRealName)); } CsPredefinedTypeMemberAccess csPredefinedTypeMemberAccess = pExpression as CsPredefinedTypeMemberAccess; if (csPredefinedTypeMemberAccess != null) { return (GetRealName( csPredefinedTypeMemberAccess.entity_typeref == null ? csPredefinedTypeMemberAccess.entity : csPredefinedTypeMemberAccess.entity_typeref.u, pName, out pRealName)); } CsEntityInstanceSpecifier csEntityInstanceSpecifier = pExpression as CsEntityInstanceSpecifier; if (csEntityInstanceSpecifier != null) { return(GetRealName(csEntityInstanceSpecifier.type.u, pName, out pRealName)); } pRealName = pName; return(false); //CsEntityDelegate csEntityDelegate = pExpression as CsEntityDelegate; //if (csEntityDelegate != null) { // pRealName = pName; // return false; //} //throw new NotImplementedException(); }