Browse Source

Implement EnvDTE.CodeParameter.Attributes

The T4MVC template looks for the MVC BindAttribute on method parameters in order to get the prefix.
pull/28/head
Matt Ward 13 years ago
parent
commit
358fbf071b
  1. 19
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributes.cs
  2. 4
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeParameter.cs
  3. 4
      src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeParameter2.cs
  4. 13
      src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/CodeParameterTests.cs
  5. 7
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/AttributeHelper.cs
  6. 7
      src/AddIns/Misc/PackageManagement/Test/Src/Helpers/ParameterHelper.cs

19
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeAttributes.cs

@ -11,17 +11,24 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -11,17 +11,24 @@ namespace ICSharpCode.PackageManagement.EnvDTE
{
public class CodeAttributes : CodeElementsList
{
IEntity entity;
public CodeAttributes(IEntity entity)
: this(entity.Attributes)
{
}
public CodeAttributes(IParameter parameter)
: this(parameter.Attributes)
{
}
public CodeAttributes(IEnumerable<IAttribute> attributes)
{
this.entity = entity;
GetAttributes();
AddAttributes(attributes);
}
void GetAttributes()
void AddAttributes(IEnumerable<IAttribute> attributes)
{
foreach (IAttribute attribute in entity.Attributes) {
foreach (IAttribute attribute in attributes) {
AddAttribute(attribute);
}
}

4
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeParameter.cs

@ -29,5 +29,9 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -29,5 +29,9 @@ namespace ICSharpCode.PackageManagement.EnvDTE
public virtual CodeTypeRef2 Type {
get { return new CodeTypeRef2(projectContent, this, Parameter.ReturnType); }
}
public virtual CodeElements Attributes {
get { return new CodeAttributes(Parameter); }
}
}
}

4
src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/CodeParameter2.cs

@ -32,9 +32,5 @@ namespace ICSharpCode.PackageManagement.EnvDTE @@ -32,9 +32,5 @@ namespace ICSharpCode.PackageManagement.EnvDTE
}
return vsCMParameterKind.vsCMParameterKindNone;
}
public virtual CodeElements Attributes {
get { throw new NotImplementedException(); }
}
}
}

13
src/AddIns/Misc/PackageManagement/Test/Src/EnvDTE/CodeParameterTests.cs

@ -34,5 +34,18 @@ namespace PackageManagement.Tests.EnvDTE @@ -34,5 +34,18 @@ namespace PackageManagement.Tests.EnvDTE
Assert.AreEqual(vsCMElement.vsCMElementParameter, kind);
}
[Test]
public void Attributes_ParameterHasOneAttribute_ReturnsOneAttribute()
{
CreateParameter();
helper.AddAttributeToParameter("System.Web.Mvc.BindAttribute");
CodeElements attributes = parameter.Attributes;
CodeAttribute2 attribute = parameter.Attributes.FirstCodeAttribute2OrDefault();
Assert.AreEqual(1, attributes.Count);
Assert.AreEqual("System.Web.Mvc.BindAttribute", attribute.FullName);
}
}
}

7
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/AttributeHelper.cs

@ -56,5 +56,12 @@ namespace PackageManagement.Tests.Helpers @@ -56,5 +56,12 @@ namespace PackageManagement.Tests.Helpers
attributes.Add(Attribute);
method.Stub(m => m.Attributes).Return(attributes);
}
public void AddAttributeToParameter(IParameter parameter)
{
var attributes = new List<IAttribute>();
attributes.Add(Attribute);
parameter.Stub(p => p.Attributes).Return(attributes);
}
}
}

7
src/AddIns/Misc/PackageManagement/Test/Src/Helpers/ParameterHelper.cs

@ -40,5 +40,12 @@ namespace PackageManagement.Tests.Helpers @@ -40,5 +40,12 @@ namespace PackageManagement.Tests.Helpers
{
Parameter.Stub(p => p.Modifiers).Return(ParameterModifiers.In);
}
public void AddAttributeToParameter(string attributeTypeName)
{
var attributeHelper = new AttributeHelper();
attributeHelper.CreateAttribute(attributeTypeName);
attributeHelper.AddAttributeToParameter(Parameter);
}
}
}

Loading…
Cancel
Save