本文整理汇总了C#中System.Collections.Hashtable.Cast方法的典型用法代码示例。如果您正苦于以下问题:C# Hashtable.Cast方法的具体用法?C# Hashtable.Cast怎么用?C# Hashtable.Cast使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.Hashtable
的用法示例。
在下文中一共展示了Hashtable.Cast方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Cast_CastsParametersWithDotNotation
public void Cast_CastsParametersWithDotNotation()
{
var parameters = new Hashtable { { "Octopus.Machine.Name", "some machine name" } };
var sut = parameters.Cast<DotNotationParameter>();
Assert.Equal("some machine name", sut.OctopusMachineName);
}
示例2: Download
private string Download(string uri, Hashtable vars)
{
// 1. format query string
if (vars != null)
{
var query = vars.Cast<DictionaryEntry>().Aggregate("", (current, d) => current + ("&" + d.Key.ToString() + "=" + d.Value.ToString()));
if (query.Length > 0)
{
uri = uri + "?" + query.Substring(1);
}
}
// 2. setup basic authenication
var authstring = Convert.ToBase64String(
Encoding.ASCII.GetBytes(String.Format("{0}:{1}",
_id, _token)));
// 3. perform GET using WebClient
var client = new WebClient();
client.Headers.Add("Authorization",
String.Format("Basic {0}", authstring));
var resp = client.DownloadData(uri);
return Encoding.ASCII.GetString(resp);
}
示例3: Cast_ConvertsDecimalParamCorrectly
public void Cast_ConvertsDecimalParamCorrectly()
{
var parameters = new Hashtable {{"NetFramework", "4.5"}};
var sut = parameters.Cast<SingleDecimalParameter>();
Assert.Equal(4.5M, sut.NetFramework);
}
示例4: Cast_DoesNotThrowWhenNotRequiredParamNotGiven
public void Cast_DoesNotThrowWhenNotRequiredParamNotGiven()
{
var parameters = new Hashtable {{"SiteName", "MySite"}};
var sut = parameters.Cast<RequiredParameters>();
Assert.Equal("MySite", sut.SiteName);
}
示例5: Cast_ConvertsShortParamCorrectly
public void Cast_ConvertsShortParamCorrectly()
{
var parameters = new Hashtable {{"Port", "80"}};
var sut = parameters.Cast<SingleShortParameter>();
Assert.Equal(80, sut.Port);
}
示例6: HashtableToDict
public static Dictionary<string, object> HashtableToDict(Hashtable hashtable)
{
if (hashtable == null)
{
return new Dictionary<string, object>();
}
return hashtable.Cast<DictionaryEntry>().ToDictionary(
kvp => (string) kvp.Key.ToString(), kvp => (object) kvp.Value
);
}
示例7: CreateWebhook
public Model.Webhook CreateWebhook(
string resourceGroupName,
string automationAccountName,
string name,
string runbookName,
bool isEnabled,
DateTimeOffset expiryTime,
Hashtable runbookParameters)
{
Requires.Argument("ResourceGroupName", resourceGroupName).NotNull();
Requires.Argument("AutomationAccountName", automationAccountName).NotNull();
using (var request = new RequestSettings(this.automationManagementClient))
{
var rbAssociationProperty = new RunbookAssociationProperty { Name = runbookName };
var createOrUpdateProperties = new WebhookCreateOrUpdateProperties
{
IsEnabled = isEnabled,
ExpiryTime = expiryTime,
Runbook = rbAssociationProperty,
Uri =
this.automationManagementClient
.Webhooks.GenerateUri(
resourceGroupName,
automationAccountName).Uri
};
if (runbookParameters != null)
{
createOrUpdateProperties.Parameters =
runbookParameters.Cast<DictionaryEntry>()
.ToDictionary(kvp => (string)kvp.Key, kvp => (string)kvp.Value);
}
var webhookCreateOrUpdateParameters = new WebhookCreateOrUpdateParameters(
name,
createOrUpdateProperties);
var webhook =
this.automationManagementClient.Webhooks.CreateOrUpdate(
resourceGroupName,
automationAccountName,
webhookCreateOrUpdateParameters).Webhook;
return new Model.Webhook(
resourceGroupName,
automationAccountName,
webhook,
webhookCreateOrUpdateParameters.Properties.Uri);
}
}
示例8: Upload
private string Upload(string uri, string method, Hashtable vars)
{
// 1. format body data
var data = "";
if (vars != null)
{
data = vars.Cast<DictionaryEntry>().Aggregate(data, (current, d) => current + (d.Key.ToString() + "=" + d.Value.ToString() + "&"));
}
// 2. setup basic authenication
var authstring = Convert.ToBase64String(Encoding.ASCII.GetBytes(String.Format("{0}:{1}", _id, _token)));
// 3. perform POST/PUT/DELETE using WebClient
ServicePointManager.Expect100Continue = false;
var postbytes = Encoding.ASCII.GetBytes(data);
var client = new WebClient();
client.Headers.Add("Authorization", String.Format("Basic {0}", authstring));
client.Headers.Add("Content-Type", "application/x-www-form-urlencoded");
var resp = client.UploadData(uri, method, postbytes);
return Encoding.ASCII.GetString(resp);
}
示例9: Cast_GivesParametersWhenSuppliedUsingCorrectCasing
public void Cast_GivesParametersWhenSuppliedUsingCorrectCasing()
{
var parameters = new Hashtable {{"SiteName", "MySite"}};
var sut = parameters.Cast<InstallerContextTests.SingleStringParameter>();
Assert.Equal("MySite", sut.SiteName);
}
示例10: SetTemplateMetadata
public static void SetTemplateMetadata(ProvisioningTemplate template, string templateDisplayName, string templateImagePreviewUrl, Hashtable templateProperties)
{
if (!String.IsNullOrEmpty(templateDisplayName))
{
template.DisplayName = templateDisplayName;
}
if (!String.IsNullOrEmpty(templateImagePreviewUrl))
{
template.ImagePreviewUrl = templateImagePreviewUrl;
}
if (templateProperties != null && templateProperties.Count > 0)
{
var properties = templateProperties
.Cast<DictionaryEntry>()
.ToDictionary(i => (String)i.Key, i => (String)i.Value);
foreach (var key in properties.Keys)
{
if (!String.IsNullOrEmpty(key))
{
template.Properties[key] = properties[key];
}
}
}
}
示例11: ConvertComplexSearchObjectToSQL
/// <summary>
/// VHSoft: Add function to handle complex searching; converting the json object from jqgrid to workable sql where string
/// </summary>
private void ConvertComplexSearchObjectToSQL(Hashtable searchObject, ref string where, ref string additionalSQL)
{
Dictionary<string, object> value2 = searchObject.Cast<DictionaryEntry> ().ToDictionary(kvp => (string)kvp.Key, kvp => (object)kvp.Value);
this.ConvertComplexSearchObjectToSQL(value2, ref where, ref additionalSQL);
}
示例12: Cast_OnlySetsWritableProperties
public void Cast_OnlySetsWritableProperties()
{
var parameters = new Hashtable { { "Port", 80 } };
var sut = parameters.Cast<ReadonlyParameter>();
Assert.Equal(90, sut.Port);
}
示例13: Cast_IgnoresExtraNotRequiredParameters
public void Cast_IgnoresExtraNotRequiredParameters()
{
var parameters = new Hashtable {{"SiteName", "MySite"}, {"ApplicationPoolName", "AppPool1"}};
var sut = parameters.Cast<InstallerContextTests.SingleStringParameter>();
Assert.Equal("MySite", sut.SiteName);
}
示例14: GeraProjetoInterface
private static void GeraProjetoInterface(ParametrosCriarProjetos parametros, string guidProjInterface, List<string> arquivosInterface, string templateAssembly)
{
var trocasInterface = new Hashtable
{
{"[guid]", guidProjInterface},
{"[namespace]", parametros.NameSpace},
{"[arquivos]", string.Join("\n", arquivosInterface.ToArray())}
};
var projInterface = Gerador.RetornaTextoBase("secafretnIetalpmeT");
projInterface = trocasInterface.Cast<DictionaryEntry>().Aggregate(projInterface, (current, entry) => current.Replace(entry.Key.ToString(), entry.Value.ToString()));
projInterface = projInterface.Replace("[versao]", parametros.VersaoFramework);
var assemblyInterface = templateAssembly.Replace("[log]", "");
assemblyInterface = assemblyInterface.Replace("[namespace]", parametros.NameSpace);
assemblyInterface = assemblyInterface.Replace("[guid]", guidProjInterface);
File.WriteAllText(string.Format("{0}\\Interfaces\\{1}Interfaces.csproj", parametros.CaminhoDestino, parametros.NameSpace), projInterface);
File.WriteAllText(string.Format("{0}\\Interfaces\\Properties\\AssemblyInfo.cs", parametros.CaminhoDestino), assemblyInterface);
}
示例15: GeraSoluction
private static void GeraSoluction(ParametrosCriarProjetos parametros, string guidProjTO, string guidProjDAL, string guidProjInterface, string guidProjBLL, string guidProjWcf)
{
var trocasSolution = new Hashtable
{
{"[guid]", Guid.NewGuid().ToString().ToUpper().ToUpper()},
{"[namespace]", parametros.NameSpace},
{"[guidTO]", guidProjTO},
{"[guidDAL]", guidProjDAL},
{"[guidInterface]", guidProjInterface},
{"[guidBLL]", guidProjBLL}
};
var projSolution = Gerador.RetornaTextoBase("noituloS");
if (parametros.MapWcf)
{
projSolution = projSolution.Replace("[guidWcf]", string.Format("Project(\"{{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}}\") = \"{0}Wcf\", \"{0}Wcf\\{0}Wcf.csproj\", \"{{53034ACE-081D-4CDA-8075-D3B158C7DAF9}}\"{1}EndProject", parametros.NameSpace, Environment.NewLine));
projSolution = projSolution.Replace("[guidGlobalWcf]", string.Format("{{{0}}}.Debug|Any CPU.ActiveCfg = Debug|Any CPU{1}{{{0}}}.Debug|Any CPU.Build.0 = Debug|Any CPU{1}{{{0}}}.Release|Any CPU.ActiveCfg = Release|Any CPU{1}{{{0}}}.Release|Any CPU.Build.0 = Release|Any CPU", guidProjWcf, Environment.NewLine));
}
else
{
projSolution = projSolution.Replace("[guidWcf]", "");
projSolution = projSolution.Replace("[guidGlobalWcf]", "");
}
switch (parametros.VersaoFramework)
{
case "v2.0":
projSolution = projSolution.Replace("2010", "2008");
projSolution = projSolution.Replace("11.00", "10.00");
break;
case "v4.5":
projSolution = projSolution.Replace("2010", "2012");
projSolution = projSolution.Replace("11.00", "12.00");
break;
}
projSolution = trocasSolution.Cast<DictionaryEntry>().Aggregate(projSolution, (current, entry) => current.Replace(entry.Key.ToString(), entry.Value.ToString()));
File.WriteAllText(string.Format("{0}\\{1}.sln", parametros.CaminhoDestino, parametros.NameSpace), projSolution);
}