C# return dynamic/anonymous type value as function result

时间:2021-12-10 21:49:23

function:

   public static dynamic GetAppSecret()
{
//string[] result = new string[] { "", "" };
dynamic result = new System.Dynamic.ExpandoObject(); result = new { appid="appid", appSecret = "appSecret" }; return result;
}

if you want to use the dynamic result function in a difference assembly, you should add following code to assemblyInfo.cs

[assembly: InternalsVisibleTo("WeChatSchools")]

invoke:

var secret = Helper.GetAppSecret();
app.t_appid = secret.appid;
app.t_appkey = secret.appSecret;