private void GatherExposedFieldNames(Type clazz) { FieldInfo[] fields = clazz.GetFields(BindingFlags.Instance | BindingFlags.NonPublic); for (int i = 0; i < fields.Length; i++) { string n = fields[i].Name; string disp = n.Replace("k__BackingField", "").Replace("<", "").Replace(">", ""); var ex = clazz.GetProperty(disp); bool isDefined = false; if (ex != null) { isDefined = Attribute.IsDefined(ex, typeof(Exposed)); } if (isDefined) { Exposed attr = (Exposed)Attribute.GetCustomAttribute(ex, typeof(Exposed)); Option opt = new Option(disp, n, clazz.Name, fields[i].FieldType.ToString(), attr.getName()); this.mapping.Add(disp, opt); exposedFields.Add(disp); } } }
private void GatherExposedMethodNames() { Assembly assembly = Assembly.GetExecutingAssembly(); MethodInfo[] methods = assembly.GetTypes() .SelectMany(t => t.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)) .Where(m => m.GetCustomAttributes(typeof(Exposed), false).Length > 0) .ToArray(); foreach (MethodInfo info in methods) { var ex = info.DeclaringType.GetMethod(info.Name); Exposed attr = info.DeclaringType.GetMethod(info.Name).GetCustomAttributes(true).OfType <Exposed>().FirstOrDefault(); Option opt = new Option(info.Name, info.Name, info.DeclaringType.Name, info.ReturnType.ToString(), attr.getName()); this.mapping.Add(info.Name, opt); exposedFields.Add(info.Name); } }