DynamicUtils
using Microsoft.CSharp.RuntimeBinder;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Linq.Expressions;
using System.Runtime.CompilerServices;
namespace Newtonsoft.Json.Utilities
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
internal static class DynamicUtils
{
[System.Runtime.CompilerServices.Nullable(0)]
internal static class BinderWrapper
{
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Newtonsoft.Json relies on reflection over types that may be removed when trimming.")]
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Newtonsoft.Json relies on dynamically creating types that may not be available with Ahead of Time compilation.")]
public static CallSiteBinder GetMember(string name, Type context)
{
return Binder.GetMember(CSharpBinderFlags.None, name, context, new CSharpArgumentInfo[1] {
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.None, null)
});
}
[System.Diagnostics.CodeAnalysis.RequiresUnreferencedCode("Newtonsoft.Json relies on reflection over types that may be removed when trimming.")]
[System.Diagnostics.CodeAnalysis.RequiresDynamicCode("Newtonsoft.Json relies on dynamically creating types that may not be available with Ahead of Time compilation.")]
public static CallSiteBinder SetMember(string name, Type context)
{
return Binder.SetMember(CSharpBinderFlags.None, name, context, new CSharpArgumentInfo[2] {
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.UseCompileTimeType, null),
CSharpArgumentInfo.Create(CSharpArgumentInfoFlags.Constant, null)
});
}
}
public static IEnumerable<string> GetDynamicMemberNames(this IDynamicMetaObjectProvider dynamicProvider)
{
return dynamicProvider.GetMetaObject(Expression.Constant(dynamicProvider)).GetDynamicMemberNames();
}
}
}