/// <summary> /// Used by properties that are decorated with the ApiParameter attribute /// </summary> protected dynamic GetParameter() { var caller = new StackFrame(1); var method = caller.GetMethod(); var propName = method.Name.Substring(4); var type = method.ReflectedType; var pi = type.GetProperty(propName); object[] attributes = pi.GetCustomAttributes(typeof(ApiParameterAttribute), true); if (attributes != null && attributes.Length == 1) { var ssAttr = attributes[0] as ApiParameterAttribute; if (Parameters.ContainsKey(ssAttr.Name)) { if (pi.PropertyType.IsEnum) { var converter = new ApiEnumTypeConverter(pi.PropertyType); return(converter.ConvertFrom(Parameters[ssAttr.Name])); } else { return(Parameters[ssAttr.Name]); } } } else { throw new Exception("Property must have an ApiParameter attribute"); } return(default(dynamic)); }
/// <summary> /// Used by properties that are decorated with the ApiParameter attribute /// </summary> protected void SetParameter(object value) { var caller = new StackFrame(1); var method = caller.GetMethod(); var propName = method.Name.Substring(4); var type = method.ReflectedType; var pi = type.GetProperty(propName); object[] attributes = pi.GetCustomAttributes(typeof(ApiParameterAttribute), true); if (attributes != null && attributes.Length == 1) { var ssAttr = attributes[0] as ApiParameterAttribute; if (pi.PropertyType.IsEnum) { var converter = new ApiEnumTypeConverter(pi.PropertyType); Parameters[ssAttr.Name] = (string)converter.ConvertTo(value, typeof(string)); } else { Parameters[ssAttr.Name] = value.ToString(); } } else { throw new Exception("Property must have an ApiParameter attribute"); } }