public IEnumerable <PropertyOrFieldReflection> GetPropertiesAndFields() { var properties = Type.GetProperties(BindingFlagsAny.Get()) .Where(x => x.GetIndexParameters().Length == 0) //filter out indexers .Select(x => x.Reflection()); var fields = Type.GetFields(BindingFlagsAny.Get()) .Select(x => x.Reflection()) .Where(x => !x.HasAttribute <CompilerGeneratedAttribute>()); return(properties.Concat(fields)); }
public MethodReflection GetGenericMethod(string methodName, int numberOfGenericArguments) { var method = Type.GetMethod(methodName, numberOfGenericArguments, BindingFlagsAny.Get(), Type.DefaultBinder, Array.Empty <Type>(), null); if (method == null) { throw new InvalidOperationException($"Type {Type.Name} does not implement generic method {methodName} with {numberOfGenericArguments} of generic arguments"); } return(method.Reflection()); }
public MethodReflection GetGenericMethod(string methodName) { var method = Type.GetMethod(methodName, BindingFlagsAny.Get()); if (method == null) { throw new InvalidOperationException($"Type {Type.Name} does not implement generic method {methodName}"); } return(method.Reflection()); }
public MethodReflection GetGenericMethod(string methodName, int numberOfGenericArguments, Type[] arguments) { var method = Type.GetMethod(methodName, numberOfGenericArguments, BindingFlagsAny.Get(), Type.DefaultBinder, arguments, null); if (method == null) { var argumentsStr = string.Join(",", arguments.Select(x => x.ToString())); throw new InvalidOperationException($"Type {Type.Name} does not implement generic method {methodName} with {numberOfGenericArguments} of generic arguments and with arguments {argumentsStr}"); } return(method.Reflection()); }
public PropertyOrFieldReflection GetPropertyOrField(string propertyOrFieldName) { var field = Type.GetField(propertyOrFieldName, BindingFlagsAny.Get()); if (field != null) { return(field.Reflection()); } var property = Type.GetProperty(propertyOrFieldName, BindingFlagsAny.Get()); if (property == null) { throw new InvalidOperationException($"Type {Type.Name} does not implement property or field {property}"); } return(property.Reflection()); }
public bool HasPropertyOrField(string propertyOrFieldName) { var field = Type.GetField(propertyOrFieldName, BindingFlagsAny.Get()); if (field != null) { return(true); } var property = Type.GetProperty(propertyOrFieldName, BindingFlagsAny.Get()); if (property != null) { return(true); } return(false); }
public bool HasMethod(string propertyName) { return(Type.GetMethod(propertyName, BindingFlagsAny.Get()) != null); }
public IEnumerable <MethodReflection> GetMethodsWithoutParentMethods() { return(Type.GetMethods(BindingFlagsAny.Get() | BindingFlags.DeclaredOnly) .Where(x => !(x.Name.StartsWith("set") || x.Name.StartsWith("get"))) .Select(x => x.Reflection())); }