public class QuickSearch : Widget
{
public TreeView UsingItemTemplate(Func<HelperResult> html)
{
return UsingItemTemplate(html.Invoke().ToHtmlString());
}
}
I want to return a value of the type TreeView which is another class in the system, but I am doing this in the class named QuickSearch. How I can do that?
CodePudding user response:
"'TreeView' is a namespace, but is used like a type" - Your problem is that you have a namespace with the same name as your class. Change the namespace so that it doesn't end in "TreeView" e.g.
namespace MyProject.TreeViews
{
public class TreeView
{
//class code
}
}
CodePudding user response:
Sounds like you've misunderstood the use of namespaces. If you have a namespace for each class then you're going to run into problems. In this case, if you have a Search class and a TreeView class that are both Widgets, you could conceivably have both of them under the DB.Web.Widgets namespace. To do that, just update the namespace in each class to remove the 'Search' and 'TreeView' part in the namespace. Then the Search class should be able to use the TreeView class quite happily.
Update
If you can't refactor the namespace then you can get around it by doing:
public TreeView.TreeView UsingItemTemplate(Func<HelperResult> html)
{
return UsingItemTemplate(html.Invoke().ToHtmlString());
}