Reputation: 24052
So I have this method:
public IList<IndicationProject> GetProjectsForSponsor(int sponsorId)
{
IList<IndicationProject> result = new List<IndicationProject>();
IWspWB_IndicationGetProjectsForEntityResultSet tmpResultSet = ExecWspWB_IndicationGetProjectsForEntity(sponsorId);
if (tmpResultSet.WspWB_IndicationGetProjectsForEntity1 != null)
{
foreach (WspWB_IndicationGetProjectsForEntity1LightDataObject ldo in tmpResultSet.WspWB_IndicationGetProjectsForEntity1)
{
result.Add(
new IndicationProject()
.Named(NullConvert.From(ldo.Stp_name, null))
.IdentifiedBy(NullConvert.From(ldo.Stp_straight_through_processing_id, 0))
);
}
}
return result;
}
Contained within this class:
namespace Web.Data.Indications
{
public partial class IndicationsDataTier
{
I want to use that method in another one of my classes, like so:
IList<IndicationProject> oldList = Web.Data.Indications.IndicationsDataTier.GetProjectsForSponsor(entityId);
But when I compile I get this error:
Error 44 An object reference is required for the non-static field, method, or property 'Web.Data.Indications.IndicationsDataTier.GetProjectsForSponsor(int)'
Upvotes: 0
Views: 4370
Reputation: 3829
If the constructor of IndicationsDataTier is parameterless you can try:
IList<IndicationProject> oldList = (new Web.Data.Indications.IndicationsDataTier).GetProjectsForSponsor(entityId);
or go with the static modifier..
Upvotes: 0
Reputation: 1166
From reading you method it looks like you can mark the methods as static.
Upvotes: 0
Reputation: 1896
You have not declared the method as static, so you need to create an instance first. e.g.:
var oldList = new Web.Data.Indications.IndicationsDataTier();
oldList.GetProjectsForSponsor(int sponsorId);
Upvotes: 0
Reputation: 4572
The method is not static so you need to actually instantiate the IndicationsDataTier
Upvotes: 0
Reputation: 6208
You have declared the method non-static.
You are accessing it as a class method (MyClass.MyMethod), instead of as an instance method (myVar.MyMethod).
Change the declaration to be static
to call it the way you are.
Upvotes: 0
Reputation: 343
The method header for the specified method does not include the static keyword.
Upvotes: 0
Reputation: 838376
Your method is an instance member but you are calling it as if it were static.
If you want it to be a static method you should add the static
keyword:
public static IList<IndicationProject> GetProjectsForSponsor(int sponsorId)
{
// ...
}
If you want it to be an instance method you should create (or otherwise obtain a reference to) an instance of the type and then call the method on that instance:
using Web.Data.Indications;
// ...
IndicationsDataTier idt = new IndicationsDataTier();
IList<IndicationProject> oldList = idt.GetProjectsForSponsor(entityId);
Upvotes: 3
Reputation: 160922
You are trying to access the method via the class, but you need to access it via an instance of the class, since it's not a static method.
Upvotes: 0