vicky vicky - 11 days ago 7
ASP.NET (C#) Question

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.

Answer

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