调用了一个 .Net 对象,如下所示(cfdump 如下所示)......
<cfobject type=".NET" name="GoCardless" class="GoCardlessSdk.GoCardless" assembly="#expandpath("../GoCardlessSdk.dll")#,#expandpath("../Newtonsoft.Json.dll")#,#expandpath("../RestSharp.dll")#">
我现在需要设置一个枚举。用于此的示例 .Net 代码将是:
GoCardless.Environment = GoCardless.Environments.Sandbox;
该类的 C# 代码如下所示:
using System;
using System.Collections.Generic;
using System.Reflection;
using GoCardlessSdk.Api;
using GoCardlessSdk.Connect;
using GoCardlessSdk.Helpers;
using GoCardlessSdk.Partners;
namespace GoCardlessSdk
{
public static class GoCardless
{
static GoCardless()
{
AccountDetails = new AccountDetails();
}
public enum Environments
{
Production,
Sandbox,
Test
}
public static readonly Dictionary<Environments, string> BaseUrls =
new Dictionary<Environments, string>
{
{Environments.Production, "https://gocardless.com"},
{Environments.Sandbox, "https://sandbox.gocardless.com"},
{Environments.Test, "http://gocardless.com"}
};
private static string _baseUrl;
public static string BaseUrl
{
get { return _baseUrl ?? BaseUrls[Environment ?? Environments.Production]; }
set { _baseUrl = value.Trim(); }
}
public static Environments? Environment { get; set; }
public static AccountDetails AccountDetails { get; set; }
public static ApiClient Api
{
get { return new ApiClient(AccountDetails.Token); }
}
public static ConnectClient Connect
{
get { return new ConnectClient(); }
}
public static PartnerClient Partner
{
get { return new PartnerClient(); }
}
internal static string UserAgent = GetUserAgent();
private static string GetUserAgent()
{
try
{
return "gocardless-dotnet/v" + GetAssemblyFileVersion();
}
catch
{
return "gocardless-dotnet";
}
}
private static string GetAssemblyFileVersion()
{
Assembly assembly = Assembly.GetAssembly(typeof (GoCardless));
var attributes = assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), false)
as AssemblyFileVersionAttribute[];
if (attributes != null && attributes.Length == 1)
{
return attributes[0].Version;
}
return "";
}
private static Func<string> _generateNonce;
internal static Func<string> GenerateNonce
{
get { return _generateNonce ?? (_generateNonce = Utils.GenerateNonce); }
set { _generateNonce = value; }
}
private static Func<DateTimeOffset> _getUtcNow;
internal static Func<DateTimeOffset> GetUtcNow
{
get { return _getUtcNow ?? (_getUtcNow = () => DateTimeOffset.UtcNow); }
set { _getUtcNow = value; }
}
}
}
有人可以向我解释如何在 ColdFusion 中设置枚举吗?
谢谢!
更新
为了响应 Leigh 的实用程序类解决方案,我的代码如下:
<cfscript>
GoCardless = createObject(".net", "GoCardlessSdk.GoCardless","path to GoCardless DLL,paths to supporting DLLs");
Environments = createObject(".net", "GoCardlessSdk.GoCardless$Environments", "path to GoCardless DLL");
util = createObject(".net", "GoCardlessSdk.GoCardlessSdkUtil", "path to utility DLL");
dumps etc...
</cfscript>
如果我删除最后一个 createobject() 调用前两个运行得很好。即使我在所有createobject() 调用中包含所有DLL的路径,我仍然会遇到相同的错误。