RandomExtensionsNextObject(Random, Type, GenerateObjectSettings) Method

Returns a random object of the specified type or if type cannot be instantiated with the provided settings.

Definition

Namespace: KGySoft.CoreLibraries
Assembly: KGySoft.CoreLibraries (in KGySoft.CoreLibraries.dll) Version: 7.0.0-rc.1
C#
public static Object? NextObject(
	this Random random,
	Type type,
	GenerateObjectSettings? settings = null
)

Parameters

random  Random
The Random instance to use.
type  Type
The type of the object to be created. If TryResolveInterfacesAndAbstractTypes property in settings is , then it can be also an interface or abstract type; however, if no implementation or usable constructor found, then a value will be returned.
settings  GenerateObjectSettings  (Optional)
The settings to use or to use the default settings.
Default value: .

Return Value

Object
An instance of type or if the type cannot be instantiated with the provided settings See the Remarks section of the NextObjectT(Random, GenerateObjectSettings) overload for details.

Usage Note

In Visual Basic and C#, you can call this method as an instance method on any object of type Random. When you use instance method syntax to call this method, omit the first parameter. For more information, see Extension Methods (Visual Basic) or Extension Methods (C# Programming Guide).

Exceptions

ArgumentNullExceptionrandom or type is .

See Also