Exemplo n.º 1
0
        private Dictionary <string, PropertyValueBuilder> GetPropertyDefaults <T>(params Action <Defaulter <T> >[] defaulterActions)
        {
            var newPropertyDefaults = new Dictionary <string, PropertyValueBuilder>();

            foreach (var defaulterAction in defaulterActions)
            {
                var defaulter = new Defaulter <T>();
                defaulter.OnPropertyNameSet = propertyName =>
                {
                    newPropertyDefaults[propertyName] = EmptyPropertyValueBuilder.Instance;
                };
                defaulter.OnPropertyValueSet = (propertyName, propertyValue) =>
                {
                    newPropertyDefaults[propertyName] = new SingleValuePropertyValueBuilder(propertyValue);
                };
                defaulter.OnPropertyValueSetToAuto = (propertyName, propertyValueType) =>
                {
                    ThrowExceptionIfNotReferenceType(propertyValueType, propertyName);
                    newPropertyDefaults[propertyName] = new AutoBuildPropertyValueBuilder(propertyValueType, GetInstance);
                };
                defaulterAction(defaulter);
            }
            ;

            ThrowExceptionIfAnyInvalidProperties(typeof(T), newPropertyDefaults, isDefaultOverride: true);

            return(newPropertyDefaults);
        }
Exemplo n.º 2
0
 public DefaultValue(string propertyName,
                     Action <string, object> onPropertyValueSetCallback,
                     Action <string, Type> onPropertyValueSetToAutoBuildCallback,
                     Defaulter <T> parent)
 {
     _propertyName = propertyName;
     _onPropertyValueSetCallback            = onPropertyValueSetCallback;
     _onPropertyValueSetToAutoBuildCallback = onPropertyValueSetToAutoBuildCallback;
     _parent = parent;
 }