本文整理汇总了C#中LitJson.JsonData.Has方法的典型用法代码示例。如果您正苦于以下问题:C# JsonData.Has方法的具体用法?C# JsonData.Has怎么用?C# JsonData.Has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LitJson.JsonData
的用法示例。
在下文中一共展示了JsonData.Has方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParseModInfo
/// <summary>
/// Parses the mod's information from Json, loading any required references, and returns its <see cref="ModInfo"/> object.
/// </summary>
/// <param name="j">Json Data to load the <see cref="ModInfo"/> from</param>
/// <param name="path">The path to the mod</param>
/// <returns>The <see cref="ModInfo"/> of the mod</returns>
public static ModInfo ParseModInfo(JsonData j, string path)
{
var refs = new List<IReference>();
if (j.Has("dllReferences"))
foreach (object s in j["dllReferences"])
refs.Add(new AssemblyReference(s.ToString(), path));
if (j.Has("modReferences"))
foreach (object s in j["modReferences"])
refs.Add(new ModReference(s.ToString()));
string internalName = j.GetOrExn<string>("internalName");
return new ModInfo(
path,
internalName,
j.GetOrDef("displayName", internalName),
j.GetOrDef("author", "<unspecified>"),
j.GetOrDef("version", "0.0.0.0"),
j.GetOrDef<string>("description"),
j.GetOrExn<string>("asmFileName"),
j.GetOrExn<string>("modDefTypeName"),
refs.ToArray()
);
}
示例2: BuildSource
static void BuildSource(string sourcePath, string outputPath, JsonData modInfo, CompileException cex, Dictionary<string, string> dictNames)
{
string[] modPathSplit = sourcePath.Split('\\', '/');
string modName = modPathSplit[modPathSplit.Length - 1].Split('.')[0];
if (modInfo.Has("MSBuild"))
if ((bool)modInfo["MSBuild"])
{
// done by msbuild anyway
ModsCompile.BuildSource(sourcePath, outputPath, modInfo, cex, dictNames);
return;
}
bool generatePDB = false;
if (modInfo.Has("includePDB"))
generatePDB = (bool)modInfo["includePDB"];
// but this has to change - other CodeDomProviders (default stays C#)
CodeDomProvider cdp = new CSharpCodeProvider();
foreach (string fileName in Directory.EnumerateFiles(sourcePath, "*.json", SearchOption.AllDirectories))
{
string fname = fileName.Substring(sourcePath.Length + 1).Replace('\\', '/');
if (fname == "ModInfo.json")
continue;
try
{
JsonData json2 = JsonMapper.ToObject(File.ReadAllText(fileName));
if (fname.ToLower().StartsWith("item/"))
ValidateJson.Item(modName, fileName, json2, cex);
if (fname.ToLower().StartsWith("npc/"))
ValidateJson.NPC(modName, fileName, json2, cex);
if (fname.ToLower().StartsWith("projectile/"))
ValidateJson.Projectile(modName, fileName, json2, cex);
//TODO: check all the JSON files other than ModInfo.json for required fields
}
catch (Exception e)
{
cex.AddProblem(fileName, "Invalid JSON file.\n" + e.Message);
}
}
CompilerParameters cp = new CompilerParameters();
cp.GenerateExecutable = false;
cp.ReferencedAssemblies.Add(Assembly.GetExecutingAssembly().Location);
cp.IncludeDebugInformation = generatePDB;
cp.ReferencedAssemblies.Add("mscorlib.dll");
cp.ReferencedAssemblies.Add("System.dll");
cp.ReferencedAssemblies.Add("System.Core.dll");
cp.ReferencedAssemblies.Add("System.Numerics.dll");
cp.ReferencedAssemblies.Add("System.Xml.dll");
cp.ReferencedAssemblies.Add("System.Drawing.dll");
cp.ReferencedAssemblies.Add("System.Windows.Forms.dll");
cp.ReferencedAssemblies.Add("Microsoft.Xna.Framework.dll");
cp.ReferencedAssemblies.Add("Microsoft.Xna.Framework.Xact.dll");
cp.ReferencedAssemblies.Add("Microsoft.Xna.Framework.Game.dll");
cp.ReferencedAssemblies.Add("Microsoft.Xna.Framework.Graphics.dll");
if (modInfo != null)
{
if (modInfo.Has("language"))
switch (((string)modInfo["language"]).ToLowerInvariant())
{
case "js":
case "js.net":
case "jscript":
case "jscript.net":
case "javascript":
case "javascript.net":
cdp = new JScriptCodeProvider();
break;
case "vb":
case "vb.net":
case "visualbasic":
case "visualbasic.net":
case "visual basic":
case "visual basic.net":
cdp = new VBCodeProvider();
break;
}
if (modInfo.Has("modReferences"))
{
if (Directory.Exists(Mods.pathDirMods + "/.Temp"))
Directory.Delete(Mods.pathDirMods + "/.Temp", true);
Directory.CreateDirectory(Mods.pathDirMods + "/.Temp");
JsonData jRefs = (JsonData)modInfo["modReferences"];
for (int i = 0; i < jRefs.Count; i++)
{
string jRef = (string)jRefs[i];
if (!dictNames.ContainsKey(jRef))
continue;
string modfile = dictNames[jRef];
//.........这里部分代码省略.........