public IQuery SetProperties(object bean) { System.Type clazz = bean.GetType(); string[] @params = NamedParameters; for (int i = 0; i < @params.Length; i++) { string namedParam = @params[i]; try { var getter = ReflectHelper.GetGetter(clazz, namedParam, "property"); var retType = getter.ReturnType; var obj = getter.Get(bean); if (typeof(IEnumerable).IsAssignableFrom(retType) && retType != typeof(string)) { SetParameterList(namedParam, (IEnumerable)obj); } else { SetParameter(namedParam, obj, DetermineType(namedParam, retType)); } } catch (PropertyNotFoundException) { // ignore } } return(this); }
public void LowerCaseUnderscoreNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyFour", "field.lowercase-underscore"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(Int64), fieldGetter.ReturnType, "returns Int64."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(Int64.MaxValue, fieldGetter.Get(obj), "Get() for Int64"); }
public void CamelCaseUnderscoreNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyTwo", "field.camelcase-underscore"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(Boolean), fieldGetter.ReturnType, "returns Boolean."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(true, fieldGetter.Get(obj), "Get() for Boolean"); }
public void CamelCaseNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyOne", "field.camelcase"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(DateTime), fieldGetter.ReturnType, "returns DateTime."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(DateTime.Parse("2000-01-01"), fieldGetter.Get(obj), "Get() for DateTime"); }
public void NoNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "Id", "field"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(Int32), fieldGetter.ReturnType, "returns Int32."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(7, fieldGetter.Get(obj), "Get() for Int32"); }
public void PascalCaseMUnderscoreNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyThree", "field.pascalcase-m-underscore"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(TimeSpan), fieldGetter.ReturnType, "returns DateTime."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(new TimeSpan(DateTime.Parse("2001-01-01").Ticks), fieldGetter.Get(obj), "Get() for TimeSpan"); }
public void CamelCaseMUnderscoreNamingStrategy() { IGetter fieldGetter = ReflectHelper.GetGetter(typeof(FieldGetterClass), "PropertyFive", "field.camelcase-m-underscore"); Assert.IsNotNull(fieldGetter, "should have found getter"); Assert.AreEqual(typeof(FieldAccessor.FieldGetter), fieldGetter.GetType(), "IGetter should be for a field."); Assert.AreEqual(typeof(decimal), fieldGetter.ReturnType, "returns Decimal."); Assert.IsNull(fieldGetter.Method, "no MethodInfo for fields."); Assert.IsNull(fieldGetter.PropertyName, "no Property Names for fields."); Assert.AreEqual(2.5m, fieldGetter.Get(obj), "Get() for Decimal"); }
/// <summary> /// /// </summary> /// <param name="bean"></param> /// <returns></returns> public IQuery SetProperties(object bean) { System.Type clazz = bean.GetType(); foreach (string namedParam in actualNamedParameters) { try { IGetter getter = ReflectHelper.GetGetter(clazz, namedParam, "property"); SetParameter(namedParam, getter.Get(bean), GuessType(getter.ReturnType)); } catch (Exception) { } } return(this); }