diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
commit | 95408b1a41b31b645f3a8c3323ab7d3ca4bff26b (patch) | |
tree | f8f137cddcb9a40499d303be95722fd2c6081bce /main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PropertyGenerator.cs | |
parent | b70e4e04b4e41b8ec28d7e4b220b401ecf467e7a (diff) | |
parent | de043d330a8bf5855d4d983c804cd36727cb2406 (diff) |
Merge remote-tracking branch 'origin/roslyn' into new-project-model
Diffstat (limited to 'main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PropertyGenerator.cs')
-rw-r--r-- | main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PropertyGenerator.cs | 72 |
1 files changed, 55 insertions, 17 deletions
diff --git a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PropertyGenerator.cs b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PropertyGenerator.cs index b8829e58e7..c658adc37b 100644 --- a/main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PropertyGenerator.cs +++ b/main/src/addins/CSharpBinding/MonoDevelop.CSharp.CodeGeneration/PropertyGenerator.cs @@ -25,16 +25,15 @@ // THE SOFTWARE. using System; - -using ICSharpCode.NRefactory.CSharp; -using MonoDevelop.Core; -using MonoDevelop.Ide.Gui; -using Gtk; +using System.Linq; using System.Collections.Generic; -using MonoDevelop.Refactoring; using System.Text; -using ICSharpCode.NRefactory.TypeSystem; -using System.Linq; +using MonoDevelop.Core; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Simplification; +using System.Threading.Tasks; namespace MonoDevelop.CodeGeneration { @@ -86,19 +85,19 @@ namespace MonoDevelop.CodeGeneration { if (Options.EnclosingType == null || Options.EnclosingMember != null) yield break; - foreach (IField field in Options.EnclosingType.Fields) { - if (field.IsSynthetic) + foreach (var field in Options.EnclosingType.GetMembers ().OfType<IFieldSymbol> ()) { + if (field.IsImplicitlyDeclared) continue; - var list = Options.EnclosingType.Fields.Where (f => f.Name == CreatePropertyName (field));; + var list = Options.EnclosingType.GetMembers ().OfType<IFieldSymbol> ().Where (f => f.Name == CreatePropertyName (field)); if (!list.Any ()) yield return field; } } - static string CreatePropertyName (IMember member) + static string CreatePropertyName (ISymbol member) { int i = 0; - while (i + 1 < member.Name.Length && member.Name[i] == '_') + while (i + 1 < member.Name.Length && member.Name [i] == '_') i++; if (i + 1 >= member.Name.Length) return char.ToUpper (member.Name [i]).ToString (); @@ -107,10 +106,49 @@ namespace MonoDevelop.CodeGeneration protected override IEnumerable<string> GenerateCode (List<object> includedMembers) { - var generator = Options.CreateCodeGenerator (); - generator.AutoIndent = false; - foreach (IField field in includedMembers) - yield return generator.CreateFieldEncapsulation (Options.EnclosingPart, field, CreatePropertyName (field), Accessibility.Public, ReadOnly); + foreach (IFieldSymbol field in includedMembers) { + var node = SyntaxFactory.PropertyDeclaration ( + CreateConstructorGenerator.ConvertType (field.Type), + CreatePropertyName (field) + ); + + node = node.AddAccessorListAccessors ( + SyntaxFactory.AccessorDeclaration ( + SyntaxKind.GetAccessorDeclaration, + SyntaxFactory.Block ( + SyntaxFactory.ReturnStatement ( + SyntaxFactory.MemberAccessExpression ( + SyntaxKind.SimpleMemberAccessExpression, + SyntaxFactory.ThisExpression (), + SyntaxFactory.IdentifierName (field.Name) + ) + ) + ) + ) + ); + if (!ReadOnly) { + node = node.AddAccessorListAccessors ( + SyntaxFactory.AccessorDeclaration ( + SyntaxKind.SetAccessorDeclaration, + SyntaxFactory.Block ( + SyntaxFactory.ExpressionStatement ( + SyntaxFactory.AssignmentExpression ( + SyntaxKind.SimpleAssignmentExpression, + SyntaxFactory.MemberAccessExpression ( + SyntaxKind.SimpleMemberAccessExpression, + SyntaxFactory.ThisExpression (), + SyntaxFactory.IdentifierName (field.Name) + ), + SyntaxFactory.IdentifierName ("value") + ) + ) + ) + ) + ); + } + yield return Options.OutputNode (node).Result; + } + } } } |