Add these three (indented) lines to your csproj file
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
true
using Newtonsoft.Json; | |
namespace myproject | |
{ | |
public interface ICanJson | |
{ | |
// marker | |
} | |
public static class JsonExtensions |
using Newtonsoft.Json.Linq; | |
using System.Text; | |
namespace ConsoleApp1; | |
public class JsonApp | |
{ | |
private string json = @"{ | |
'Customer': { | |
'FirstName': 'Amy', |
// A nice way to find out if a string contains any value in a string list | |
using System.Linq; | |
public static bool ContainsAny(string s, List<string> substrings) | |
{ | |
if (string.IsNullOrEmpty(s) || substrings == null) | |
return false; | |
return substrings.Any(substring => s.Contains(substring, StringComparison.CurrentCultureIgnoreCase)); |
Add these three (indented) lines to your csproj file
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
true
# nullable disable | |
using Microsoft.Extensions.DependencyInjection; | |
using Microsoft.Extensions.Hosting; | |
using Microsoft.Extensions.Logging; | |
var host = CreateHostBuilder(args).Build(); | |
Application app = host.Services.GetRequiredService<Application>(); | |
static IHostBuilder CreateHostBuilder(string[] args) |
{ | |
"latitude": 45.51, | |
"longitude": -122.68, | |
"timezone": "America/Los_Angeles", | |
"currently": { | |
"time": 1590159600, | |
"summary": "Showers.", | |
"icon": "rain", | |
"precipIntensity": 0.02, | |
"precipProbability": 0.49, |
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace DateTimeExtensionTest | |
{ | |
public static class DateTimeExtensions | |
{ |
List<long> firstList = new List<long>() {100,102,106,109,110,118,124,125,127,129,130,131,133,137,139,147,149,150,151,152,155,158,159,160,161,163,164,165,166,167,168,170,171,172,173,175,179,181,182,191,198,199,206,214,215,225,237,240,241,242,245,601,602,603,605,606,607,608,609,610,613,614,615,616,617,618,619,620,621,921,925,939,940,947,948,949,950,951,952,953,954,955,959,961,962,963,973,974,1001,1004,1005,6250,6255,6256,6259,6261,6262,6264,6274,6302,6307,6348,6353,6355,6358,6366,6368,6371,6382,6389,6390,6392,6395,6397,6399,6407,6411,6412,6413,6415,6417,6420,6422,6431,6435,6438,6443,6447,6457,6458,6464,6480,6493,6501,6502,6503,6505,6511,6513,6514,6528,6529,6534,6535,6547,6548,6550,6558,6560,6561,6562,6563,6565,6566,6572,6573,6575,6576,6596,6621,6622,6623,6624,6639,6640,6642,6649,6650,6651,6652,6656,6674,6675,6676,6724,6725,6726,6727,6730,6731,6732,7622,8707,9518}; | |
List<long> secondList = new List<long>() {101,102,104,105,106,107,108,109,110,112,113,114,115,116,117,118,119,121,122,123,124,125,126,127,128,129,130 |
string xmlContent = File.ReadAllText(@"c:\test\mismo.xml"); | |
XmlDocument doc = new XmlDocument(); | |
doc.LoadXml(xmlContent); | |
string json = JsonConvert.SerializeXmlNode(doc); | |
RootObject message = JsonConvert.DeserializeObject<RootObject>(json); |
public class ModelHelper<TSource, TDestination> where TSource : class | |
where TDestination : class | |
{ | |
public static void Map(TSource source, TDestination destination) | |
{ | |
var sourceProperties = source.GetType().GetProperties(); | |
var destinationProperties = destination.GetType().GetProperties(); | |
var destinationName = source.GetType().Name; | |
foreach (var sourceProperty in sourceProperties) |