src/GenFx/GeneticComponentExtensions.cs
/// <summary>
/// Creates a new version of the component, copies the configuration state, and initializes it.
/// </summary>
/// <param name="component">The component from which to create a new component and the source of the configuration state to be copied.</param>
/// <returns>A new version of the component.</returns>
Creates a new version of the component, copies the configuration state, and initializes it.
Creates a new version of the component copies the configuration state and initializes it .
public static GeneticComponent CreateNewAndInitialize(this GeneticComponent component)
        {
            if (component == null)
            {
                throw new ArgumentNullException(nameof(component));
            }
            GeneticComponent newComponent = component.CreateNew();
            if (newComponent == null)
            {
                throw new InvalidOperationException(
                    StringUtil.GetFormattedString(Resources.ErrorMsg_CreateNewComponentNull, component.GetType(), nameof(component.CreateNew)));
            }
            if (newComponent.GetType() != component.GetType())
            {
                throw new InvalidOperationException(
                    StringUtil.GetFormattedString(Resources.ErrorMsg_CreateNewComponentWrongType, component.GetType(), nameof(component.CreateNew), newComponent.GetType()));
            }
            component.CopyConfigurationStateTo(newComponent);
            if (newComponent is GeneticComponentWithAlgorithm newComponentWithAlg)
            {
                ((GeneticComponentWithAlgorithm)component).AssertIsInitialized();
                newComponentWithAlg.Initialize(((GeneticComponentWithAlgorithm)component).Algorithm!);
            }
            return newComponent;
        }
public static GeneticComponent CreateNewAndInitialize ( this GeneticComponent component ) { if ( component == null ) { throw new ArgumentNullException ( nameof ( component ) ) ; } GeneticComponent newComponent = component . CreateNew ( ) ; if ( newComponent == null ) { throw new InvalidOperationException ( StringUtil . GetFormattedString ( Resources . ErrorMsg_CreateNewComponentNull , component . GetType ( ) , nameof ( component . CreateNew ) ) ) ; } if ( newComponent . GetType ( ) != component . GetType ( ) ) { throw new InvalidOperationException ( StringUtil . GetFormattedString ( Resources . ErrorMsg_CreateNewComponentWrongType , component . GetType ( ) , nameof ( component . CreateNew ) , newComponent . GetType ( ) ) ) ; } component . CopyConfigurationStateTo ( newComponent ) ; if ( newComponent is GeneticComponentWithAlgorithm newComponentWithAlg ) { ( ( GeneticComponentWithAlgorithm ) component ) . AssertIsInitialized ( ) ; newComponentWithAlg . Initialize ( ( ( GeneticComponentWithAlgorithm ) component ) . Algorithm ! ) ; } return newComponent ; }
Creates a new version of the component, copies the configuration state, and initializes it.
Creates a new version of the component copies the configuration state and initializes it .
A new version of the component.
A new version of the component .
GeneticComponent
this
component
The component from which to create a new component and the source of the configuration state to be copied.
The component from which to create a new component and the source of the configuration state to be copied .