protected override void DefaultVisit(JsNode node) { base.DefaultVisit(node); if (node.Annotation <VMPropertyInfoAnnotation>() is VMPropertyInfoAnnotation propAnnotation) { var target = node.GetChildByRole(JsTreeRoles.TargetExpression); if (target.HasAnnotation <ObservableUnwrapInvocationAnnotation>()) { target = target.GetChildByRole(JsTreeRoles.TargetExpression); } else if (target.HasAnnotation <ObservableSetterInvocationAnnotation>()) { throw new NotImplementedException(); } var propertyType = propAnnotation.MemberInfo.GetResultType(); var containsObservables = true; if (propAnnotation.SerializationMap == null && target?.Annotation <ViewModelInfoAnnotation>() is ViewModelInfoAnnotation targetAnnotation) { propAnnotation.SerializationMap = targetAnnotation.SerializationMap.Properties.FirstOrDefault(p => p.PropertyInfo == propAnnotation.MemberInfo); containsObservables = targetAnnotation.ContainsObservables; } if (propAnnotation.SerializationMap is ViewModelPropertyMap propertyMap) { if (propertyMap.ViewModelProtection == ViewModel.ProtectMode.EncryptData) { throw new Exception($"Property {propAnnotation.MemberInfo.Name} is encrypted and cannot be used in JS."); } if (node is JsMemberAccessExpression memberAccess && propertyMap.Name != memberAccess.MemberName) { memberAccess.MemberName = propertyMap.Name; } } else if (propAnnotation.MemberInfo is FieldInfo) { throw new NotSupportedException($"Can not translate field '{propAnnotation.MemberInfo}' to Javascript"); } if (containsObservables) { node.AddAnnotation(ResultIsObservableAnnotation.Instance); if (ViewModelJsonConverter.IsCollection(propertyType)) { node.AddAnnotation(ResultIsObservableArrayAnnotation.Instance); } } node.AddAnnotation(new ViewModelInfoAnnotation(propertyType, containsObservables: containsObservables)); node.AddAnnotation(MayBeNullAnnotation.Instance); } if (node.Annotation <ViewModelInfoAnnotation>() is var vmAnnotation && vmAnnotation?.Type != null && vmAnnotation.SerializationMap == null) { vmAnnotation.SerializationMap = mapper.GetMap(vmAnnotation.Type); } }
private void SetType(JsNode node, IJsTypeInfo type, JsPropertyInfo prop = null, JsMethodSignature sig = null) { var a = node.Annotation<JsNodeTypeAnnotation>() ?? node.AddAnnotation(new JsNodeTypeAnnotation()); if (a.Type != null) a.Type = type; if (a.Property != null) a.Property = prop; if (a.FunctionSignature != null) a.FunctionSignature = sig; }