Here are the examples of the csharp api System.Array.Copy(System.Array, System.Array, int) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
1718 Examples
19
Source : MinHeap.cs
with MIT License
from 39M
with MIT License
from 39M
public void Insert(T element) {
#if VALIDATE
validateHeapInternal("Insert");
#endif
//if the array isn't big enough, expand it
if (_array.Length == _count) {
T[] newArray = new T[_array.Length * 2];
Array.Copy(_array, newArray, _array.Length);
_array = newArray;
}
element.heapIndex = _count;
_count++;
bubbleUp(element);
}
19
Source : BasicList.cs
with MIT License
from 404Lcc
with MIT License
from 404Lcc
public Node Append(object value)
{
object[] newData;
int newLength = length + 1;
if (data == null)
{
newData = new object[10];
}
else if (length == data.Length)
{
newData = new object[data.Length * 2];
Array.Copy(data, newData, length);
} else
{
newData = data;
}
newData[length] = value;
return new Node(newData, newLength);
}
19
Source : BasicList.cs
with MIT License
from 404Lcc
with MIT License
from 404Lcc
public Node Trim()
{
if (length == 0 || length == data.Length) return this;
object[] newData = new object[length];
Array.Copy(data, newData, length);
return new Node(newData, length);
}
19
Source : RaceLibrary.cs
with Apache License 2.0
from A7ocin
with Apache License 2.0
from A7ocin
override public void AddRace(RaceData race)
{
if (race == null) return;
ValidateDictionary();
for (int i = 0; i < raceElementList.Length; i++)
{
if (raceElementList[i].raceName == race.raceName)
{
raceElementList[i] = race;
return;
}
}
var list = new RaceData[raceElementList.Length + 1];
Array.Copy(raceElementList, list, raceElementList.Length );
list[raceElementList.Length] = race;
raceElementList = list;
raceDictionary.Add(race.raceName, race);
}
19
Source : OverlayColorData.cs
with Apache License 2.0
from A7ocin
with Apache License 2.0
from A7ocin
public void EnsureChannels(int channels)
{
if (channelMask == null)
{
channelMask = new Color[channels];
channelAdditiveMask = new Color[channels];
for (int i = 0; i < channels; i++)
{
channelMask[i] = Color.white;
channelAdditiveMask[i] = new Color(0, 0, 0, 0);
}
}
else
{
if (channelMask.Length < channels)
{
var newMask = new Color[channels];
System.Array.Copy(channelMask, newMask, channelMask.Length);
for (int i = channelMask.Length; i < channels; i++)
{
newMask[i] = Color.white;
}
channelMask = newMask;
}
if (channelAdditiveMask.Length < channels)
{
var newAdditiveMask = new Color[channels];
System.Array.Copy(channelAdditiveMask, newAdditiveMask, channelAdditiveMask.Length);
for (int i = channelAdditiveMask.Length; i < channels; i++)
{
newAdditiveMask[i] = new Color(0,0,0,0);
}
channelAdditiveMask = newAdditiveMask;
}
}
}
19
Source : PerformanceAppender.cs
with MIT License
from Abc-Arbitrage
with MIT License
from Abc-Arbitrage
public void WriteEvent(ILogEventHeader logEventHeader, byte[] messageBytes, int messageLength)
{
Array.Copy(messageBytes, _messages[_count].StartTimestampInChars, messageLength);
_messages[_count].MessageLength = messageLength;
_messages[_count].EndTimestamp = Stopwatch.GetTimestamp();
_count++;
}
19
Source : FdbMemoizedTuple.cs
with MIT License
from abdullin
with MIT License
from abdullin
public object[] ToArray()
{
var obj = new object[m_items.Length];
Array.Copy(m_items, obj, obj.Length);
return obj;
}
19
Source : ArticulatedHandPose.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from abist-co-ltd
public void Copy(ArticulatedHandPose other)
{
Array.Copy(other.localJointPoses, localJointPoses, jointCount);
}
19
Source : MixedRealityLineRenderer.cs
with Apache License 2.0
from abist-co-ltd
with Apache License 2.0
from abist-co-ltd
private IEnumerator FadeLine(float targetAlphaPercentage, float animationLength)
{
float currentTime = 0f;
if (cachedKeys == null)
{
cachedKeys = LineColor.alphaKeys;
}
GradientAlphaKey[] fadedKeys = new GradientAlphaKey[cachedKeys.Length];
Array.Copy(cachedKeys, fadedKeys, cachedKeys.Length);
float startAlpha = 1f;
while (currentTime != animationLength)
{
currentTime += Time.deltaTime;
if (currentTime > animationLength)
{
currentTime = animationLength;
}
float percentageComplete = currentTime / animationLength;
float scalar = Mathf.Lerp(startAlpha, targetAlphaPercentage, percentageComplete);
for (int i = 0; i < fadedKeys.Length; i++)
{
fadedKeys[i].alpha = cachedKeys[i].alpha * scalar;
}
LineColor.alphaKeys = fadedKeys;
yield return null;
}
fadeLine = null;
}
19
Source : AudioDeviceHandler.cs
with MIT License
from ABTSoftware
with MIT License
from ABTSoftware
private void ProcessData()
{
while (!_token.IsCancellationRequested)
{
if (_processEvt.WaitOne(100))
{
lock (_input)
{
Array.Copy(_input, _inputBack, _input.Length);
}
DataReceived?.Invoke(this, EventArgs.Empty);
}
}
}
19
Source : SpectrogramDemoView.xaml.cs
with MIT License
from ABTSoftware
with MIT License
from ABTSoftware
private void UpdateSpectrogramHeatmapSeries(XyDataSeries<double,double> series)
{
// Compute the new spectrogram frame
for (int x = 99; x >= 0; x--)
for (int y = 0; y < 1024; y++)
_spectrogramBuffer[x, y] = (x == 99) ? series.YValues[y] : _pastFrame[x + 1, y];
// Preserve the past frame, as current spectrogram is computed based on last + Xy fft values
Array.Copy(_spectrogramBuffer, _pastFrame, _spectrogramBuffer.Length);
// Forces Heatmap to redraw after updating values
_uniformHeatmapDataSeries.InvalidateParentSurface(RangeMode.None);
}
19
Source : ArrayExtensions.cs
with GNU General Public License v3.0
from Acumatica
with GNU General Public License v3.0
from Acumatica
public static T[] RemoveAt<T>(this T[] array, int position, int length)
{
if (position + length > array.Length)
{
length = array.Length - position;
}
T[] newArray = new T[array.Length - length];
if (position > 0)
{
Array.Copy(array, newArray, position);
}
if (position < newArray.Length)
{
Array.Copy(array, position + length, newArray, position, newArray.Length - position);
}
return newArray;
}
19
Source : ArrayExtensions.cs
with GNU General Public License v3.0
from Acumatica
with GNU General Public License v3.0
from Acumatica
public static T[] InsertAt<T>(this T[] array, int position, T item)
{
T[] newArray = new T[array.Length + 1];
if (position > 0)
{
Array.Copy(array, newArray, position);
}
if (position < array.Length)
{
Array.Copy(array, position, newArray, position + 1, array.Length - position);
}
newArray[position] = item;
return newArray;
}
19
Source : ArrayExtensions.cs
with GNU General Public License v3.0
from Acumatica
with GNU General Public License v3.0
from Acumatica
public static T[] ReplaceAt<T>(this T[] array, int position, T item)
{
T[] newArray = new T[array.Length];
Array.Copy(array, newArray, array.Length);
newArray[position] = item;
return newArray;
}
19
Source : ArrayExtensions.cs
with GNU General Public License v3.0
from Acumatica
with GNU General Public License v3.0
from Acumatica
public static T[] InsertAt<T>(this T[] array, int position, T[] items)
{
T[] newArray = new T[array.Length + items.Length];
if (position > 0)
{
Array.Copy(array, newArray, position);
}
if (position < array.Length)
{
Array.Copy(array, position, newArray, position + items.Length, array.Length - position);
}
items.CopyTo(newArray, position);
return newArray;
}
19
Source : RegistryValue.cs
with MIT License
from ADeltaX
with MIT License
from ADeltaX
public byte[] GetData()
{
if (_cell.DataLength < 0)
{
int len = _cell.DataLength & 0x7FFFFFFF;
byte[] buffer = new byte[4];
EndianUtilities.WriteBytesLittleEndian(_cell.DataIndex, buffer, 0);
byte[] result = new byte[len];
Array.Copy(buffer, result, len);
return result;
}
return _hive.RawCellData(_cell.DataIndex, _cell.DataLength);
}
19
Source : TerrainMap.cs
with MIT License
from Adsito
with MIT License
from Adsito
public void Pop()
{
if (src == dst) return;
Array.Copy(dst, src, src.Length);
dst = src;
}
19
Source : BytePacker.cs
with Apache License 2.0
from advancer68
with Apache License 2.0
from advancer68
public byte[] Pack(byte[] content)
{
pkgLengthBytes = BitConverter.GetBytes(content.Length);
pkgLengthByteSize = pkgLengthBytes.Length;
var buf = new byte[content.Length + pkgLengthByteSize];
int offset = 0;
Array.Copy(pkgLengthBytes, buf, pkgLengthBytes.Length);
offset += pkgLengthBytes.Length;
Array.Copy(content, 0, buf, offset, content.Length);
return buf;
}
19
Source : kcpUtil.cs
with Apache License 2.0
from advancer68
with Apache License 2.0
from advancer68
public static T[] copyAll<T>(this T[] self)
{
var it = new T[self.Length];
Array.Copy(self, it, self.Length);
return it;
}
19
Source : ByteBuf.cs
with Apache License 2.0
from advancer68
with Apache License 2.0
from advancer68
public void Recapacity(int newCapacity)
{
byte[] old = data;
data = new byte[newCapacity];
Array.Copy(old, data, old.Length);
}
19
Source : EntityStateReadBuffers.cs
with The Unlicense
from aeroson
with The Unlicense
from aeroson
internal void Enable()
{
//Turn everything on.
lock (FlipLocker)
{
int initialCount = Math.Max(manager.enreplacedies.Count, 64);
backBuffer = new MotionState[initialCount];
frontBuffer = new MotionState[initialCount];
for (int i = 0; i < manager.enreplacedies.Count; i++)
{
Enreplacedy enreplacedy = manager.enreplacedies[i];
backBuffer[i].Position = enreplacedy.position;
backBuffer[i].Orientation = enreplacedy.orientation;
backBuffer[i].LinearVelocity = enreplacedy.linearVelocity;
backBuffer[i].AngularVelocity = enreplacedy.angularVelocity;
}
Array.Copy(backBuffer, frontBuffer, backBuffer.Length);
}
}
19
Source : InterpolatedStatesManager.cs
with The Unlicense
from aeroson
with The Unlicense
from aeroson
internal void Enable()
{
//Turn everything on.
lock (FlipLocker)
{
int initialCount = Math.Max(manager.enreplacedies.Count, 64);
backBuffer = new RigidTransform[initialCount];
states = new RigidTransform[initialCount];
for (int i = 0; i < manager.enreplacedies.Count; i++)
{
Enreplacedy enreplacedy = manager.enreplacedies[i];
backBuffer[i].Position = enreplacedy.position;
backBuffer[i].Orientation = enreplacedy.orientation;
}
Array.Copy(backBuffer, states, backBuffer.Length);
}
}
19
Source : RawList.cs
with The Unlicense
from aeroson
with The Unlicense
from aeroson
public T[] ToArray()
{
var toReturn = new T[Count];
Array.Copy(Elements, toReturn, Count);
return toReturn;
}
19
Source : QuickLZ.cs
with MIT License
from afxw
with MIT License
from afxw
public static byte[] Compress(byte[] source, int level)
{
int src = 0;
int dst = DEFAULT_HEADERLEN + CWORD_LEN;
uint cword_val = 0x80000000;
int cword_ptr = DEFAULT_HEADERLEN;
byte[] destination = new byte[source.Length + 400];
int[,] hashtable;
int[] cachetable = new int[HASH_VALUES];
byte[] hash_counter = new byte[HASH_VALUES];
byte[] d2;
int fetch = 0;
int last_matchstart = (source.Length - UNCONDITIONAL_MATCHLEN - UNCOMPRESSED_END - 1);
int lits = 0;
if (level != 1 && level != 3)
throw new ArgumentException("C# version only supports level 1 and 3");
if (level == 1)
hashtable = new int[HASH_VALUES, QLZ_POINTERS_1];
else
hashtable = new int[HASH_VALUES, QLZ_POINTERS_3];
if (source.Length == 0)
return new byte[0];
if (src <= last_matchstart)
fetch = source[src] | (source[src + 1] << 8) | (source[src + 2] << 16);
while (src <= last_matchstart)
{
if ((cword_val & 1) == 1)
{
if (src > source.Length >> 1 && dst > src - (src >> 5))
{
d2 = new byte[source.Length + DEFAULT_HEADERLEN];
WriteHeader(d2, level, false, source.Length, source.Length + DEFAULT_HEADERLEN);
Array.Copy(source, 0, d2, DEFAULT_HEADERLEN, source.Length);
return d2;
}
FastWrite(destination, cword_ptr, (int)((cword_val >> 1) | 0x80000000), 4);
cword_ptr = dst;
dst += CWORD_LEN;
cword_val = 0x80000000;
}
if (level == 1)
{
int hash = ((fetch >> 12) ^ fetch) & (HASH_VALUES - 1);
int o = hashtable[hash, 0];
int cache = cachetable[hash] ^ fetch;
cachetable[hash] = fetch;
hashtable[hash, 0] = src;
if (cache == 0 && hash_counter[hash] != 0 && (src - o > MINOFFSET || (src == o + 1 && lits >= 3 && src > 3 && source[src] == source[src - 3] && source[src] == source[src - 2] && source[src] == source[src - 1] && source[src] == source[src + 1] && source[src] == source[src + 2])))
{
cword_val = ((cword_val >> 1) | 0x80000000);
if (source[o + 3] != source[src + 3])
{
int f = 3 - 2 | (hash << 4);
destination[dst + 0] = (byte)(f >> 0 * 8);
destination[dst + 1] = (byte)(f >> 1 * 8);
src += 3;
dst += 2;
}
else
{
int old_src = src;
int remaining = ((source.Length - UNCOMPRESSED_END - src + 1 - 1) > 255 ? 255 : (source.Length - UNCOMPRESSED_END - src + 1 - 1));
src += 4;
if (source[o + src - old_src] == source[src])
{
src++;
if (source[o + src - old_src] == source[src])
{
src++;
while (source[o + (src - old_src)] == source[src] && (src - old_src) < remaining)
src++;
}
}
int matchlen = src - old_src;
hash <<= 4;
if (matchlen < 18)
{
int f = (hash | (matchlen - 2));
destination[dst + 0] = (byte)(f >> 0 * 8);
destination[dst + 1] = (byte)(f >> 1 * 8);
dst += 2;
}
else
{
FastWrite(destination, dst, hash | (matchlen << 16), 3);
dst += 3;
}
}
fetch = source[src] | (source[src + 1] << 8) | (source[src + 2] << 16);
lits = 0;
}
else
{
lits++;
hash_counter[hash] = 1;
destination[dst] = source[src];
cword_val = (cword_val >> 1);
src++;
dst++;
fetch = ((fetch >> 8) & 0xffff) | (source[src + 2] << 16);
}
}
else
{
fetch = source[src] | (source[src + 1] << 8) | (source[src + 2] << 16);
int o, offset2;
int matchlen, k, m, best_k = 0;
byte c;
int remaining = ((source.Length - UNCOMPRESSED_END - src + 1 - 1) > 255 ? 255 : (source.Length - UNCOMPRESSED_END - src + 1 - 1));
int hash = ((fetch >> 12) ^ fetch) & (HASH_VALUES - 1);
c = hash_counter[hash];
matchlen = 0;
offset2 = 0;
for (k = 0; k < QLZ_POINTERS_3 && c > k; k++)
{
o = hashtable[hash, k];
if ((byte)fetch == source[o] && (byte)(fetch >> 8) == source[o + 1] && (byte)(fetch >> 16) == source[o + 2] && o < src - MINOFFSET)
{
m = 3;
while (source[o + m] == source[src + m] && m < remaining)
m++;
if ((m > matchlen) || (m == matchlen && o > offset2))
{
offset2 = o;
matchlen = m;
best_k = k;
}
}
}
o = offset2;
hashtable[hash, c & (QLZ_POINTERS_3 - 1)] = src;
c++;
hash_counter[hash] = c;
if (matchlen >= 3 && src - o < 131071)
{
int offset = src - o;
for (int u = 1; u < matchlen; u++)
{
fetch = source[src + u] | (source[src + u + 1] << 8) | (source[src + u + 2] << 16);
hash = ((fetch >> 12) ^ fetch) & (HASH_VALUES - 1);
c = hash_counter[hash]++;
hashtable[hash, c & (QLZ_POINTERS_3 - 1)] = src + u;
}
src += matchlen;
cword_val = ((cword_val >> 1) | 0x80000000);
if (matchlen == 3 && offset <= 63)
{
FastWrite(destination, dst, offset << 2, 1);
dst++;
}
else if (matchlen == 3 && offset <= 16383)
{
FastWrite(destination, dst, (offset << 2) | 1, 2);
dst += 2;
}
else if (matchlen <= 18 && offset <= 1023)
{
FastWrite(destination, dst, ((matchlen - 3) << 2) | (offset << 6) | 2, 2);
dst += 2;
}
else if (matchlen <= 33)
{
FastWrite(destination, dst, ((matchlen - 2) << 2) | (offset << 7) | 3, 3);
dst += 3;
}
else
{
FastWrite(destination, dst, ((matchlen - 3) << 7) | (offset << 15) | 3, 4);
dst += 4;
}
lits = 0;
}
else
{
destination[dst] = source[src];
cword_val = (cword_val >> 1);
src++;
dst++;
}
}
}
while (src <= source.Length - 1)
{
if ((cword_val & 1) == 1)
{
FastWrite(destination, cword_ptr, (int)((cword_val >> 1) | 0x80000000), 4);
cword_ptr = dst;
dst += CWORD_LEN;
cword_val = 0x80000000;
}
destination[dst] = source[src];
src++;
dst++;
cword_val = (cword_val >> 1);
}
while ((cword_val & 1) != 1)
{
cword_val = (cword_val >> 1);
}
FastWrite(destination, cword_ptr, (int)((cword_val >> 1) | 0x80000000), CWORD_LEN);
WriteHeader(destination, level, true, source.Length, dst);
d2 = new byte[dst];
Array.Copy(destination, d2, dst);
return d2;
}
19
Source : PrefabLightmapData.cs
with GNU General Public License v3.0
from affederaffe
with GNU General Public License v3.0
from affederaffe
private void Update()
{
LightmapData[] lightmapData = LightmapSettings.lightmaps;
LightmapData[] combinedLightmaps = new LightmapData[m_Lightmaps!.Length + lightmapData.Length];
Array.Copy(lightmapData, combinedLightmaps, lightmapData.Length);
for (int i = 0; i < m_Lightmaps.Length; i++)
{
combinedLightmaps[lightmapData.Length + i] = new LightmapData
{
lightmapColor = m_Lightmaps[i]
};
}
ApplyRendererInfo(m_Renderers!, m_LightmapOffsetScales!, lightmapData.Length);
LightmapSettings.lightmaps = combinedLightmaps;
}
19
Source : UnityContainerAttributeExtensions.cs
with Apache License 2.0
from agoda-com
with Apache License 2.0
from agoda-com
private static void RegisterForCollection<TLifestyleManager>(RegistrationContext reg)
where TLifestyleManager : LifetimeManager, new()
{
reg.Key = Guid.NewGuid().ToString();
// As well as registering the collection items individually, Unity also requires us to explicitly register
// the IEnumerable<T> to make them injectable as a collection. Do this now if we haven't already done so.
var enumerableInterface = typeof(IEnumerable<>).MakeGenericType(reg.FromType);
if (!_container.IsRegistered(enumerableInterface))
{
_container.RegisterType(enumerableInterface, new TLifestyleManager(), new InjectionFactory(c =>
{
// To keep the runtime happy, we need to return a strongly typed enumerable. The only way I can see
// to do this with the runtime types we have available is by calling Array.CreateInstance with our
// target type and copying into it.
var untypedObjects = _collectionItemsForType[reg.FromType]
.OrderBy(item => item.Order)
.Select(item => c.Resolve(reg.FromType, item.Key))
.ToArray();
var typedObjects = Array.CreateInstance(reg.FromType, untypedObjects.Length);
Array.Copy(untypedObjects, typedObjects, untypedObjects.Length);
return typedObjects;
}));
_collectionItemsForType.Add(reg.FromType, new List<ResolutionItem>());
}
// Ensure Order is unique for collection.
if (reg.Collection.Order != 0)
{
var registeredOrders = _collectionItemsForType[reg.FromType]
.Where(item => item.Order != 0)
.OrderBy(item => item.Order)
.ToList();
if (registeredOrders.Any(item => item.Order == reg.Collection.Order))
{
var msg =
$"{reg.ToType.FullName}: an item has already been registered with {nameof(ContainerRegistrationAttribute.Order)} " +
$"= {reg.Collection.Order} for collection of {reg.FromType.FullName}. A collection's " +
$"{nameof(ContainerRegistrationAttribute.Order)} property must be either unspecified, 0, or otherwise unique. " +
$"The following {nameof(ContainerRegistrationAttribute.Order)}s were previously registered: " +
$"{{ {string.Join(", ", registeredOrders.Select(item => item.Order))} }}.";
throw new RegistrationFailedException(msg);
}
}
// Ensure the lifetime of the new item matches those of the existing.
var lifetimeManager = new TLifestyleManager();
var mismatchedItem = _collectionItemsForType[reg.FromType]
.FirstOrDefault(item => item.LifetimeManager.GetType() != typeof(TLifestyleManager));
if (mismatchedItem != null && mismatchedItem.LifetimeManager != default(TLifestyleManager))
{
var msg = $"{reg.ToType.FullName}: registered with invalid lifetime {lifetimeManager.GetType().Name}. " +
$"All items in a collection must be registered with the same lifetime. Lifetime is fixed once " +
$"the first item is registered, in this case {mismatchedItem.LifetimeManager.GetType().Name}.";
throw new RegistrationFailedException(msg);
}
_collectionItemsForType[reg.FromType].Add(ResolutionItem.Create(reg.Key, reg.Collection.Order, lifetimeManager));
// Now go wash your eyes out.
}
19
Source : DiagnosticResult.cs
with Apache License 2.0
from agoda-com
with Apache License 2.0
from agoda-com
private DiagnosticResult AppendSpan(FileLinePositionSpan span)
{
FileLinePositionSpan[] newSpans;
if (spans != null)
{
newSpans = new FileLinePositionSpan[spans.Length + 1];
Array.Copy(spans, newSpans, spans.Length);
newSpans[spans.Length] = span;
}
else
{
newSpans = new FileLinePositionSpan[1]
{
span
};
}
// clone the object, so that the fluent syntax will work on immutable objects.
return new DiagnosticResult
{
Id = Id,
Message = message,
MessageFormat = MessageFormat,
MessageArguments = MessageArguments,
Severity = Severity,
Spans = newSpans
};
}
19
Source : Crypto.cs
with BSD 3-Clause "New" or "Revised" License
from airzero24
with BSD 3-Clause "New" or "Revised" License
from airzero24
public static string Decrypt(string encrypted)
{
byte[] input = Convert.FromBase64String(encrypted);
int uuidLength = Config.PayloadUUID.Length;
// Input is uuid:iv:ciphertext:hmac, IV is 16 bytes
byte[] uuidInput = new byte[uuidLength];
Array.Copy(input, uuidInput, uuidLength);
byte[] IV = new byte[16];
Array.Copy(input, uuidLength, IV, 0, 16);
byte[] ciphertext = new byte[input.Length - uuidLength - 16 - 32];
Array.Copy(input, uuidLength + 16, ciphertext, 0, ciphertext.Length);
HMACSHA256 sha256 = new HMACSHA256(Convert.FromBase64String(Config.Psk));
byte[] hmac = new byte[32];
Array.Copy(input, uuidLength + 16 + ciphertext.Length, hmac, 0, 32);
if (Convert.ToBase64String(hmac) == Convert.ToBase64String(sha256.ComputeHash(IV.Concat(ciphertext).ToArray())))
{
using (Aes aes = Aes.Create())
{
// Use our PSK (generated in Apfell payload config) as the AES key
aes.Key = Convert.FromBase64String(Config.Psk);
aes.Padding = PaddingMode.PKCS7;
ICryptoTransform decryptor = aes.CreateDecryptor(aes.Key, IV);
using (MemoryStream decryptMemStream = new MemoryStream(ciphertext))
using (CryptoStream decryptCryptoStream = new CryptoStream(decryptMemStream, decryptor, CryptoStreamMode.Read))
using (StreamReader decryptStreamReader = new StreamReader(decryptCryptoStream))
{
string decrypted = decryptStreamReader.ReadToEnd();
// Return decrypted message from Apfell server
return Encoding.UTF8.GetString(uuidInput) + decrypted;
}
}
}
else
{
return "";
}
}
19
Source : StringOperation.cs
with MIT License
from AiursoftWeb
with MIT License
from AiursoftWeb
public static byte[] ToUTF8WithDom(this string content)
{
byte[] encoded = Encoding.UTF8.GetBytes(content);
var bom = new byte[] { 0xEF, 0xBB, 0xBF };
var all = new byte[bom.Length + encoded.Length];
Array.Copy(bom, all, bom.Length);
Array.Copy(encoded, 0, all, bom.Length, encoded.Length);
return all;
}
19
Source : CombineLatest.cs
with Apache License 2.0
from akarnokd
with Apache License 2.0
from akarnokd
void Drain()
{
if (Interlocked.Increment(ref wip) != 1)
{
return;
}
var missed = 1;
var downstream = this.downstream;
var queue = this.queue;
var observers = this.observers;
var n = observers.Length;
var values = this.values;
var hasLatest = this.hasLatest;
for (; ; )
{
for (; ;)
{
if (Volatile.Read(ref disposed))
{
while (queue.TryDequeue(out var _)) ;
for (int i = 0; i < n; i++)
{
values[i] = default(T);
}
break;
}
if (!delayErrors)
{
var ex = Volatile.Read(ref error);
if (ex != null)
{
downstream.OnError(ex);
Volatile.Write(ref disposed, true);
DisposeAll();
continue;
}
}
var d = Volatile.Read(ref done) == n;
var empty = !queue.TryDequeue(out var v);
if (d && empty)
{
var ex = Volatile.Read(ref error);
if (ex != null)
{
downstream.OnError(ex);
}
else
{
downstream.OnCompleted();
}
Volatile.Write(ref disposed, true);
DisposeAll();
continue;
}
if (empty)
{
break;
}
var idx = v.index;
if (!hasLatest[idx])
{
hasLatest[idx] = true;
available++;
}
values[idx] = v.value;
if (available == n)
{
var result = default(R);
try
{
var a = new T[n];
Array.Copy(values, a, n);
result = mapper(a);
}
catch (Exception ex)
{
if (delayErrors)
{
ExceptionHelper.AddException(ref error, ex);
ex = ExceptionHelper.Terminate(ref error);
downstream.OnError(ex);
Volatile.Write(ref disposed, true);
DisposeAll();
}
else
{
if (Interlocked.CompareExchange(ref error, ex, null) == null)
{
downstream.OnError(ex);
Volatile.Write(ref disposed, true);
DisposeAll();
}
}
continue;
}
downstream.OnNext(result);
}
}
missed = Interlocked.Add(ref wip, -missed);
if (missed == 0)
{
break;
}
}
}
19
Source : DataTableConverter.cs
with MIT License
from akaskela
with MIT License
from akaskela
private static void CreateRow(JsonReader reader, DataTable dt, JsonSerializer serializer)
{
DataRow dr = dt.NewRow();
reader.ReadAndreplacedert();
while (reader.TokenType == JsonToken.PropertyName)
{
string columnName = (string)reader.Value;
reader.ReadAndreplacedert();
DataColumn column = dt.Columns[columnName];
if (column == null)
{
Type columnType = GetColumnDataType(reader);
column = new DataColumn(columnName, columnType);
dt.Columns.Add(column);
}
if (column.DataType == typeof(DataTable))
{
if (reader.TokenType == JsonToken.StartArray)
{
reader.ReadAndreplacedert();
}
DataTable nestedDt = new DataTable();
while (reader.TokenType != JsonToken.EndArray)
{
CreateRow(reader, nestedDt, serializer);
reader.ReadAndreplacedert();
}
dr[columnName] = nestedDt;
}
else if (column.DataType.IsArray && column.DataType != typeof(byte[]))
{
if (reader.TokenType == JsonToken.StartArray)
{
reader.ReadAndreplacedert();
}
List<object> o = new List<object>();
while (reader.TokenType != JsonToken.EndArray)
{
o.Add(reader.Value);
reader.ReadAndreplacedert();
}
Array destinationArray = Array.CreateInstance(column.DataType.GetElementType(), o.Count);
Array.Copy(o.ToArray(), destinationArray, o.Count);
dr[columnName] = destinationArray;
}
else
{
dr[columnName] = (reader.Value != null) ? serializer.Deserialize(reader, column.DataType) : DBNull.Value;
}
reader.ReadAndreplacedert();
}
dr.EndEdit();
dt.Rows.Add(dr);
}
19
Source : JavaScriptUtils.cs
with MIT License
from akaskela
with MIT License
from akaskela
public static void WriteEscapedJavaScriptString(TextWriter writer, string s, char delimiter, bool appendDelimiters,
bool[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, IArrayPool<char> bufferPool, ref char[] writeBuffer)
{
// leading delimiter
if (appendDelimiters)
{
writer.Write(delimiter);
}
if (s != null)
{
int lastWritePosition = 0;
for (int i = 0; i < s.Length; i++)
{
var c = s[i];
if (c < charEscapeFlags.Length && !charEscapeFlags[c])
{
continue;
}
string escapedValue;
switch (c)
{
case '\t':
escapedValue = @"\t";
break;
case '\n':
escapedValue = @"\n";
break;
case '\r':
escapedValue = @"\r";
break;
case '\f':
escapedValue = @"\f";
break;
case '\b':
escapedValue = @"\b";
break;
case '\\':
escapedValue = @"\\";
break;
case '\u0085': // Next Line
escapedValue = @"\u0085";
break;
case '\u2028': // Line Separator
escapedValue = @"\u2028";
break;
case '\u2029': // Paragraph Separator
escapedValue = @"\u2029";
break;
default:
if (c < charEscapeFlags.Length || stringEscapeHandling == StringEscapeHandling.EscapeNonAscii)
{
if (c == '\'' && stringEscapeHandling != StringEscapeHandling.EscapeHtml)
{
escapedValue = @"\'";
}
else if (c == '"' && stringEscapeHandling != StringEscapeHandling.EscapeHtml)
{
escapedValue = @"\""";
}
else
{
if (writeBuffer == null || writeBuffer.Length < UnicodeTextLength)
{
writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, UnicodeTextLength, writeBuffer);
}
StringUtils.ToCharAsUnicode(c, writeBuffer);
// slightly hacky but it saves multiple conditions in if test
escapedValue = EscapedUnicodeText;
}
}
else
{
escapedValue = null;
}
break;
}
if (escapedValue == null)
{
continue;
}
bool isEscapedUnicodeText = string.Equals(escapedValue, EscapedUnicodeText);
if (i > lastWritePosition)
{
int length = i - lastWritePosition + ((isEscapedUnicodeText) ? UnicodeTextLength : 0);
int start = (isEscapedUnicodeText) ? UnicodeTextLength : 0;
if (writeBuffer == null || writeBuffer.Length < length)
{
char[] newBuffer = BufferUtils.RentBuffer(bufferPool, length);
// the unicode text is already in the buffer
// copy it over when creating new buffer
if (isEscapedUnicodeText)
{
Array.Copy(writeBuffer, newBuffer, UnicodeTextLength);
}
BufferUtils.ReturnBuffer(bufferPool, writeBuffer);
writeBuffer = newBuffer;
}
s.CopyTo(lastWritePosition, writeBuffer, start, length - start);
// write unchanged chars before writing escaped text
writer.Write(writeBuffer, start, length - start);
}
lastWritePosition = i + 1;
if (!isEscapedUnicodeText)
{
writer.Write(escapedValue);
}
else
{
writer.Write(writeBuffer, 0, UnicodeTextLength);
}
}
if (lastWritePosition == 0)
{
// no escaped text, write entire string
writer.Write(s);
}
else
{
int length = s.Length - lastWritePosition;
if (writeBuffer == null || writeBuffer.Length < length)
{
writeBuffer = BufferUtils.EnsureBufferSize(bufferPool, length, writeBuffer);
}
s.CopyTo(lastWritePosition, writeBuffer, 0, length);
// write remaining text
writer.Write(writeBuffer, 0, length);
}
}
// trailing delimiter
if (appendDelimiters)
{
writer.Write(delimiter);
}
}
19
Source : StringBuffer.cs
with MIT License
from akaskela
with MIT License
from akaskela
private void EnsureSize(IArrayPool<char> bufferPool, int appendLength)
{
char[] newBuffer = BufferUtils.RentBuffer(bufferPool, (_position + appendLength) * 2);
if (_buffer != null)
{
Array.Copy(_buffer, newBuffer, _position);
BufferUtils.ReturnBuffer(bufferPool, _buffer);
}
_buffer = newBuffer;
}
19
Source : KrakenX.cs
with GNU General Public License v3.0
from akmadian
with GNU General Public License v3.0
from akmadian
public void ApplyEffect(KrakenXChannel Channel, IEffect Effect, bool ApplyToChannel = true)
{
if (!Effect.IsCompatibleWith(Type)) // If the effect is not compatible with a KrakenX
throw new IncompatibleEffectException("KrakenX", Effect.EffectName);
if (ApplyToChannel)
{
if (Channel.ChannelByte == 0x00)
{
_Both.UpdateEffect(Effect);
_Logo.UpdateEffect(Effect);
_Ring.UpdateEffect(Effect);
}
else if (Channel.ChannelByte == 0x01) Logo.UpdateEffect(Effect);
else if (Channel.ChannelByte == 0x02) Ring.UpdateEffect(Effect);
}
List<byte[]> CommandQueue = Effect.BuildBytes(Type, Channel);
if (CommandQueue == null)
throw new NullReferenceException("CommandQueue for ApplyEffect returned null.");
foreach (byte[] Command in CommandQueue)
{
if (Command.Length <= 0x41)
{
_COMController.Write(Command);
} else
{
byte[] truncCommand = new byte[0x41];
Array.Copy(Command, truncCommand, truncCommand.Length);
_COMController.Write(truncCommand);
}
}
}
19
Source : DynamicTreeBroadPhase.cs
with MIT License
from Alan-FGR
with MIT License
from Alan-FGR
private void BufferMove(int proxyId)
{
if (_moveCount == _moveCapacity)
{
int[] oldBuffer = _moveBuffer;
_moveCapacity *= 2;
_moveBuffer = new int[_moveCapacity];
Array.Copy(oldBuffer, _moveBuffer, _moveCount);
}
_moveBuffer[_moveCount] = proxyId;
++_moveCount;
}
19
Source : DynamicTreeBroadPhase.cs
with MIT License
from Alan-FGR
with MIT License
from Alan-FGR
private bool QueryCallback(int proxyId)
{
// A proxy cannot form a pair with itself.
if (proxyId == _queryProxyId)
{
return true;
}
// Grow the pair buffer as needed.
if (_pairCount == _pairCapacity)
{
Pair[] oldBuffer = _pairBuffer;
_pairCapacity *= 2;
_pairBuffer = new Pair[_pairCapacity];
Array.Copy(oldBuffer, _pairBuffer, _pairCount);
}
_pairBuffer[_pairCount].ProxyIdA = Math.Min(proxyId, _queryProxyId);
_pairBuffer[_pairCount].ProxyIdB = Math.Max(proxyId, _queryProxyId);
++_pairCount;
return true;
}
19
Source : DynamicTree.cs
with MIT License
from Alan-FGR
with MIT License
from Alan-FGR
private int AllocateNode()
{
// Expand the node pool as needed.
if (_freeList == NullNode)
{
Debug.replacedert(_nodeCount == _nodeCapacity);
// The free list is empty. Rebuild a bigger pool.
TreeNode<T>[] oldNodes = _nodes;
_nodeCapacity *= 2;
_nodes = new TreeNode<T>[_nodeCapacity];
Array.Copy(oldNodes, _nodes, _nodeCount);
// Build a linked list for the free list. The parent
// pointer becomes the "next" pointer.
for (int i = _nodeCount; i < _nodeCapacity - 1; ++i)
{
_nodes[i] = new TreeNode<T>();
_nodes[i].ParentOrNext = i + 1;
_nodes[i].Height = -1;
}
_nodes[_nodeCapacity - 1] = new TreeNode<T>();
_nodes[_nodeCapacity - 1].ParentOrNext = NullNode;
_nodes[_nodeCapacity - 1].Height = -1;
_freeList = _nodeCount;
}
// Peel a node off the free list.
int nodeId = _freeList;
_freeList = _nodes[nodeId].ParentOrNext;
_nodes[nodeId].ParentOrNext = NullNode;
_nodes[nodeId].Child1 = NullNode;
_nodes[nodeId].Child2 = NullNode;
_nodes[nodeId].Height = 0;
_nodes[nodeId].UserData = default(T);
++_nodeCount;
return nodeId;
}
19
Source : KDNode.cs
with MIT License
from alen-smajic
with MIT License
from alen-smajic
private void ExtendBounds(double[] tPoint)
{
// If we don't have bounds, create them using the new point then bail.
if (tMinBound == null)
{
tMinBound = new double[iDimensions];
tMaxBound = new double[iDimensions];
Array.Copy(tPoint, tMinBound, iDimensions);
Array.Copy(tPoint, tMaxBound, iDimensions);
return;
}
// For each dimension.
for (int i = 0; i < iDimensions; ++i)
{
if (Double.IsNaN(tPoint[i]))
{
if (!Double.IsNaN(tMinBound[i]) || !Double.IsNaN(tMaxBound[i]))
bSinglePoint = false;
tMinBound[i] = Double.NaN;
tMaxBound[i] = Double.NaN;
}
else if (tMinBound[i] > tPoint[i])
{
tMinBound[i] = tPoint[i];
bSinglePoint = false;
}
else if (tMaxBound[i] < tPoint[i])
{
tMaxBound[i] = tPoint[i];
bSinglePoint = false;
}
}
}
19
Source : IntervalHeap.cs
with MIT License
from alen-smajic
with MIT License
from alen-smajic
public void Insert(double key, T value)
{
// If more room is needed, double the array size.
if (Size >= Capacity)
{
// Double the capacity.
Capacity *= 2;
// Expand the data array.
var newData = new T[Capacity];
Array.Copy(tData, newData, tData.Length);
tData = newData;
// Expand the key array.
var newKeys = new double[Capacity];
Array.Copy(tKeys, newKeys, tKeys.Length);
tKeys = newKeys;
}
// Insert the new value at the end.
Size++;
tData[Size-1] = value;
tKeys[Size-1] = key;
// Ensure it is in the right place.
SiftInsertedValueUp();
}
19
Source : MinHeap.cs
with MIT License
from alen-smajic
with MIT License
from alen-smajic
public void Insert(double key, T value)
{
// If we need more room, double the space.
if (Size >= Capacity)
{
// Calcualte the new capacity.
Capacity *= 2;
// Copy the data array.
var newData = new T[Capacity];
Array.Copy(tData, newData, tData.Length);
tData = newData;
// Copy the key array.
var newKeys = new double[Capacity];
Array.Copy(tKeys, newKeys, tKeys.Length);
tKeys = newKeys;
}
// Insert new value at the end
tData[Size] = value;
tKeys[Size] = key;
SiftUp(Size);
Size++;
}
19
Source : AesEncryptor.cs
with MIT License
from alexanderdna
with MIT License
from alexanderdna
public static byte[] Encrypt(byte[] plainTextBytes, byte[] keyBytes)
{
if (keyBytes.Length != KeySize) throw new ArgumentException("Invalid key length", nameof(keyBytes));
byte[] initialVectorBytes = new byte[BlockSize];
_rand.NextBytes(initialVectorBytes);
byte[] cipherTextBytes = null;
using (var symmetricKey = Rijndael.Create())
{
symmetricKey.Mode = CipherMode.CFB;
symmetricKey.IV = initialVectorBytes;
symmetricKey.Key = keyBytes;
symmetricKey.Padding = PaddingMode.Zeros;
symmetricKey.BlockSize = BlockSize * 8;
symmetricKey.FeedbackSize = BlockSize * 8;
using ICryptoTransform encryptor = symmetricKey.CreateEncryptor();
using MemoryStream memStream = new MemoryStream();
using (CryptoStream cryptoStream = new CryptoStream(memStream, encryptor, CryptoStreamMode.Write))
{
cryptoStream.Write(plainTextBytes, 0, plainTextBytes.Length);
}
cipherTextBytes = memStream.ToArray();
}
byte[] returnBytes = new byte[initialVectorBytes.Length + cipherTextBytes.Length];
Array.Copy(initialVectorBytes, returnBytes, initialVectorBytes.Length);
Array.Copy(cipherTextBytes, 0, returnBytes, initialVectorBytes.Length, cipherTextBytes.Length);
return returnBytes;
}
19
Source : AesEncryptor.cs
with MIT License
from alexanderdna
with MIT License
from alexanderdna
public static byte[] Decrypt(byte[] cipherTextBytes, byte[] keyBytes)
{
if (keyBytes.Length != KeySize) throw new ArgumentException("Invalid key length", nameof(keyBytes));
byte[] initialVectorBytes = new byte[BlockSize];
Array.Copy(cipherTextBytes, initialVectorBytes, initialVectorBytes.Length);
byte[] plainTextBytes = new byte[cipherTextBytes.Length - initialVectorBytes.Length];
using (var symmetricKey = Rijndael.Create())
{
symmetricKey.Mode = CipherMode.CFB;
symmetricKey.IV = initialVectorBytes;
symmetricKey.Key = keyBytes;
symmetricKey.Padding = PaddingMode.Zeros;
symmetricKey.BlockSize = BlockSize * 8;
symmetricKey.FeedbackSize = BlockSize * 8;
using ICryptoTransform decryptor = symmetricKey.CreateDecryptor();
using MemoryStream memStream = new MemoryStream(cipherTextBytes, initialVectorBytes.Length, plainTextBytes.Length);
using CryptoStream cryptoStream = new CryptoStream(memStream, decryptor, CryptoStreamMode.Read);
cryptoStream.Read(plainTextBytes, 0, plainTextBytes.Length);
}
return plainTextBytes;
}
19
Source : WebassemblyModule.cs
with MIT License
from alexanderkyte
with MIT License
from alexanderkyte
protected uint GrowMemory (uint addition)
{
var temp = this.memory;
var curr_length = temp.Length / PageSize;
var new_length = (curr_length + 1) * PageSize;
// Fixme: check maximum length
var new_memory = new byte [new_length];
Array.Copy(temp, this.memory, curr_length);
this.memory = new_memory;
return Convert.ToUInt32 (curr_length);
}
19
Source : ImmutableDictionary.cs
with MIT License
from alexandrnikitin
with MIT License
from alexandrnikitin
internal override ImmutableDictionary<TKey, TValue> Add(TKey key, TValue value, uint hash, int shift)
{
var bit = 1U << (int) ((hash >> shift) & Mask);
if ((_bitmap & bit) != 0)
{
var newNodes = new ImmutableDictionary<TKey, TValue>[_nodes.Length];
Array.Copy(_nodes, newNodes, _nodes.Length);
var index = Popcnt.PopCount((_bitmap >> (int) bit) & Mask);
newNodes[index] = _nodes[index].Add(key, value, hash, shift + Shift);
return new BitMapNode<TKey, TValue>(_bitmap, newNodes);
}
else
{
var index = Popcnt.PopCount((_bitmap >> (int)bit) & Mask);
var newNodes = new ImmutableDictionary<TKey, TValue>[_nodes.Length + 1];
Array.Copy(_nodes, newNodes, index);
Array.Copy(_nodes, index, newNodes, index + 1, _nodes.Length - index);
newNodes[index] = new KeyValueNode<TKey, TValue>(key, value, hash);
return new BitMapNode<TKey, TValue>(_bitmap | bit, newNodes);
}
}
19
Source : ImmutableDictionary.cs
with MIT License
from alexandrnikitin
with MIT License
from alexandrnikitin
internal override ImmutableDictionary<TKey, TValue> Add(TKey key, TValue value, uint hash, int shift)
{
var bit = 1U << (int) ((hash >> shift) & Mask);
if ((_bitmapNodes & bit) != 0)
{
var newNodes = new ImmutableDictionary<TKey, TValue>[_nodes.Length];
Array.Copy(_nodes, newNodes, _nodes.Length);
var index = Popcnt.PopCount(_bitmapNodes & (bit - 1));
newNodes[index] = _nodes[index].Add(key, value, hash, shift + Shift);
return new BitMapNode<TKey, TValue, TValues>(_bitmapNodes, newNodes, _bitmapValues, _values);
}
else if ((_bitmapValues & bit) != 0)
{
// TODO collisions and same value
var newNodes = new ImmutableDictionary<TKey, TValue>[_nodes.Length + 1];
var index = Popcnt.PopCount(_bitmapNodes & (bit - 1));
Array.Copy(_nodes, newNodes, index);
Array.Copy(_nodes, index, newNodes, index + 1, _nodes.Length - index);
var indexValues = Popcnt.PopCount(_bitmapValues & (bit - 1));
var key2 = _values.GetKey(indexValues);
var value2 = _values.GetValue(indexValues);
newNodes[index] = BitMapNode<TKey, TValue, TValues>.From(key, value, hash, shift + Shift, key2, value2);
return _values.Shrink(_bitmapNodes | bit, newNodes, _bitmapValues ^ bit, (uint) indexValues);
}
else
{
var index = (uint)Popcnt.PopCount(_bitmapValues & (bit - 1));
return _values.Add(key, value, _bitmapNodes, _nodes, _bitmapValues | bit, index);
}
}
19
Source : TemplateOptionsData.cs
with MIT License
from alexismorin
with MIT License
from alexismorin
public void CopyPortOptionsFrom( TemplateOptionsContainer container, string preplacedName )
{
if( container == null || container.Options == null )
return;
List<TemplateOptionsItem> newItems = new List<TemplateOptionsItem>();
for( int i = 0; i < container.Options.Length; i++ )
{
if( container.Options[ i ].Type == AseOptionsType.Port &&
container.Options[ i ].Id.Equals( preplacedName ) )
{
newItems.Add( container.Options[ i ] );
}
}
if( newItems.Count > 0 )
{
Enabled = true;
if( Options == null )
{
Options = newItems.ToArray();
}
else
{
Array.Resize<TemplateOptionsItem>( ref Options, Options.Length + newItems.Count );
Array.Copy( newItems.ToArray(), Options, newItems.Count );
}
}
newItems.Clear();
newItems = null;
}
19
Source : Reflection.cs
with MIT License
from alfa-laboratory
with MIT License
from alfa-laboratory
public static object ConvertObject(object obj, Type type)
{
var t = GetObjectType(type);
if(obj == null)
{
return GetDefault(t);
}
if(t.IsEnum)
{
obj = Enum.Parse(t, obj is string value ? value : obj.ToString(), false);
}
if(t == typeof(string))
{
if(obj is string convertObject)
{
return convertObject;
}
var mi = obj.GetType().GetMethods().SingleOrDefault(m => m.Name == "ToString" && !m.GetMethodParameters().Any());
return mi?.Invoke(obj, Array.Empty<object>());
}
if((obj is string s) && t == typeof(char[]))
{
return s.Split();
}
if(t.IsArray)
{
if(obj is Array arrSrc)
{
var arrDest = (Array)CreateArray(t.GetElementType(), arrSrc.Length);
Array.Copy(arrSrc, arrDest, arrSrc.Length);
return arrDest;
}
}
if(t == typeof(object))
{
return obj;
}
if(obj is not string o)
{
return Convert.ChangeType(obj, t);
}
if(t == typeof(bool))
{
if(short.TryParse(o, out var i))
{
return i != 0;
}
return bool.Parse(o);
}
if(t == typeof(decimal) || t == typeof(float))
{
var types = new[] { typeof(string), typeof(NumberStyles), typeof(IFormatProvider), t.MakeByRefType() };
var args = new[] { o, NumberStyles.Any, new NumberFormatInfo { NumberDecimalSeparator = "," }, GetDefault(t) };
if((bool)t.GetMethod("TryParse", types)?.Invoke(null, args)!)
{
return args[3];
}
types = new[] { typeof(string), typeof(NumberStyles), typeof(IFormatProvider) };
args = new object[] { o, NumberStyles.Any, new NumberFormatInfo { NumberDecimalSeparator = "." } };
return t.GetMethod("Parse", types)?.Invoke(null, args);
}
if(t == typeof(long)
|| t == typeof(ulong)
|| t == typeof(int)
|| t == typeof(uint)
|| t == typeof(short)
|| t == typeof(ushort)
|| t == typeof(byte)
|| t == typeof(sbyte)
|| t == typeof(char))
{
return t.GetMethod("Parse", new[] { typeof(string) })?.Invoke(null, new object[] {o});
}
if(t == typeof(DateTime))
{
return DateTime.TryParse(o, CultureInfo.GetCultureInfo("ru-RU"), DateTimeStyles.replacedumeLocal, out var dt) ? dt : DateTime.Parse(o, CultureInfo.GetCultureInfo("en-US"), DateTimeStyles.replacedumeLocal);
}
return Convert.ChangeType(o, t);
}
19
Source : HelloFS.cs
with MIT License
from alhimik45
with MIT License
from alhimik45
protected override Errno OnGetPathExtendedAttribute (string path, string name, byte[] value, out int bytesWritten)
{
Trace.WriteLine ("(OnGetPathExtendedAttribute {0})", path);
bytesWritten = 0;
if (path != hello_path) {
return 0;
}
byte[] _value;
lock (hello_attrs) {
if (!hello_attrs.ContainsKey (name))
return 0;
_value = hello_attrs [name];
}
if (value != null)
{
if (value.Length < _value.Length) {
return Errno.ERANGE;
}
Array.Copy(_value, value, _value.Length);
}
bytesWritten = _value.Length;
return 0;
}
19
Source : MainForm.cs
with Apache License 2.0
from alibaba
with Apache License 2.0
from alibaba
private void LoadImg()
{
//MessageBox.Show(cur.ToString());
Image img = rgIMD[cur].GetImg();
if (null != img)
{
bmp = new Bitmap(img);
Poly[] rgPoly = rgIMD[cur].GetPoly();
if (rgPoly.Length > 0)
{
index = rgPoly.Length;
Array.Copy(rgPoly, buffer, index);
}
bottomToolStripStatusLabel.Text = Path.GetFileName(rgIMD[cur].path);
}
else
{
bottomToolStripStatusLabel.Text = "Image corruption : " + Path.GetFileName(rgIMD[cur].path);
}
DrawPanel(-1);
OperateClick();
if (ava == cur)
{
FindAva();
}
nextButton.Enabled = (cur + 1) < rgIMD.Length;
preButton.Enabled = cur > 0;
}
19
Source : KeyStoreCrypto.cs
with MIT License
from allartprotocol
with MIT License
from allartprotocol
public byte[] GenerateCipherKey(byte[] derivedKey)
{
var cypherKey = new byte[16];
Array.Copy(derivedKey, cypherKey, 16);
return cypherKey;
}
See More Examples