This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public List<JToken> FindTokens(JToken containerToken, string name) | |
{ | |
List<JToken> matches = new List<JToken>(); | |
FindTokens(containerToken, name, matches); | |
return matches; | |
} | |
private void FindTokens(JToken containerToken, string name, List<JToken> matches) | |
{ | |
if (containerToken.Type == JTokenType.Array) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(?<=^|,)(\"(?:[^\"]|\"\")*\"|[^,]*) | |
/* | |
May be usefull to: | |
1997,Ford,E350,"ac, abs, moon",30100.00 | |
1999,Chevy,"Venture ""Extended Edition""",,49000.00 | |
1996,Jeep,Grand Cherokee,"MUST SELL! | |
air, moon roof, loaded",479699.00 | |
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public bool DoWork(BrokeredMessage message) | |
{ | |
if (message == null) | |
throw new ArgumentNullException(nameof(message)); | |
try | |
{ | |
if (!_isInitialized) | |
Initialize(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void RenameToken(JToken token, string newName) | |
{ | |
var parent = token.Parent; | |
if (parent == null) | |
throw new InvalidOperationException("The parent is missing."); | |
var newToken = new JProperty(newName, token); | |
parent.Replace(newToken); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static string ToDescription<T>(this T source) | |
{ | |
FieldInfo fi = source.GetType().GetField(source.ToString()); | |
DescriptionAttribute[] attributes = (DescriptionAttribute[])fi.GetCustomAttributes(typeof(DescriptionAttribute), false); | |
// | |
return attributes.Length > 0 ? attributes[0].Description : source.ToString(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Web.Mvc; | |
namespace Core.Extensions | |
{ | |
public static class MarkerAttributeExtension | |
{ | |
public static bool HasMarkerAttribute<T>(this AuthorizationContext that) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static object GetPropValue(object obj, string name) | |
{ | |
foreach (var part in name.Split('.')) | |
{ | |
if (obj == null) { return null; } | |
Type type = obj.GetType(); | |
PropertyInfo info = type.GetProperty(part); | |
if (info == null) { return null; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static IEnumerable<byte[]> ReadChunks(string source) | |
{ | |
using (Stream stream = IsUrl(source) ? WebRequest.Create(source).GetResponse().GetResponseStream() : new FileStream(source, FileMode.Open, FileAccess.Read, FileShare.Read)) | |
{ | |
const int sampleSize = 300; | |
var fileSize = GetFileSize(source); | |
if (fileSize > sampleSize) | |
fileSize = sampleSize; | |
var buffer = new byte[fileSize]; | |
if (stream == null) |
NewerOlder