I'm new in the c# world and I'm trying to pass an argument dynamically
So I'm doing a small addin on ms Project, and I need to do some calculation when the data is a duration or a Cost, so I have many duration field Duration1,Duration2,... and the same for cost fields
So what I'm doing is simple, I found all duration ID and I put them in my DurationList, after that I make a check, if I select only one column and the ID of this selected column is in my list, I take the name of this field and I try to pass it as an argument
This is a piece of my code, here I'm just working on the duration
using MSProject = Microsoft.Office.Interop.MSProject;
private void Application_WindowSelectionChange(MSProject.Window Window, MSProject.Selection sel, object selType)
{
MSProject.Task task = null;
List <int> DurationList = new List<int> { 188744967,...};
int value= Int32.Parse(Application.ActiveSelection.FieldIDList[1]);
Double Cost=0, CostTotal=0;
if (DurationList.Contains(value)){
string fieldname= Application.ActiveSelection.FieldName[1];
for (int i = 1; i <= sel.Tasks.Count; i++)
{
task = sel.Tasks[i];
Cost = Convert.ToDouble(task.fieldname);
CostTotal += Cost;
}
}
}
but when I tried that I get an error message: "Task" doesn't contain a definition for name and no extension method 'name' accepting a first argument of type 'Task' could be found. So what my code is excpected to do, it gets the name of my field, it stores it in my fieldname string and after that I want to pass the content of this string as an arugment of my task.fieldname. If I used a suggested field which appear with the small wrench, like cost or duration, my code runs without issues but I need to get something more dynamic Any idea?
Thanks