private void Tranlate_MethodOrProperty(PhpClassDefinition phpClass, MethodInfo info, IStatement body, string overrideName) { _state.Principles.CurrentMethod = info; try { var mti = _state.Principles.GetOrMakeTranslationInfo(info); var phpMethod = new PhpClassMethodDefinition(string.IsNullOrEmpty(overrideName) ? mti.ScriptName : overrideName); phpClass.Methods.Add(phpMethod); if (info.IsPublic) { phpMethod.Visibility = Visibility.Public; } else if (info.IsPrivate) { phpMethod.Visibility = Visibility.Private; } else { phpMethod.Visibility = Visibility.Protected; } phpMethod.IsStatic = info.IsStatic; { var declaredParameters = info.GetParameters(); foreach (var parameter in declaredParameters) { var phpParameter = new PhpMethodArgument(); phpParameter.Name = parameter.Name; phpMethod.Arguments.Add(phpParameter); if (parameter.HasDefaultValue) { phpParameter.DefaultValue = new PhpConstValue(parameter.DefaultValue); } } } if (body != null) { phpMethod.Statements.AddRange(TranslateStatement(body)); } } finally { _state.Principles.CurrentMethod = null; } }
private void TranslateConstructor(PhpClassDefinition phpClass, ConstructorDeclaration md) { // state.Principles.CurrentMethod = md.Info; try { // MethodTranslationInfo mti = MethodTranslationInfo.FromMethodInfo(md.Info); // state.Principles.CurrentMethod = var phpMethod = new PhpClassMethodDefinition("__construct"); phpClass.Methods.Add(phpMethod); if (md.Info.IsPublic) { phpMethod.Visibility = Visibility.Public; } else if (md.Info.IsPrivate) { phpMethod.Visibility = Visibility.Private; } else { phpMethod.Visibility = Visibility.Protected; } phpMethod.IsStatic = md.Info.IsStatic; { var declaredParameters = md.Info.GetParameters(); foreach (var parameter in declaredParameters) { var phpParameter = new PhpMethodArgument(); phpParameter.Name = parameter.Name; phpMethod.Arguments.Add(phpParameter); if (parameter.HasDefaultValue) { phpParameter.DefaultValue = new PhpConstValue(parameter.DefaultValue); } } } if (md.Body != null) { phpMethod.Statements.AddRange(TranslateStatement(md.Body)); } } finally { _state.Principles.CurrentMethod = null; } }
protected override IPhpValue VisitLambdaExpression(LambdaExpression src) { var T = new Translator(state); var a = new PhpMethodDefinition(""); a.Statements.AddRange(T.TranslateStatement(src.Body)); foreach (var p in src.Parameters) { var phpParameter = new PhpMethodArgument(); phpParameter.Name = p.Name; a.Arguments.Add(phpParameter); } var b = new PhpLambdaExpression(a); return(SimplifyPhpExpression(b)); }