/// <summary>Generates the information for the field from the field definition</summary> /// <param name="field">The field definition to look into</param> /// <returns>Returns the information of the field</returns> public static FieldInfo GenerateInfo(FieldDefinition field) { // Variables FieldInfo info = new FieldInfo(); string val = System.Text.ASCIIEncoding.ASCII.GetString(field.InitialValue); if (field.IsAssembly) { info.accessor = "internal"; } else if (field.IsFamily) { info.accessor = "protected"; } else if (field.IsPrivate) { info.accessor = "private"; } else { info.accessor = "public"; } if (TypeInfo.ignorePrivate && PropertyInfo.GetAccessorId(info.accessor) == 0) { info.shouldDelete = true; return(info); } info.name = field.Name; info.typeInfo = QuickTypeInfo.GenerateInfo(field.FieldType); info.implementedType = QuickTypeInfo.GenerateInfo(field.DeclaringType); info.value = $"{ field.Constant ?? val }"; info.isConstant = field.HasConstant; info.isStatic = field.IsStatic; info.isReadonly = field.IsInitOnly; info.attributes = AttributeInfo.GenerateInfoArray(field.CustomAttributes); if (field.HasConstant) { info.modifier = "const"; } else if (field.IsStatic && field.IsInitOnly) { info.modifier = "static readonly"; } else if (field.IsStatic) { info.modifier = "static"; } else if (field.IsInitOnly) { info.modifier = "readonly"; } else { info.modifier = ""; } info.fullDeclaration = ( $"{ info.accessor } " + (info.modifier != "" ? info.modifier + " " : "") + $"{ info.typeInfo.name } " + info.name ); if (info.isConstant) { info.fullDeclaration += $" = { info.value }"; } return(info); }