C# return dynamic/anonymous type value as function result

zyip發表於2014-04-03

 

 

 

 

 

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;

 

 

 

 

 

 

 

相關文章