I am working on implementing a .net core OData interface.
One field: FileStore is of type IEnumerable. In order to get this field in excel, I converted it to string using string.join. Now, I want to apply a regex on it to get values only matching "MKOIP-P0".
return Ok(_assetDiscoveryService.GetAllAssets(tenantGuid).Select(a => new ODataAsset
{
FileStore = a.Type == "VMWare.Compute/virtualMachines" ? string.Join(",", a.VSphereSpecificInfo.DiskInfo.Select(b => b.Filestore) ): null,
}).AsQueryable());
I am aware of Regex.Match. but that throws an error: Cannot implicitly convert source type "System.Text.RegularExpressions.Match" to target type "String".
Any help would be much appreciated.
Since the requirement is to check if b.FileStore contains a constant string "MKOIP-P0", we could just use string.Contains method:
FileStore = a.Type == "VMWare.Compute/virtualMachines" ? string.Join(",", a.VSphereSpecificInfo.DiskInfo.Select(b => b.Filestore).Where(fs => fs.Contains("MKOIP-P0")) ): null,