public static bool Init(this IBaseServiceRequest serviceRequest, JObject request) { var result = false; if (request != null) { foreach ( var prop in serviceRequest.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetCustomAttribute <IgnoreAttribute>() == null)) { if (prop.CanRead) { var token = request.GetValue(prop.Name); if (token != null) { var value = token.Value <object>(); result = serviceRequest.SetProperty(prop, value); //if (value != null) //{ // if (prop.PropertyType == typeof(CommandInputOutputParameter)) // { // var cmdIO = prop.GetValue(serviceRequest) as CommandInputOutputParameter; // if (cmdIO != null) // { // cmdIO.Value = value; // result = true; // } // } // else // { // if (prop.PropertyType == typeof(GuidCommandParameter)) // { // var cmdGUID = prop.GetValue(serviceRequest) as GuidCommandParameter; // if (cmdGUID != null) // { // cmdGUID.Value = value; // result = true; // } // } // else // { // prop.SetValue(serviceRequest, value); // result = true; // } // } //} } } } } return(result); }
public static bool Init(this IBaseServiceRequest serviceRequest, IDictionary <string, object> request) { var result = false; if (request != null) { foreach (var prop in serviceRequest.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetCustomAttribute <IgnoreAttribute>() == null)) { if (prop.CanRead) { if (request.ContainsKey(prop.Name)) { var value = request[prop.Name]; result = serviceRequest.SetProperty(prop, value); } } } } return(result); }
public static bool Init(this IBaseServiceRequest serviceRequest, object request) { var result = false; if (request != null) { var d = request as IDictionary <string, object>; if (d != null) { return(serviceRequest.Init(d)); } var jo = request as JObject; if (jo != null) { return(serviceRequest.Init(jo)); } foreach (var prop in serviceRequest.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.GetCustomAttribute <IgnoreAttribute>() == null)) { if (prop.CanRead) { var xProp = request.GetType() .GetProperty(prop.Name, BindingFlags.Public | BindingFlags.Instance | BindingFlags.IgnoreCase); if (xProp != null) { var value = xProp.GetValue(request); result = serviceRequest.SetProperty(prop, value); //if (value != null) //{ // if (prop.PropertyType == typeof(CommandInputOutputParameter)) // { // var cmdIO = prop.GetValue(serviceRequest) as CommandInputOutputParameter; // if (cmdIO != null) // { // cmdIO.Value = value; // result = true; // } // } // else // { // if (prop.PropertyType == typeof(GuidCommandParameter)) // { // var cmdGUID = prop.GetValue(serviceRequest) as GuidCommandParameter; // if (cmdGUID != null) // { // cmdGUID.Value = value; // result = true; // } // } // else // { // prop.SetValue(serviceRequest, value); // result = true; // } // } //} } } } } return(result); }