/// <summary> /// Fields the instance. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="genericField">The generic field.</param> /// <param name="externalId">The external identifier.</param> /// <param name="fieldId">The field identifier.</param> /// <returns>T.</returns> protected T fieldInstance <T>(ApplicationField genericField, string externalId = null, int?fieldId = null) where T : ApplicationField, new() { T specificField = new T(); if (genericField != null) { foreach (var property in genericField.GetType().GetRuntimeProperties()) { var jsonAttribute = ((JsonPropertyAttribute[])property.GetCustomAttributes(typeof(JsonPropertyAttribute), false)); if (jsonAttribute.Length > 0) { specificField.GetType().GetRuntimeProperty(property.Name).SetValue(specificField, property.GetValue(genericField, null), null); } } } return(specificField); }
/// <summary> /// Sets the type of the field. /// </summary> /// <param name="field">The field.</param> private void SetFieldType(ApplicationField field) { if (field.GetType() == typeof(TextApplicationField)) { field.Type = "text"; } if (field.GetType() == typeof(NumericApplicationField)) { field.Type = "number"; } if (field.GetType() == typeof(StateApplicationField)) { field.Type = "state"; } if (field.GetType() == typeof(ImageApplicationField)) { field.Type = "image"; } if (field.GetType() == typeof(DateApplicationField)) { field.Type = "date"; } if (field.GetType() == typeof(AppReferenceApplicationField)) { field.Type = "app"; } if (field.GetType() == typeof(MoneyApplicationField)) { field.Type = "money"; } if (field.GetType() == typeof(ProgressApplicationField)) { field.Type = "progress"; } if (field.GetType() == typeof(LocationApplicationField)) { field.Type = "location"; } if (field.GetType() == typeof(DurationApplicationField)) { field.Type = "duration"; } if (field.GetType() == typeof(ContactApplicationField)) { field.Type = "contact"; } if (field.GetType() == typeof(CalculationApplicationField)) { field.Type = "calculation"; } if (field.GetType() == typeof(EmbedApplicationField)) { field.Type = "embed"; } if (field.GetType() == typeof(QuestionApplicationField)) { field.Type = "question"; } if (field.GetType() == typeof(CategoryApplicationField)) { field.Type = "category"; } if (field.GetType() == typeof(FileApplicationField)) { field.Type = "file"; } }