本文整理汇总了C#中Deserializer类的典型用法代码示例。如果您正苦于以下问题:C# Deserializer类的具体用法?C# Deserializer怎么用?C# Deserializer使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Deserializer类属于命名空间,在下文中一共展示了Deserializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInstance
public static UniversityPortalConfig GetInstance (int portalId)
{
var lazyPortalConfig = portalConfigs.GetOrAdd (portalId, newKey =>
new Lazy<UniversityPortalConfig> (() => {
var portalSettings = new PortalSettings (portalId);
var portalConfigFile = Path.Combine (portalSettings.HomeDirectoryMapPath, "R7.University.yml");
// ensure portal config file exists
if (!File.Exists (portalConfigFile)) {
File.Copy (Path.Combine (
Globals.ApplicationMapPath,
"DesktopModules\\R7.University\\R7.University\\R7.University.yml"),
portalConfigFile);
}
using (var configReader = new StringReader (File.ReadAllText (portalConfigFile))) {
var deserializer = new Deserializer (namingConvention: new HyphenatedNamingConvention ());
return deserializer.Deserialize<UniversityPortalConfig> (configReader);
}
}
));
return lazyPortalConfig.Value;
}
示例2: Start
// Use this for initialization
void Start () {
var input = new StringReader(Document);
var deserializer = new Deserializer();
var reader = new EventReader(new Parser(input));
// Consume the stream start event "manually"
reader.Expect<StreamStart>();
var output = new StringBuilder();
while(reader.Accept<DocumentStart>())
{
// Deserialize the document
var doc = deserializer.Deserialize<List<string>>(reader);
output.AppendLine("## Document");
foreach(var item in doc)
{
output.AppendLine(item);
}
}
Debug.Log(output);
}
示例3: Main
static void Main(string[] args)
{
var sourceList = new Item[10000];
for (int i = 0; i < sourceList.Length; i++)
{
sourceList[i] = new Item { IntValue = i, StringValue = i.ToString() };
}
var mySerializer = new YamlSerializer();
var myDeserializer = new YamlDeserializer();
var defaultSerializer = new Serializer();
var defaultDeserializer = new Deserializer();
var watch = new Stopwatch();
while (true)
{
var sw = new StringWriter();
watch.Restart();
mySerializer.Serialize(sw, sourceList);
var stime = watch.ElapsedMilliseconds;
watch.Restart();
var list = myDeserializer.Deserialize<List<Item>>(new StringReader(sw.ToString()));
var dtime = watch.ElapsedMilliseconds;
Console.WriteLine("My - Serialize time: {0}ms, Deserialize time: {1}ms", stime, dtime);
sw = new StringWriter();
watch.Restart();
defaultSerializer.Serialize(sw, sourceList);
stime = watch.ElapsedMilliseconds;
watch.Restart();
list = defaultDeserializer.Deserialize<List<Item>>(new StringReader(sw.ToString()));
dtime = watch.ElapsedMilliseconds;
Console.WriteLine("Default - Serialize time: {0}ms, Deserialize time: {1}ms", stime, dtime);
}
}
示例4: Load
public static void Load(string filename)
{
var buffer = File.ReadAllText(filename);
var deserializer = new Deserializer();
var config = deserializer.Deserialize<Config>(new StringReader(buffer));
}
示例5: LoadFiles
public static void LoadFiles(AddFunc addFunc)
{
TextAsset dirTxt = Resources.Load<TextAsset>(HFT_WEB_DIR);
if (dirTxt == null)
{
Debug.LogError("could not load: " + HFT_WEB_DIR);
return;
}
Deserializer deserializer = new Deserializer();
string[] files = deserializer.Deserialize<string[] >(dirTxt.text);
foreach (string file in files)
{
string path = HFT_WEB_PATH + file;
TextAsset asset = Resources.Load(path) as TextAsset;
if (asset == null)
{
Debug.LogError("Could not load: " + path);
}
else
{
addFunc(file, asset.bytes);
}
}
}
示例6: Notify
public static void Notify(StringReader reader)
{
var deserializer = new Deserializer(null, new NullNamingConvention(), ignoreUnmatched: true);
var legacyConfig = deserializer.Deserialize<LegacyConfig>(reader);
if (legacyConfig == null)
return;
var issues = new List<string>();
var oldConfigs = legacyConfig.Branches.Keys.Where(k => OldConfigKnownRegexes.Keys.Contains(k) && k != OldConfigKnownRegexes[k]).ToList();
if (oldConfigs.Any())
{
var max = oldConfigs.Max(c => c.Length);
var oldBranchConfigs = oldConfigs.Select(c => string.Format("{0} -> {1}", c.PadRight(max), OldConfigKnownRegexes[c]));
var branchErrors = string.Join("\r\n ", oldBranchConfigs);
issues.Add(string.Format(
@"GitVersion branch configs no longer are keyed by regexes, update:
{0}", branchErrors));
}
if (legacyConfig.assemblyVersioningScheme != null)
issues.Add("assemblyVersioningScheme has been replaced by assembly-versioning-scheme");
if (legacyConfig.DevelopBranchTag != null)
issues.Add("develop-branch-tag has been replaced by branch specific configuration. See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration");
if (legacyConfig.ReleaseBranchTag != null)
issues.Add("release-branch-tag has been replaced by branch specific configuration. See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration");
if (legacyConfig.Branches != null && legacyConfig.Branches.Any(branches => branches.Value.IsDevelop != null))
issues.Add("'is-develop' is deprecated, use 'tracks-release-branches' instead. See http://gitversion.readthedocs.org/en/latest/configuration/#branch-configuration");
if (issues.Any())
throw new OldConfigurationException("GitVersion configuration file contains old configuration, please fix the following errors:\r\n" + string.Join("\r\n", issues));
}
示例7: Load
//private static Configuration ConfigOnDisk;
public static LoadResult Load(string fileName)
{
if (!File.Exists(fileName))
{
Logger.Log(null, "Config file not found. Creating a new one...", LogLevel.Info);
try
{
var exampleConfigStream =
Assembly.GetExecutingAssembly().GetManifestResourceStream("BaggyBot.src.EmbeddedData.Configuration.example-config.yaml");
exampleConfigStream.CopyTo(File.Create(fileName));
}
catch (Exception e) when (e is FileNotFoundException || e is FileLoadException || e is IOException)
{
Logger.Log(null, "Unable to load the default config file.", LogLevel.Error);
Logger.Log(null, "Default config file not created. You might have to create one yourself.", LogLevel.Warning);
return LoadResult.Failure;
}
return LoadResult.NewFileCreated;
}
var deserialiser = new Deserializer(namingConvention: new HyphenatedNamingConvention(), ignoreUnmatched: false);
using (var reader = File.OpenText(fileName))
{
Config = deserialiser.Deserialize<Configuration>(reader);
}
/*using (var reader = File.OpenText(fileName))
{
ConfigOnDisk = deserialiser.Deserialize<Configuration>(reader);
}*/
return LoadResult.Success;
}
示例8: Initialize
private void Initialize()
{
if (!JustInitialized) return;
_serializer = new Serializer<SimpleJsonWriter>(_primaryType);
_deserializer = new Deserializer<SimpleJsonReader>(_primaryType);
JustInitialized = false;
}
示例9: FromYaml
/// <summary>
/// Loads an article from a .yml file.
/// </summary>
static Article FromYaml(string path)
{
// Get the file path from the given URL path
var filename = "articles/" + path + ".yml";
if (!File.Exists(filename))
throw new FileNotFoundException(filename);
// Load the article with a YamlDotNet deserializer
var articleFile = File.OpenRead(filename);
var deserializer = new Deserializer();
var article = deserializer.Deserialize<Article>(new StreamReader(articleFile));
// Set some default values if they are not specified in the file
if (article.Slug == null)
article.Slug = path;
if (article.Summary == null)
{
var firstLine = article.Content.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.RemoveEmptyEntries)[0];
article.Summary = firstLine;
}
// Convert the Markdown content to HTML
var markdownConverter = new Markdown();
article.Content = markdownConverter.Transform(article.Content);
article.Summary = Utils.StripHtmlTags(markdownConverter.Transform(article.Summary));
return article;
}
示例10: Generate_All
public void Generate_All()
{
Clean();
EnsurePathsExist();
var files = GetAllYamlFiles();
var deser = new Deserializer();
foreach( var file in files )
{
//if( !file.Contains("random", StringComparison.OrdinalIgnoreCase) )
// continue;//just deal with random for now.
Console.WriteLine("READING: " + file);
var sr = new StringReader(File.ReadAllText(file));
var yamlTest = deser.Deserialize<YamlTest>(sr);
var mutator = new CSharpTestMutator(yamlTest);
mutator.MutateTests();
var outputFile =
Path.Combine(OutputDir,
Path.GetFileName(
Path.ChangeExtension(file, ".cs")));
Console.WriteLine("OUTPUT: " + outputFile);
var template = new TestTemplate() {YamlTest = yamlTest};
File.WriteAllText(outputFile, template.TransformText());
}
}
示例11: LoadFromFile
public static AgentConfig LoadFromFile(string file)
{
AgentConfig ac;
using (StreamReader sr = File.OpenText(file))
{
Deserializer ds = new Deserializer(namingConvention: new CamelCaseNamingConvention());
ac = ds.Deserialize<AgentConfig>(sr);
}
CheckAgentConfigForNull(ac);
ac = InitializeAgentConfigLists(ac);
ac = SetDefaultTaskValues(ac);
if (ac._checks != null)
ac = LoadSerializedCheck(ac);
if (ac._info != null)
ac = LoadSerializedInfo(ac);
if (ac._actions != null)
ac = LoadSerializedActions(ac);
return ac;
}
示例12: TestInit
public void TestInit()
{
_fixture = new Fixture();
_jsonSerializer = new Mock<IJsonSerializer>(MockBehavior.Strict);
_jsonDeserializer = new Mock<IJsonSerializer>(MockBehavior.Strict);
_deserializer = new Deserializer<SampleSource>(_jsonSerializer.Object, _jsonDeserializer.Object);
}
示例13: Awake
// Use this for initialization
void Awake()
{
//Read in archetype file
Reader = new StringReader(Resources.Load<TextAsset>("creatures").text);
NPCReader = new StringReader(Resources.Load<TextAsset>("npcDefinitions").text);
CamelCaseDeserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention());
DialogNPCs = new List<NpcData>();
}
示例14: Config
static Config()
{
using (var reader = new StreamReader(File.OpenRead("config.yml")))
{
var deserializer = new Deserializer(namingConvention: new CamelCaseNamingConvention());
Instance = deserializer.Deserialize<Config>(reader);
}
}
示例15: LoadFromFile
public static NemesisConfig LoadFromFile(string file)
{
using (var sr = File.OpenText(file))
{
var ds = new Deserializer(namingConvention: new CamelCaseNamingConvention());
return ds.Deserialize<NemesisConfig>(sr);
}
}