sashok
sashok
CC#
Created by sashok on 6/28/2024 in #help
Unable to get the FieldInfo's value
public static List<T> FindInstances<T>(object value)
{
List<T> instances = new();

Type type = value.GetType();

foreach (FieldInfo field in type.GetFields())
{
if (typeof(T).IsAssignableFrom(field.FieldType))
{
object fieldValue = field.GetValue(value);

if (fieldValue is T instance)
{
instances.Add(instance);
}
}
}

return instances;
}
public static List<T> FindInstances<T>(object value)
{
List<T> instances = new();

Type type = value.GetType();

foreach (FieldInfo field in type.GetFields())
{
if (typeof(T).IsAssignableFrom(field.FieldType))
{
object fieldValue = field.GetValue(value);

if (fieldValue is T instance)
{
instances.Add(instance);
}
}
}

return instances;
}
The following method should find the fields of type T in the class. When having these strings, it only returns a List of 2 empty ones.
public string string1 = "string 1";
public string string2 = "string 2";
public string string1 = "string 1";
public string string2 = "string 2";
7 replies
CC#
Created by sashok on 2/17/2024 in #help
Regex - Match a string outside of the parentheses
How do I match any e which's not inside of the parentheses? I have created a pattern to do it, but it doesn't seem to work properly. It should store (s and remove )s, so that an e that is outside of the parentheses is matched e.g. ()()()e, but e inside of the parentheses isn't e.g. (e). https://regex101.com/r/3m6ZUc/1
(?<=(?:[^()]|(?<a>\()|(?<-a>\)))+(?(a)(?!)))e
(?<=(?:[^()]|(?<a>\()|(?<-a>\)))+(?(a)(?!)))e
14 replies
CC#
Created by sashok on 7/31/2023 in #help
Cannot connet to localhost:5432
30 replies