public string GetDeclareClassScript <T>(T obj) { Expression <Func <T, T> > expression = r => r.DeclareClassScript(); var visitor = new LinqToJavaScriptExpressionVisitor(); var exp = Expression.Invoke(expression, Expression.Constant(obj)); return(visitor.Translate(exp)); }
public override IDictionary <string, object> Serialize(object obj, JavaScriptSerializer serializer) { var javaScriptProperties = LinqToJavaScriptExpressionVisitor.GetJavaScriptProperties( obj, JavaScriptChildrenClasses); var dic = new Dictionary <string, object>(); var properties = javaScriptProperties .Where(r => r.ExpressionGetProperty == null || r.ExpressionSetProperty != null); foreach (var property in properties.Where(r => !r.ReadOnly)) { if (property.ChildObject != null) { // todo: убрать костыль. нужен другой сериализатор var sb = new StringBuilder(); sb.Append("$create(") .Append(property.JavaScriptClassAttribute.Namespace) .Append(Dot) .Append(property.JavaScriptClassAttribute.ClassName) .Append(", "); dic[property.PropertyName + "__" + property.JavaScriptClassAttribute.ClassName + "__"] = sb.ToString(); dic[property.JavaScriptClassAttribute.ClassName + "__"] = Serialize(property.ChildObject, serializer); dic[property.JavaScriptClassAttribute.ClassName + "____"] = string.Empty; } else { object value = property.PropertyDescriptor.GetValue(obj); if (value != null) { dic[property.PropertyName] = value; } } } return(dic); }