在下面展示的方式调用一个.Net对象(cfdump如下所示)...
如果我删除最后一个createobject()调用,则前两个将完美运行。即使在所有createobject()调用中包括所有DLL的路径,我仍然会得到相同的错误。
<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的路径,我仍然会得到相同的错误。
createobject
调用中使用。 - Leigh