forked from fajiao/OnvifServer-CSharp
fajiao
3 years ago
13 changed files with 206 additions and 53 deletions
@ -1,14 +1,14 @@ |
|||||
using Microsoft.Extensions.Configuration; |
using Microsoft.Extensions.Configuration; |
||||
using System.IO; |
using System.IO; |
||||
|
|
||||
namespace EC.Helper.FileExt |
namespace EC.Helper.Common |
||||
{ |
{ |
||||
public class JsonHelper |
public class ConfigHelper |
||||
{ |
{ |
||||
public static IConfiguration ReadConfiguration(string configPath) |
public static IConfiguration ReadConfiguration(string configPath) |
||||
{ |
{ |
||||
ConfigurationBuilder builder = new(); |
ConfigurationBuilder builder = new(); |
||||
if (!File.Exists(configPath)) { return builder.Build(); } |
if (!File.Exists(configPath)) { return null; } |
||||
builder.AddJsonFile(configPath); |
builder.AddJsonFile(configPath); |
||||
return builder.Build(); |
return builder.Build(); |
||||
} |
} |
@ -0,0 +1,12 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Text; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace EC.Helper.Common |
||||
|
{ |
||||
|
public class FileHelper |
||||
|
{ |
||||
|
} |
||||
|
} |
@ -0,0 +1,73 @@ |
|||||
|
using Newtonsoft.Json; |
||||
|
using Newtonsoft.Json.Linq; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace EC.Helper.Common |
||||
|
{ |
||||
|
public class JsonHelper |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Object To Json
|
||||
|
/// </summary>
|
||||
|
/// <param name="obj"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public static string ToJson(object obj) |
||||
|
{ |
||||
|
return JsonConvert.SerializeObject(obj); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Json To Object
|
||||
|
/// </summary>
|
||||
|
/// <param name="json"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public static object ToObject(string json) |
||||
|
{ |
||||
|
return !string.IsNullOrEmpty(json) ? JsonConvert.DeserializeObject(json) : default; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Json To T Object
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="T"></typeparam>
|
||||
|
/// <param name="json"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public static T ToObject<T>(string json) where T : class |
||||
|
{ |
||||
|
return !string.IsNullOrEmpty(json) ? JsonConvert.DeserializeObject<T>(json) : default; |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Json To JObject
|
||||
|
/// </summary>
|
||||
|
/// <param name="json"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public static JObject ToJObject(string json) |
||||
|
{ |
||||
|
return ToObject<JObject>(json); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Json To Object List
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="T"></typeparam>
|
||||
|
/// <param name="json"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public static List<T> ToList<T>(string json) where T : class |
||||
|
{ |
||||
|
return ToObject<List<T>>(json); |
||||
|
} |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// 深克隆
|
||||
|
/// </summary>
|
||||
|
/// <typeparam name="T"></typeparam>
|
||||
|
/// <param name="obj"></param>
|
||||
|
/// <returns></returns>
|
||||
|
public static T DeepClone<T>(T obj) where T : class |
||||
|
{ |
||||
|
string json = ToJson(obj); |
||||
|
return ToObject<T>(json); |
||||
|
} |
||||
|
} |
||||
|
} |
@ -1,6 +1,6 @@ |
|||||
{ |
{ |
||||
"Apis": { |
"Apis": { |
||||
"onvif_http_url": "http://localhost:6000", |
"onvif_http_url": "http://192.168.1.119:10011", |
||||
"onvif_https_url": "https://localhost:6001" |
"onvif_https_url": "https://localhost:6001" |
||||
} |
} |
||||
} |
} |
@ -0,0 +1,12 @@ |
|||||
|
{ |
||||
|
"version": 1, |
||||
|
"isRoot": true, |
||||
|
"tools": { |
||||
|
"dotnet-ef": { |
||||
|
"version": "6.0.2", |
||||
|
"commands": [ |
||||
|
"dotnet-ef" |
||||
|
] |
||||
|
} |
||||
|
} |
||||
|
} |
Loading…
Reference in new issue