Exemplo n.º 1
0
 /// <summary>
 /// Creates an instance of <see cref="CollectionSetting{T}"/>.
 /// </summary>
 /// <param name="selector">The targeted value. If this doesn't have a setter it will still work.</param>
 /// <param name="names">The names to use for this setting. Must supply at least one name. The first name will be designated the main name.</param>
 /// <param name="parser">The converter to convert from a string to the value. Can be null if a primitive type or enum.</param>
 public CollectionSetting(
     Expression <Func <ICollection <TValue> > > selector,
     IEnumerable <string> names       = default,
     TryParseDelegate <TValue> parser = default)
     : base(SettingParsingUtils.DistinctNames(selector.GetMemberExpression().Member.Name, names), parser)
 {
     _Getter           = selector?.Compile() ?? throw new ArgumentException(nameof(selector));
     ResetValueFactory = x => { x.Clear(); return(x); }; //Clear the list when reset by default
     HasBeenSet        = true;                           //Set to prevent it from stopping things
 }
 /// <summary>
 /// Creates an instance of <see cref="StaticSetting{TSource, TValue}"/> with full setter and getter capabilities targeting the supplied value.
 /// </summary>
 /// <param name="selector">The targeted value. This can be any property/field local/instance/global/static in a class. It NEEDS to have both a getter and setter.</param>
 /// <param name="names">The names to use for this setting. Must supply at least one name. The first name will be designated the main name.</param>
 /// <param name="parser">The converter to convert from a string to the value. Can be null if a primitive type or enum.</param>
 public StaticSetting(Expression <Func <TSource, TValue> > selector, IEnumerable <string> names = default, TryParseDelegate <TValue> parser = default)
     : base(SettingParsingUtils.DistinctNames(selector.GetMemberExpression().Member.Name, names), parser)
 {
     _Getter = selector.Compile();
     _Setter = selector.GenerateSetter();
 }
Exemplo n.º 3
0
 /// <summary>
 /// Creates an instance of <see cref="Setting{T}"/> with full setter and getter capabilities targeting the supplied value.
 /// </summary>
 /// <param name="reference">The targeted value. This can be any property/field local/instance/global/static in a class.</param>
 /// <param name="names">The names to use for this setting. Must supply at least one name. The first name will be designated the main name.</param>
 /// <param name="parser">The converter to convert from a string to the value. Can be null if a primitive type or enum.</param>
 public Setting(IRef <TValue> reference, IEnumerable <string> names = default, TryParseDelegate <TValue> parser = default)
     : base(SettingParsingUtils.DistinctNames(reference.Name, names), parser)
 {
     _Ref = reference ?? throw new ArgumentException(nameof(reference));
 }