This paper addresses the problem of state and parameter estimation for the class of affine systems in the state space representation. The method does not require a specific state representation of the system and consists of designing a switched observer that, under certain conditions given in the paper, allows for the state and parameter estimation errors to converge to zero. Assuming that the parameters to be estimated belong to a given polytope, the idea of the method is to recast the parameter estimation problem as a switching rule design for an auxiliary switched system whose matrices at the equilibrium correspond to the matrices of the system to be estimated. A guaranteed cost is used in the design and the switching rule is based on a max composition of a set of quadratic functions of the observation error. The method is simple and has low computational cost. The main disadvantage regards the amount of information that is needed to have both state and parameters estimated simultaneously. The case when there is no parameter to estimate the method reduces to a standard Luenberger observer with guaranteed cost.