Skip to content

How to port code in legacy nuget package to this package TypeConversion. #4

Open
@zydjohnHotmail

Description

@zydjohnHotmail

Hello:
I want to port an old C# class library to target .NET 5.0 for Windows 10.
The old class library used TypeConvert nuget version 2.1.6, but when I install this nuget package, I got warning for the TypeConvert nuget package is legacy. As I don’t want to use the legacy package, but I don’t quite understand how to use other nuget package or use C# built-in library like:
Convert.ChangeType Method from System.Runtime.dll.
Let me know if I can use this package TypeConversion (version 3.0.1) to replace TypeConvert package version 2.1.6 to replace the following C# code.

	internal static T? GetNullable<T>(string? id)
		where T : JsObject
	{
		if (id == null) { return null; }

		var (constructor, @ref) = 
			objRefs.GetOrAdd(id, _ => throw new ObjectDisposedException(id));
		
		if ([email protected](out var obj))
		{
			obj = constructor(id);
			@ref.SetTarget(obj);
		}

		return (T) TypeConvert.Convert
		(
			value: obj,
			toType: typeof(T)
		);
	}

Thanks,

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions