public static IsArray ( IContractResolver resolver, |
||
resolver | IContractResolver | |
type | ||
Résultat | bool |
public KnockoutObservableArray(IContractResolver resolver, object array) { if (array == null) { throw new ArgumentNullException("array"); } if (!JsonValue.IsArray(resolver, array.GetType())) { throw new ArgumentException("array must be a recognized Json.NET array type.", "array"); } _array = array; }
static JsonValue ToViewModelInternal(Stack <object> visited, Type modelType, IContractResolver resolver, object model) { if (JsonValue.IsPrimitive(resolver, modelType)) { return(new JsonValue(resolver, model)); } else { var dicType = typeof(ViewDataDictionary <>).MakeGenericType(modelType); var viewData = (ViewDataDictionary)Activator.CreateInstance(dicType, model); var metadata = ModelMetadata.FromStringExpression(string.Empty, viewData); var json = JsonObject.Create(); foreach (var p in metadata.Properties) { var vdi = viewData.GetViewDataInfo(p.PropertyName); //not using eval so it doesn't convert to string... var value = vdi.PropertyDescriptor.GetValue(viewData.Model); if (JsonValue.IsPrimitive(resolver, p.ModelType)) { json.AddObservable(p.PropertyName, value); } else if (JsonValue.IsArray(resolver, p.ModelType)) { //its an enumerable (we test the property type instead of the value incase the value is null) json.AddObservableArray(p.PropertyName, (IEnumerable)value, resolver); } else { if (!visited.Contains(value)) { visited.Push(value); json.AddProperty(p.PropertyName, ToViewModelInternal(visited, p.ModelType, resolver, value)); visited.Pop(); } } } return(json); } }