Пример #1
0
			public override void VisitPropertyDeclaration (PropertyDeclaration p)
			{
				if (p.Getter != null && p.Getter.Body.IsNull && p.Setter != null && p.Setter.Body.IsNull) {

					var f = new FieldDeclaration {
						Modifiers = p.Modifiers,
						ReturnType = p.ReturnType.Clone (),
					};
					f.Variables.Add (new VariableInitializer (p.Name));
					p.ReplaceWith (f);
				} else {

					foreach (var a in p.Children.OfType<Accessor> ()) {
//						a.Body.Remove ();

						var getter = a.Role == PropertyDeclaration.GetterRole;

						var fun = new MethodDeclaration {
							Body = (BlockStatement)a.Body.Clone(),
							Name = (getter ? "get " : "set ") + p.Name,
							Modifiers = p.Modifiers,
						};
						fun.AddAnnotation (a);

						if (getter) {
							fun.ReturnType = p.ReturnType.Clone ();
						}
						else {
							fun.ReturnType = new PrimitiveType ("void");
							fun.Parameters.Add (new ParameterDeclaration {
								Name = "value",
								Type = p.ReturnType.Clone (),
							});
						}

						p.Parent.InsertChildAfter (p, fun, Roles.TypeMemberRole);
					}

					p.Remove ();

				}
			}