void ProcessMember() { Member = Res.Member; Method = Member as IMethod; if (Method == null) { Property = Member as IProperty; if (Property != null) { Method = Property.Getter; Member = Method; } } MethodAtt = Method != null?Sk.GetJsMethodAttribute(Method) : null; }
public virtual JsNode ExportMethod(IMethod me) { var jma = Sk.GetJsMethodAttribute(me); if (jma != null && jma.GlobalCode) { var block = ExportMethodBody(me); return(new JsUnit { Statements = block.Statements }); } var func = new JsFunction(); func.Parameters = ExportMethodParameters(me); func.Name = SkJs.GetEntityJsName(me); func.Block = ExportMethodBody(me); func = ApplyYield(func); return(func); }
public JsNode VisitInvocationResolveResultAsCtor(CSharpInvocationResolveResult res) { if (res.Type.Kind == TypeKind.Delegate) { return(Visit(res.Arguments.Single())); } var me = (IMethod)res.Member; var meAtt = Sk.GetJsMethodAttribute(me); var ce = me.GetDeclaringTypeDefinition(); var att = ce == null ? null : ce.GetJsTypeAttribute(); if (att != null && att.Mode == JsMode.Json && (meAtt == null || meAtt.Name == null)) { var jtfn = ce == null ? null : Sk.GetJsonTypeFieldName(ce); var node2 = VisitInvocationResolveResult(res); var json = Importer.InitializersToJson(res.InitializerStatements, res.Type); if (jtfn != null) { var x = json as JsJsonObjectExpression; if (x != null) { x.Add(jtfn, SkJs.EntityTypeRefToMember(res.Type)); } } return(json); } else { var invokeExp = (JsInvocationExpression)VisitInvocationResolveResult(res); var newExp = new JsNewObjectExpression { Invocation = invokeExp }; JsExpression finalExp; if (meAtt != null && meAtt.OmitNewOperator) { finalExp = invokeExp; } else { finalExp = newExp; } if (meAtt != null && meAtt.JsonInitializers) { var json = Importer.InitializersToJson(res.InitializerStatements, res.Type); invokeExp.Arguments.Add(json); } else if (res.InitializerStatements.IsNotNullOrEmpty()) { var func = Js.Function(); var inits2 = res.InitializerStatements.Select(t => Visit(t)).ToList(); //var init1 = res.InitializerStatements[0]; var target = AstNodeConverter.FindInitializedObjectResolveResult(res);// ((init1 as OperatorResolveResult).Operands[0] as MemberResolveResult).TargetResult as InitializedObjectResolveResult; var varName = Importer.Initializers[target]; func.Add(Js.Var(varName, finalExp).Statement()); foreach (var init in inits2) { var exp = ((JsExpression)init); func.Add(exp.Statement()); } func.Add(Js.Return(Js.Member(varName))); finalExp = Importer.WrapFunctionAndInvoke(res, func); } return(finalExp); } }