public static ParameterInfo[] GetDescription(this IParameters parameters) { return(parameters .GetType() .GetProperties() .Where(p => p.GetCustomAttributes(false).OfType <ParameterInfo>().Any()) .Select(p => p.GetCustomAttributes(false).OfType <ParameterInfo>().First()) .ToArray()); }
public static System.Reflection.ParameterInfo[] GetDescription(this IParameters parameters) { return(parameters.GetType() .GetProperties() .Select(x => x.GetCustomAttributes(typeof(System.Reflection.ParameterInfo), false)) .Where(x => x.Length > 0) .Select(x => x[0]) .Cast <System.Reflection.ParameterInfo>() .ToArray()); }
public static ParameterInfo[] GetDesсription(this IParameters parameters) { return(parameters .GetType() .GetProperties() .Select(p => p.GetCustomAttributes(typeof(ParameterInfo), false)) .Where(p => p.Length > 0) .Select(p => p[0]) .Cast <ParameterInfo>() .ToArray()); }
public static void SetValues(this IParameters parameters, double[] values) { var properties = parameters.GetType() .GetProperties() .Where(x => x.GetCustomAttributes(typeof(System.Reflection.ParameterInfo), false).Length > 0) .ToArray(); for (int i = 0; i < values.Length; i++) { properties[i].SetValue(parameters, values[i], new object[0]); } }
public TBuilder GetParameterBuilder(IParameters parameters) { foreach (IParametersBuilder registeredBuilder in this.registeredBuilders) { if (registeredBuilder.CanBuild(parameters.GetType())) { return((TBuilder)registeredBuilder); } } return(default(TBuilder)); }
public static void Parse(this IParameters parameters, double[] data) { int i = 0; foreach ( var property in parameters .GetType() .GetProperties() .Where(p => p.GetCustomAttributes(false).OfType <ParameterInfo>().Any()) ) { property.SetValue(parameters, data[i++], new object[0]); } }
private void SetAndGetArray <T>(IParameters parameters, string property, params T[] value) { var prop = parameters.GetType().GetProperty(property); if (prop == null) { throw new ArgumentException($"Could not find property '{property}'"); } prop.SetValue(parameters, value); var val = prop.GetValue(parameters); AssertEx.AreEqualLists(value?.ToList(), val?.ToIEnumerable().Cast <T>().ToList(), $"Property '{property}' was incorrect"); }
private void SetAndGet(IParameters parameters, string property, object value) { var prop = parameters.GetType().GetProperty(property); if (prop == null) { throw new ArgumentException($"Could not find property '{property}'"); } prop.SetValue(parameters, value); var val = prop.GetValue(parameters); Assert.AreEqual(value, val); }
public static string ConvertToUrlEncodedString(this IParameters parameters) { var result = new Dictionary <string, string>(); if (parameters == null) { return(string.Empty); } var parametersType = parameters.GetType(); foreach (var prop in parametersType.GetProperties()) { foreach (var customAttribute in prop.GetCustomAttributes(true)) { string propValueAsString; if (prop.GetValue(parameters, null) is IEnumerable <string> ) { propValueAsString = GetEnumerableElementsAsString((IEnumerable <string>)prop.GetValue(parameters, null)); } else { propValueAsString = prop.GetValue(parameters, null)?.ToString(); } if (string.IsNullOrEmpty(propValueAsString)) { continue; } if (customAttribute is JsonPropertyAttribute jsonPropAttribute) { result.Add(jsonPropAttribute.PropertyName, propValueAsString); } else { result.Add(prop.Name, propValueAsString); } } } using (var content = new FormUrlEncodedContent(result)) { return(content.ReadAsStringAsync().Result); } }
public static void SetValues(this IParameters parameters, string[] adressParameters) { var properties = parameters.GetType() .GetProperties() .Where(z => z.GetCustomAttributes(typeof(ParameterAttribute), false).Length > 0) .ToArray(); for (int i = 0; i < properties.Length; i++) { ParameterAttribute propertyAttribute = (ParameterAttribute)properties[i].GetCustomAttributes(typeof(ParameterAttribute), false)[0]; string stringParameterValue = i < adressParameters.Length ? adressParameters[i] : null; object targetParameterValue = propertyAttribute.ParseFromString(stringParameterValue); properties[i].SetValue(parameters, targetParameterValue); } }
public async Task <Tuple <int, double> > PostContext <T>(IParameters param) { var response = await client.ExecuteAsync(new RestRequest(security.Request(param.GetType().Name), Method.POST).AddJsonBody(param, security.ContentType), source.Token); try { if (response != null && response.RawBytes != null && response.RawBytes.Length > 0) { Coin += security.GetSettleTheFare(response.RawBytes.Length); SendMessage(Coin); } switch (param) { case Privacies _: return(new Tuple <int, double>((int)response.StatusCode, JsonConvert.DeserializeObject <double>(response.Content))); } } catch (Exception ex) { SendMessage(ex.StackTrace); SendMessage((int)response.StatusCode); } return(new Tuple <int, double>((int)response.StatusCode, Coin)); }
public async Task <int> DeleteContext <T>(IParameters param) { var response = await client.ExecuteAsync <T>(new RestRequest(string.Concat(security.CoreAPI, param.GetType().Name, "/", param.Security), Method.DELETE), source.Token); try { if (response != null && response.RawBytes != null && response.RawBytes.Length > 0) { Coin += security.GetSettleTheFare(response.RawBytes.Length); SendMessage(Coin); } return((int)response.StatusCode); } catch (Exception ex) { SendMessage(ex.StackTrace); SendMessage((int)response.StatusCode); } return(int.MinValue); }
public async Task <object> GetContext <T>(IParameters param) { var response = await client.ExecuteAsync <T>(new RestRequest(string.Concat(security.CoreAPI, param.GetType().Name, "/", param.Security), Method.GET), source.Token); try { if (response != null && response.RawBytes != null && response.RawBytes.Length > 0) { Coin += security.GetSettleTheFare(response.RawBytes.Length); SendMessage(Coin); } switch (param) { case Privacies _: return(JsonConvert.DeserializeObject <Privacies>(response.Content)); } } catch (Exception ex) { SendMessage(ex.StackTrace); SendMessage((int)response.StatusCode); } return(null); }