private PropOrField FindSetterByName([NotNull] Type objectType, [NotNull, ItemNotNull] PropertyInfo[] properties, [NotNull, ItemNotNull] FieldInfo[] fields, [NotNull] string name, [CanBeNull] INamingConvention naming) { PropOrField result; foreach (var prop in properties) { ScriptableObjectPropertyAttribute sopa; if (_propertyAttributeCache.ContainsKey(prop)) { sopa = _propertyAttributeCache[prop]; } else { sopa = prop.GetCustomAttribute <ScriptableObjectPropertyAttribute>(); _propertyAttributeCache[prop] = sopa; } var propName = !string.IsNullOrEmpty(sopa?.Name) ? sopa.Name : (naming != null ? naming.GetCorrected(prop.Name) : prop.Name); if (propName == name) { var key = (objectType, propName, mbp : sopa); if (_createdSetters.ContainsKey(key)) { result = _createdSetters[key]; } else { result = new PropOrField(prop, sopa); _createdSetters[key] = result; } return(result); } } foreach (var field in fields) { ScriptableObjectPropertyAttribute sopa; if (_fieldAttributeCache.ContainsKey(field)) { sopa = _fieldAttributeCache[field]; } else { sopa = field.GetCustomAttribute <ScriptableObjectPropertyAttribute>(); _fieldAttributeCache[field] = sopa; } var fieldName = !string.IsNullOrEmpty(sopa?.Name) ? sopa.Name : (naming != null ? naming.GetCorrected(field.Name) : field.Name); if (fieldName == name) { var key = (objectType, fieldName, mbp : sopa); if (_createdSetters.ContainsKey(key)) { result = _createdSetters[key]; } else { result = new PropOrField(field, sopa); _createdSetters[key] = result; } return(result); } } return(PropOrField.Null); }
private static PropertyOrField FindByName(IReadOnlyList <PropertyInfo> properties, IReadOnlyList <FieldInfo> fields, string name, INamingConvention namingConvention) { foreach (var prop in properties) { var mbp = prop.GetCustomAttribute <MonoBehaviourPropertyAttribute>(); var propName = !string.IsNullOrEmpty(mbp?.Name) ? mbp.Name : (namingConvention != null ? namingConvention.GetCorrected(prop.Name) : prop.Name); if (propName == name) { return(new PropertyOrField(prop, mbp)); } } foreach (var field in fields) { var mbp = field.GetCustomAttribute <MonoBehaviourPropertyAttribute>(); var fieldName = !string.IsNullOrEmpty(mbp?.Name) ? mbp.Name : (namingConvention != null ? namingConvention.GetCorrected(field.Name) : field.Name); if (fieldName == name) { return(new PropertyOrField(field, mbp)); } } return(new PropertyOrField()); }
private static string GetCorrectedMemberName([CanBeNull] ScriptableObjectPropertyAttribute sopa, [CanBeNull] INamingConvention naming, [NotNull] string fallback) { return(!string.IsNullOrEmpty(sopa?.Name) ? sopa.Name : (naming != null ? naming.GetCorrected(fallback) : fallback)); }
private PropOrField FindByName([NotNull] Type objectType, [NotNull, ItemNotNull] IReadOnlyList <PropertyInfo> properties, [NotNull, ItemNotNull] IReadOnlyList <FieldInfo> fields, string name, INamingConvention namingConvention) { PropOrField result; foreach (var prop in properties) { var mbp = prop.GetCustomAttribute <MonoBehaviourPropertyAttribute>(); var propName = !string.IsNullOrEmpty(mbp?.Name) ? mbp.Name : (namingConvention != null ? namingConvention.GetCorrected(prop.Name) : prop.Name); if (propName == name) { var key = new SimpleValueTuple <Type, string, MonoBehaviourPropertyAttribute>(objectType, propName, mbp); if (_createdSetters.ContainsKey(key)) { result = _createdSetters[key]; } else { result = new PropOrField(prop, mbp); _createdSetters[key] = result; } return(result); } } foreach (var field in fields) { var mbp = field.GetCustomAttribute <MonoBehaviourPropertyAttribute>(); var fieldName = !string.IsNullOrEmpty(mbp?.Name) ? mbp.Name : (namingConvention != null ? namingConvention.GetCorrected(field.Name) : field.Name); if (fieldName == name) { var key = new SimpleValueTuple <Type, string, MonoBehaviourPropertyAttribute>(objectType, fieldName, mbp); if (_createdSetters.ContainsKey(key)) { result = _createdSetters[key]; } else { result = new PropOrField(field, mbp); _createdSetters[key] = result; } return(result); } } return(PropOrField.Null); }