how to check if a string value exists in ReportParameter list c#

I have a ReportParameter list called lstParam with few values.

List<ReportParameter> lstParam = new List<ReportParameter>();
ReportParameter rpm = new ReportParameter();    
rpm.Name = "Department";
rpm.Name = "Location";
lstParam.Add(rpm);

Note: ReportParameter is used from reporting services rdlobject model

Now I need to check if the list has a specific string value and the below code doesn't work for 'ReportParameter' list.

var matchingvalues = !lstParam.Where(stringToCheck => stringToCheck.Contains(stringValue));

if (!lstParam.Any(str => str.Contains(stringValue)))
  { 

  }

Both the above statement didn't help and I get the below error.

'ReportParameter' does not contain a definition for 'Contains' and the best extension 
method overload 'Queryable.Contains<string>(IQueryable<string>,string)' 
requires a receiver of type 'IQueryable<string>'

ReportParameter class:

public class ReportParameter : ReportObject, INamedObject
{
    public ReportParameter();

    [DefaultValue(false)]
    public bool AllowBlank { get; set; }
    public DataTypes DataType { get; set; }
    public DefaultValue DefaultValue { get; set; }
    [DefaultValue(false)]
    public bool Hidden { get; set; }
    [DefaultValue(false)]
    public bool MultiValue { get; set; }
    [XmlAttribute(typeof(string))]
    public string Name { get; set; }
    [DefaultValue(false)]
    public bool Nullable { get; set; }
    [ReportExpressionDefaultValueAttribute]
    public ReportExpression Prompt { get; set; }
    [DefaultValue("")]
    [XmlChildAttributeAttribute("Prompt", "LocID", "http://schemas.microsoft.com/SQLServer/reporting/reportdesigner")]
    public string PromptLocID { get; set; }
    [DefaultValue(UsedInQueryTypes.Auto)]
    public UsedInQueryTypes UsedInQuery { get; set; }
    public ValidValues ValidValues { get; set; }

    protected override bool RdlSemanticEqualsCore(ReportObject rdlObj, ICollection<ReportObject> visitedList);
}

Really appreciate any suggestions.


ANSWERS:


If you want to check only if there ia any item that satisifes your condition, can you please try this code

bool matchingvalues = lstDSParameter.SelectMany(stringToCheck => stringToCheck.Name.Contains(stringValue) || stringToCheck.PromptLocID.Contains(stringValue)).ToList().Count > 0

You describe two lists: lstParam and lstDSParameter. I assume that is a typo and they are the same list.

Each element in lstParam is of type ReportParameter. If you use Enumerable.Where, every item in the were clause represents a ReportParameter. A ReportParameter is not a string, and thus you get the compiler error you described.

You say that you need to check if the list has a specific string value.

Well obviously, because the list does not contain strings, there isn't any. Therefore I assume that you need to check if a certain property of the elements in the sequence contains a specific string value. Let's assume you want to check if any of the Names of the ReportParameters in the sequence contains the specific string value.

To do this, you have to transform every element in the sequence to a string that contains the Name value of each element. In Linq, whenever you need to transform elements from a sequence into something else you use Enumerable.Select:

List<ReportParameter> lstParam = ...;
var reportParameterNames = lstParam.Select(reportParameter => reportParameter.Name);

"From every reportParameter in lstParam, take reportParameter.Name, and put these names in a new sequence called reportParameterNames"

Now to check if any of the reportParameterNames equals the SpecificStringValue you can use Enumerable.Any:

bool lstParamContainSpecificStringValue = reportParameterNames
    .Any(name => name == SpecificStringValue);

"Check if any element in the reportParameterNames sequence equals SpecificStringValue"

This article helped me to understand LINQ, and learned me how to use it


It seems you are using the ReportParameter from the wrong namespace. Try using the one in the Microsoft.ReportingServices.ReportRendering Namespace. This one contains a Value property.

MSDN ReportParameter Class

So you can use it like this:

if (!lstParam.Any(p => p.Value?.ToString().Contains(stringValue)))
{ 

}

have look at the question this.

may be reflection can help you here. I suggest you to 1st loop through the

    List<ReportParameter> lstParam = new List<ReportParameter>();
foreach(var item in lstParam )
{
//and then loop through class properties 
Type type = item.GetType();
PropertyInfo[] properties = type.GetProperties();

foreach (PropertyInfo property in properties )
{
    //now here you can play with class properties 
//like property.Name or property.Value
//place your check here
}
}

I haven't tested this code, just suggesting you the path to go. I hope this will help, trying to find some other efficiente way to get rid of loops.



 MORE:


 ? how to check if a string value exists in ReportParameter list c#
 ? How to loop through all the properties of a class?
 ? c# Reporting Services -- ReportParameter value that isn't a string
 ? Check Acive Directory Group Membership form within SSRS Report Custom Code
 ? Set SSRS Report Parameter value with passed Querystring value in SSRS
 ? SUM IIF Expression returning an error
 ? SSRS Report resizes when rendered in preview mode
 ? AX SSRS use expression from another dataset in total
 ? ssrs dril through to another report from matrix collapsed mode
 ? How to create little colored shape in a cell that would indicate colors on a chart? SSRS 2012