I am facing the problem in Typecast inside the Generic class.
I need a function which will take two param 1:-Xpath 2:- XMLDOC
and return me what i will need.
here is the code for accessing to the Generic class.
Expand|Select|Wrap|Line Numbers
- private double mtrxgraphdata;
- private XMLdocument Matrixdata;
- GraphControl.XMLUtility<double> obj = new XMLUtility<double>();
- mtrxgraphdata = obj.GetElement("//Matrix/matrixdata/",Matrixdata);
- Here is the code for the Generic class.
- class XMLUtility<T>
- {
- public T GetElement(string Xpath,XmlDocument XmlDoc)
- {
- XmlNodeList Elements = XmlDoc.SelectNodes(Xpath);
- T[] returnList = new T[Elements.Count];
- int counter = 0;
- foreach (XmlNode node in Elements)
- {
- returnList[counter] =(T) node.InnerText;// here i am getting error "Cannot convert type 'string' to 'T' "
- counter++;
- }
- }
- return returnList;
- }
- }