Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2743 from comintern/next
EncapsulateFieldDialog fixes, refactor.
- Loading branch information
Showing
8 changed files
with
201 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
RetailCoder.VBE/Refactorings/EncapsulateField/PropertyGenerator.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
using System; | ||
|
||
namespace Rubberduck.Refactorings.EncapsulateField | ||
{ | ||
public class PropertyGenerator | ||
{ | ||
public string PropertyName { get; set; } | ||
public string BackingField { get; set; } | ||
public string AsTypeName { get; set; } | ||
public string ParameterName { get; set; } | ||
public bool GenerateLetter { get; set; } | ||
public bool GenerateSetter { get; set; } | ||
|
||
public string AllPropertyCode | ||
{ | ||
get | ||
{ | ||
return GetterCode + | ||
(GenerateLetter ? LetterCode : string.Empty) + | ||
(GenerateSetter ? SetterCode : string.Empty); | ||
} | ||
} | ||
|
||
public string GetterCode | ||
{ | ||
get | ||
{ | ||
if (GenerateSetter && GenerateLetter) | ||
{ | ||
return string.Join(Environment.NewLine, | ||
string.Format("Public Property Get {0}() As {1}", PropertyName, AsTypeName), | ||
string.Format(" If IsObject({0}) Then", BackingField), | ||
string.Format(" Set {0} = {1}", PropertyName, BackingField), | ||
" Else", | ||
string.Format(" {0} = {1}", PropertyName, BackingField), | ||
" End If", | ||
"End Property", | ||
Environment.NewLine); | ||
} | ||
|
||
return string.Join(Environment.NewLine, | ||
string.Format("Public Property Get {0}() As {1}", PropertyName, AsTypeName), | ||
string.Format(" {0}{1} = {2}", GenerateSetter ? "Set " : string.Empty, PropertyName, BackingField), | ||
"End Property", | ||
Environment.NewLine); | ||
} | ||
} | ||
|
||
public string SetterCode | ||
{ | ||
get | ||
{ | ||
if (!GenerateSetter) | ||
{ | ||
return string.Empty; | ||
} | ||
return string.Join(Environment.NewLine, | ||
string.Format("Public Property Set {0}(ByVal {1} As {2})", PropertyName, ParameterName, AsTypeName), | ||
string.Format(" Set {0} = {1}", BackingField, ParameterName), | ||
"End Property", | ||
Environment.NewLine); | ||
} | ||
} | ||
|
||
public string LetterCode | ||
{ | ||
get | ||
{ | ||
if (!GenerateLetter) | ||
{ | ||
return string.Empty; | ||
} | ||
return string.Join(Environment.NewLine, | ||
string.Format("Public Property Let {0}(ByVal {1} As {2})", PropertyName, ParameterName, AsTypeName), | ||
string.Format(" {0} = {1}", BackingField, ParameterName), | ||
"End Property", | ||
Environment.NewLine); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.