Skip to content

Commit

Permalink
Merge with dev
Browse files Browse the repository at this point in the history
  • Loading branch information
Piedone committed Mar 18, 2017
2 parents fa1ff88 + de3412a commit f504509
Show file tree
Hide file tree
Showing 15 changed files with 428 additions and 172 deletions.
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 Lombiq.Vsix.Orchard/Forms/InjectDependencyDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

56 changes: 25 additions & 31 deletions Lombiq.Vsix.Orchard/Forms/InjectDependencyDialog.cs
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)
{

}
}
}
Loading

0 comments on commit f504509

Please sign in to comment.