static void GenProps(FieldInfo fieldInfo, ref Dictionary <string, StringBuilder> clsNameToSb) { AttrDescAttribute attr = fieldInfo.GetCustomAttribute <AttrDescAttribute>(false); if (attr == null) { return; } string t = !attr.type.IsNested ? attr.type.FullName : attr.type.ReflectedType + "." + attr.type.Name; string field; if (string.IsNullOrEmpty(attr.field)) { field = fieldInfo.Name[0].ToString().ToLower() + fieldInfo.Name.Substring(1); } else { field = attr.field; } foreach (string attrName in attr.names) { StringBuilder sb = clsNameToSb[attrName]; sb.Append($"\t\tpublic {t} "); sb.AppendLine($"{field} => ( {t} )this._attrMap[{fieldInfo.DeclaringType}.{fieldInfo.Name}];"); } }
private static void GetClsNames(FieldInfo fieldInfo, ref Dictionary <string, StringBuilder> clsNameToSb) { AttrDescAttribute attr = fieldInfo.GetCustomAttribute <AttrDescAttribute>(false); if (attr == null) { return; } foreach (string attrName in attr.names) { if (!clsNameToSb.ContainsKey(attrName)) { clsNameToSb[attrName] = new StringBuilder(); } } }
static void GenInitializations(FieldInfo fieldInfo, ref Dictionary <string, StringBuilder> ctrToSb) { AttrDescAttribute attr = fieldInfo.GetCustomAttribute <AttrDescAttribute>(false); if (attr == null) { return; } string t = !attr.type.IsNested ? attr.type.FullName : attr.type.ReflectedType + "." + attr.type.Name; int count = attr.names.Length; for (int i = 0; i < count; i++) { string attrName = attr.names[i]; string defaultValue = !string.IsNullOrEmpty(attr.defaultVal) ? attr.defaultVal : (attr.defaultVals != null ? attr.defaultVals[i] : $"default( {t} )"); StringBuilder sb = ctrToSb[attrName]; sb.AppendLine($"\t\t\tthis._attrMap[{fieldInfo.DeclaringType}.{fieldInfo.Name}] = {defaultValue};"); } }