I have the following code:
public static IList<SortOption> SortValues()
{
var sortValues = (from prop in typeof(SolrSchemaApp1).GetProperties(BindingFlags.Instance | BindingFlags.Public)
where Attribute.IsDefined(prop, typeof(SolrSortAttribute))
select new SortOption(prop.Name)).ToList();
return sortValues;
}
where SolrSchemaApp1 is a class derived from an interface called ISolrDocument.
I want to pass in an instance of SolrSchemaApp2 and make my code select the sort properties from that one instead of SolrSchemaApp1. In effect, I want to do this:
public static IList<SortOption> SortValues(ISolrDocument schemaToScan)
{
var sortValues = (from prop in typeof(schemaToScan).GetProperties(BindingFlags.Instance | BindingFlags.Public)
where Attribute.IsDefined(prop, typeof(SolrSortAttribute))
select new SortOption(prop.Name)).ToList();
return sortValues;
}
All I have done is replaced the hard coded SolrSchemaApp1 with a variable of a different type. However, I get the error
The type or namespace name ‘schemaToScan’ could not be found (are you missing a using directive or an assembly reference?)
I’m struggling with the syntax of using GetProperties on an arbitrary class.
How do I use Linq to scan the properties of the class that I pass in as a parameter?
by
schemaToScan is an instance of a type, not a type.