private void CheckIndexAttributes(PropertyInfo matchedProperty, SearchIndexField searchIndexField, IList <string> ErrorLog, string indexName) { IEnumerable <string> attributesEnabledInModel = matchedProperty.CustomAttributes .Where(m => !(new[] { "JsonPropertyAttribute", "JsonIgnoreAttribute" }).Contains(m.AttributeType.Name)) .Select(m => m.AttributeType.Name.Replace("Attribute", "").Replace("Is", "").ToLower()); IEnumerable <string> attributesEnabledInJson = searchIndexField.GetType().GetProperties() .Where(p => p.PropertyType == typeof(bool) && (bool)p.GetValue(searchIndexField, null)) .Select(p => p.Name.ToLower()); IEnumerable <string> unsyncedAttributes = attributesEnabledInModel.Except(attributesEnabledInJson); if (unsyncedAttributes.Any()) { string attributes = string.Join(",", unsyncedAttributes); ErrorLog.Add( $"Index {indexName}: {searchIndexField.Name} Json attributes ({attributes}) are false but should be true"); } unsyncedAttributes = attributesEnabledInJson.Except(attributesEnabledInModel); if (unsyncedAttributes.Any()) { string attributes = string.Join(",", unsyncedAttributes); ErrorLog.Add( $"Index {indexName}: {searchIndexField.Name} Json attributes ({attributes}) are true but should be false"); } }
private void CheckIndexFieldTypes(PropertyInfo matchedProperty, SearchIndexField searchIndexField, IList <string> ErrorLog, string indexName) { bool modelIsCollection = false; bool jsonIsCollection = false; string modelType = matchedProperty.PropertyType.Name == "Nullable`1" ? matchedProperty.PropertyType.GenericTypeArguments[0].Name : matchedProperty.PropertyType.Name; if (modelType.EndsWith("[]")) { modelType = modelType.Replace("[]", ""); modelIsCollection = true; } string jsonType = searchIndexField.Type; if (jsonType.StartsWith("Collection(")) { jsonType = jsonType.Substring(11, jsonType.Length - 12); jsonIsCollection = true; } jsonType = jsonType.Split(new[] { '.' })[1]; if (modelType.ToLowerInvariant() != jsonType.ToLowerInvariant() || modelIsCollection != jsonIsCollection) { ErrorLog.Add($"Expected {indexName}.{ matchedProperty.Name } to be of type { (modelIsCollection ? " collection of " : "") }{ modelType }, but found { (jsonIsCollection ? " collection of " : "") } { jsonType }"); } }