-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
428 additions
and
172 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,7 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
|
||
namespace Lombiq.Vsix.Orchard.Constants | ||
namespace Lombiq.Vsix.Orchard.Constants | ||
{ | ||
internal static class DependencyInjectorErrorCodes | ||
{ | ||
public const string ClassNotFound = "ClassNotFound"; | ||
public const string ConstructorNotFound = "ConstructorNotFound"; | ||
} | ||
} |
221 changes: 110 additions & 111 deletions
221
Lombiq.Vsix.Orchard/Forms/InjectDependencyDialog.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,62 +1,56 @@ | ||
using System; | ||
using Lombiq.Vsix.Orchard.Services; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Windows.Forms; | ||
|
||
namespace Lombiq.Vsix.Orchard.Forms | ||
{ | ||
public partial class InjectDependencyDialog : Form | ||
{ | ||
public string DependencyName { get { return textBox1.Text; } } | ||
private readonly IEnumerable<IFieldNameFromDependencyGenerator> _fieldNameGenerators; | ||
|
||
public string PrivateFieldName { get { return textBox2.Text; } } | ||
|
||
public string DependencyName { get { return dependencyNameTextBox.Text; } } | ||
public string PrivateFieldName { get { return fieldNameTextBox.Text; } } | ||
|
||
public InjectDependencyDialog() | ||
|
||
public InjectDependencyDialog(IEnumerable<IFieldNameFromDependencyGenerator> fieldNameGenerators) | ||
{ | ||
_fieldNameGenerators = fieldNameGenerators; | ||
|
||
InitializeComponent(); | ||
} | ||
|
||
|
||
public string GenerateFieldName(string dependency, bool useShortName = false) | ||
{ | ||
var fieldNameGenerator = _fieldNameGenerators | ||
.OrderByDescending(service => service.Priority) | ||
.First(service => service.CanGenerate(dependency)); | ||
|
||
return fieldNameGenerator.Generate(dependency, useShortName); | ||
} | ||
|
||
|
||
protected override void OnLoad(EventArgs e) | ||
{ | ||
base.OnLoad(e); | ||
|
||
this.ActiveControl = textBox1; | ||
this.ActiveControl = dependencyNameTextBox; | ||
} | ||
|
||
private void textBox1_TextChanged(object sender, EventArgs e) | ||
|
||
private void dependencyNameTextBox_TextChanged(object sender, EventArgs e) | ||
{ | ||
if (DependencyName.Length == 0) | ||
{ | ||
textBox2.Text = string.Empty; | ||
fieldNameTextBox.Text = string.Empty; | ||
} | ||
else | ||
{ | ||
textBox2.Text = GenerateFieldName(DependencyName, checkBox1.Checked); | ||
fieldNameTextBox.Text = GenerateFieldName(DependencyName, generateShortFieldNameCheckBox.Checked); | ||
} | ||
} | ||
|
||
public static string GenerateFieldName(string dependency, bool useShortName = false) | ||
{ | ||
if (dependency.Length < 2) return "_" + dependency.ToLowerInvariant(); | ||
|
||
var cleanedDependency = dependency.Length > 1 && dependency.StartsWith("I") && char.IsUpper(dependency[1]) ? dependency.Substring(1) : string.Copy(dependency); | ||
|
||
if (dependency.Length < 2) return "_" + dependency.ToLowerInvariant(); | ||
|
||
if (useShortName) | ||
{ | ||
var upperCasedLetters = cleanedDependency.Where(letter => char.IsUpper(letter)); | ||
|
||
return upperCasedLetters.Any() ? ("_" + new string(upperCasedLetters.ToArray())).ToLowerInvariant() : "_" + cleanedDependency[0]; | ||
} | ||
|
||
return "_" + char.ToLower(cleanedDependency[0]) + cleanedDependency.Substring(1); | ||
} | ||
|
||
private void button2_Click(object sender, EventArgs e) | ||
{ | ||
|
||
} | ||
} | ||
} |
Oops, something went wrong.