public void FieldInfo_Null() { var x = new JsonProperty(); x.UnderlyingName = null; Assert.IsNull(x.FieldInfo()); }
public void FieldInfo_Test() { var x = new JsonProperty(); x.UnderlyingName = "test"; x.DeclaringType = typeof(Test); Assert.IsNull(x.FieldInfo()); }
public static bool HasAttribute <T>(this JsonProperty jsonProperty) { var propInfo = jsonProperty.PropertyInfo(); if (propInfo != null) { return(Attribute.IsDefined(propInfo, typeof(T))); } else { var fieldInfo = jsonProperty.FieldInfo(); return(fieldInfo != null && Attribute.IsDefined(fieldInfo, typeof(T)));; } }
public static Schema WithValidationProperties(this Schema schema, JsonProperty jsonProperty) { var propInfo = jsonProperty.PropertyInfo(); var fieldInfo = jsonProperty.FieldInfo(); if (propInfo == null && fieldInfo == null) { return(schema); } if (propInfo != null) { foreach (var attribute in propInfo.GetCustomAttributes(false)) { schema.AddDefault(attribute); schema.AddPattern(attribute); schema.AddRange(attribute); schema.AddLength(attribute); } } if (fieldInfo != null) { foreach (var attribute in fieldInfo.GetCustomAttributes(false)) { schema.AddDefault(attribute); schema.AddPattern(attribute); schema.AddRange(attribute); schema.AddLength(attribute); } } if (!jsonProperty.Writable) { schema.readOnly = true; } return(schema); }