Skip to content
This repository has been archived by the owner on Oct 16, 2020. It is now read-only.

Commit

Permalink
Implemented EnvDTE.CodeFunction2.IsGeneric
Browse files Browse the repository at this point in the history
The T4MVC template ignores controller methods that are generic.
  • Loading branch information
mrward committed Aug 26, 2012
1 parent 1e6d363 commit 8bab34c
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public CodeFunction2(IMethod method)
}

public virtual bool IsGeneric {
get { throw new NotImplementedException(); }
get { return Method.HasTypeParameters(); }
}

public virtual vsCMOverrideKind OverrideKind {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,14 @@ public static bool IsConstructor(this IMethodOrProperty methodOrProperty)
}
return false;
}

public static bool HasTypeParameters(this IMethodOrProperty methodOrProperty)
{
var method = methodOrProperty as IMethod;
if ((method != null) && (method.TypeParameters != null)) {
return method.TypeParameters.Count > 0;
}
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
<Compile Include="Src\Helpers\TestablePackageFromRepository.cs" />
<Compile Include="Src\Helpers\TestableProjectBehaviour.cs" />
<Compile Include="Src\Helpers\TestableSelectedProjectsForUpdatedPackages.cs" />
<Compile Include="Src\Helpers\TypeParameterHelper.cs" />
<Compile Include="Src\Helpers\UsingHelper.cs" />
<Compile Include="Src\Helpers\UsingScopeHelper.cs" />
<Compile Include="Src\InstalledPackageViewModelTests.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,5 +95,37 @@ public void OverrideKind_MethodHiddenByNewKeyword_ReturnsNew()

Assert.AreEqual(vsCMOverrideKind.vsCMOverrideKindNew, kind);
}

[Test]
public void IsGeneric_MethodHasTypeParameter_ReturnsTrue()
{
CreatePublicFunction("MyClass.MyFunction");
helper.AddTypeParameter("TResult");

bool generic = codeFunction.IsGeneric;

Assert.IsTrue(generic);
}

[Test]
public void IsGeneric_MethodHasTypeParameters_ReturnsFalse()
{
CreatePublicFunction("MyClass.MyFunction");
helper.NoTypeParameters();

bool generic = codeFunction.IsGeneric;

Assert.IsFalse(generic);
}

[Test]
public void IsGeneric_MethodTypeParametersIsNull_ReturnsFalse()
{
CreatePublicFunction("MyClass.MyFunction");

bool generic = codeFunction.IsGeneric;

Assert.IsFalse(generic);
}
}
}
18 changes: 18 additions & 0 deletions src/AddIns/Misc/PackageManagement/Test/Src/Helpers/MethodHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Dom;
using Rhino.Mocks;

Expand Down Expand Up @@ -160,5 +161,22 @@ public void MakeMethodOverridable()
{
Method.Stub(m => m.IsOverridable).Return(true);
}

public void AddTypeParameter(string name)
{
var typeParameterHelper = new TypeParameterHelper();
typeParameterHelper.SetName(name);
AddTypeParameters(typeParameterHelper.TypeParameterToList());
}

public void AddTypeParameters(List<ITypeParameter> typeParameters)
{
Method.Stub(m => m.TypeParameters).Return(typeParameters);
}

public void NoTypeParameters()
{
AddTypeParameters(new List<ITypeParameter>());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)

using System;
using System.Collections.Generic;
using ICSharpCode.SharpDevelop.Dom;
using Rhino.Mocks;

namespace PackageManagement.Tests.Helpers
{
public class TypeParameterHelper
{
public ITypeParameter TypeParameter;

public TypeParameterHelper()
{
TypeParameter = MockRepository.GenerateMock<ITypeParameter>();
}

public void SetName(string name)
{
TypeParameter.Stub(tp => tp.Name);
}

public List<ITypeParameter> TypeParameterToList()
{
var parameters = new List<ITypeParameter>();
parameters.Add(TypeParameter);
return parameters;
}
}
}

0 comments on commit 8bab34c

Please sign in to comment.