private static string DetermineRessourceType(FieldInfo field, ResourceAttribute fieldAttribute) { if (String.IsNullOrEmpty(fieldAttribute.Name)) { return DetermineRessourceNameFromFieldName(field); } else { return fieldAttribute.Name; } }
private void InjectRessource(Object instance, FieldInfo field, ResourceAttribute fieldAttribute) { try { Object ressorce = DetermineResource(field, fieldAttribute); field.SetValue(instance, ressorce); } catch (Exception e) { throw new Exception("Error while injecting ressourse in " + DescribeField(field), e); } }
private Object DetermineResource(FieldInfo field, ResourceAttribute fieldAttribute) { String ressourceName = DetermineRessourceType(field, fieldAttribute); ressourceName = char.ToUpper(ressourceName[0]) + ressourceName.Substring(1); string firstFullNameByFieldName = _context.GetObjectDefinitionNames().FirstOrDefault(x => x.EndsWith(ressourceName)); if (!string.IsNullOrWhiteSpace(firstFullNameByFieldName)) { return _context.GetObject(firstFullNameByFieldName, field.FieldType); } return null; }