Skip to content

Commit ed1281f

Browse files
committed
CoreCLR (Issue #51) removed usage of Encoding.Default, Debugger.NotifyOfCrossThreadDependency(), Converter<T1, T2>, and legacy exception serialization
1 parent eecd853 commit ed1281f

File tree

7 files changed

+42
-14
lines changed

7 files changed

+42
-14
lines changed

FdbShell/Mono.Options/Options.cs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -668,22 +668,25 @@ public OptionException (string message, string optionName, Exception innerExcept
668668
this.option = optionName;
669669
}
670670

671+
#if !CORE_CLR
671672
protected OptionException (SerializationInfo info, StreamingContext context)
672673
: base (info, context)
673674
{
674675
this.option = info.GetString ("OptionName");
675676
}
676677

677-
public string OptionName {
678-
get {return this.option;}
679-
}
680-
681678
[SecurityPermission (SecurityAction.LinkDemand, SerializationFormatter = true)]
682679
public override void GetObjectData (SerializationInfo info, StreamingContext context)
683680
{
684681
base.GetObjectData (info, context);
685682
info.AddValue ("OptionName", option);
686683
}
684+
#endif
685+
686+
public string OptionName {
687+
get {return this.option;}
688+
}
689+
687690
}
688691

689692
public delegate void OptionAction<TKey, TValue> (TKey key, TValue value);

FoundationDB.Client/Async/AsyncTransformQueue.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ public int Count
6868
{
6969
get
7070
{
71+
#if !CORE_CLR
7172
Debugger.NotifyOfCrossThreadDependency();
73+
#endif
7274
lock (m_lock)
7375
{
7476
return m_queue.Count;
@@ -87,7 +89,9 @@ public bool IsConsumerBlocked
8789
{
8890
get
8991
{
92+
#if !CORE_CLR
9093
Debugger.NotifyOfCrossThreadDependency();
94+
#endif
9195
lock (m_lock)
9296
{
9397
return m_blockedConsumer != null && m_blockedConsumer.Task.IsCompleted;
@@ -100,7 +104,9 @@ public bool IsProducerBlocked
100104
{
101105
get
102106
{
107+
#if !CORE_CLR
103108
Debugger.NotifyOfCrossThreadDependency();
109+
#endif
104110
lock (m_lock)
105111
{
106112
return m_blockedProducer != null && m_blockedProducer.Task.IsCompleted;

FoundationDB.Client/Converters/FdbConverters.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -537,12 +537,13 @@ public static T Unbox<T>(object value)
537537
/// <param name="value">Boxed value</param>
538538
/// <returns>Converted value, or an exception if there are no known convertions. The value null is converted into default(<typeparamref name="R"/>) by convention</returns>
539539
/// <exception cref="System.InvalidOperationException">No valid converter for these types was found</exception>
540+
[CanBeNull]
540541
public static R ConvertBoxed<R>(object value)
541542
{
542543
if (value == null) return default(R);
543544
var type = value.GetType();
544545

545-
var targetType = typeof (R);
546+
var targetType = typeof(R);
546547

547548
// cast !
548549
if (targetType.IsAssignableFrom(type)) return (R)value;
@@ -573,7 +574,7 @@ public static R ConvertBoxed<R>(object value)
573574

574575
/// <summary>Converts all the elements of a sequence</summary>
575576
/// <returns>New sequence with all the converted elements</returns>
576-
public static IEnumerable<R> ConvertAll<T, R>(this IFdbConverter<T, R> converter, [NotNull] IEnumerable<T> items)
577+
public static IEnumerable<R> ConvertAll<T, R>([NotNull] this IFdbConverter<T, R> converter, [NotNull] IEnumerable<T> items)
577578
{
578579
if (converter == null) throw new ArgumentNullException("converter");
579580
if (items == null) throw new ArgumentNullException("items");
@@ -587,18 +588,27 @@ public static IEnumerable<R> ConvertAll<T, R>(this IFdbConverter<T, R> converter
587588
/// <summary>Converts all the elements of a list</summary>
588589
/// <returns>New list with all the converted elements</returns>
589590
[NotNull]
590-
public static List<R> ConvertAll<T, R>(this IFdbConverter<T, R> converter, [NotNull] List<T> items)
591+
public static List<R> ConvertAll<T, R>([NotNull] this IFdbConverter<T, R> converter, [NotNull] List<T> items)
591592
{
592593
if (converter == null) throw new ArgumentNullException("converter");
593594
if (items == null) throw new ArgumentNullException("items");
594595

596+
#if CORE_CLR
597+
var list = new List<R>(items.Count);
598+
foreach (var item in items)
599+
{
600+
list.Add(converter.Convert(item));
601+
}
602+
return list;
603+
#else
595604
return items.ConvertAll<R>(converter.Convert);
605+
#endif
596606
}
597607

598608
/// <summary>Converts all the elements of an array</summary>
599609
/// <returns>New array with all the converted elements</returns>
600610
[NotNull]
601-
public static R[] ConvertAll<T, R>(this IFdbConverter<T, R> converter, [NotNull] T[] items)
611+
public static R[] ConvertAll<T, R>([NotNull] this IFdbConverter<T, R> converter, [NotNull] T[] items)
602612
{
603613
if (converter == null) throw new ArgumentNullException("converter");
604614
if (items == null) throw new ArgumentNullException("items");

FoundationDB.Client/FdbException.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public FdbException(FdbError errorCode, string message, Exception innerException
5353
this.Code = errorCode;
5454
}
5555

56+
#if !CORE_CLR
5657
private FdbException(SerializationInfo info, StreamingContext context)
5758
: base(info, context)
5859
{
@@ -65,6 +66,7 @@ public override void GetObjectData(SerializationInfo info, StreamingContext cont
6566
base.GetObjectData(info, context);
6667
info.AddValue("Code", (int)this.Code);
6768
}
69+
#endif
6870

6971
/// <summary>Gets the code for this error.</summary>
7072
public FdbError Code { get; private set; }

FoundationDB.Client/Layers/Tuples/FdbTupleParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ internal static string ParseAscii(Slice slice)
733733

734734
var decoded = UnescapeByteString(slice.Array, slice.Offset + 1, slice.Count - 2);
735735

736-
return Encoding.Default.GetString(decoded.Array, decoded.Offset, decoded.Count);
736+
return Slice.DefaultEncoding.GetString(decoded.Array, decoded.Offset, decoded.Count);
737737
}
738738

739739
internal static string ParseUnicode(Slice slice)

FoundationDB.Client/Native/FdbNative.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#region BSD Licence
2-
/* Copyright (c) 2013-2014, Doxense SAS
2+
/* Copyright (c) 2013-2015, Doxense SAS
33
All rights reserved.
44
55
Redistribution and use in source and binary forms, with or without
@@ -304,11 +304,11 @@ public static Slice ToNativeString(string value, bool nullTerminated)
304304
if (nullTerminated)
305305
{ // NULL terminated ANSI string
306306
result = new byte[value.Length + 1];
307-
Encoding.Default.GetBytes(value, 0, value.Length, result, 0);
307+
Slice.DefaultEncoding.GetBytes(value, 0, value.Length, result, 0);
308308
}
309309
else
310310
{
311-
result = Encoding.Default.GetBytes(value);
311+
result = Slice.DefaultEncoding.GetBytes(value);
312312
}
313313
return new Slice(result, 0, result.Length);
314314
}

FoundationDB.Client/Utils/Slice.cs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,12 +830,19 @@ public static Slice FromUuid64(Uuid64 value)
830830
return value.ToSlice();
831831
}
832832

833+
internal static readonly Encoding DefaultEncoding =
834+
#if CORE_CLR
835+
Encoding.GetEncoding(0);
836+
#else
837+
Encoding.Default;
838+
#endif
839+
833840
/// <summary>Dangerously create a slice containing string converted to ASCII. All non-ASCII characters may be corrupted or converted to '?'</summary>
834841
/// <remarks>WARNING: if you put a string that contains non-ASCII chars, it will be silently corrupted! This should only be used to store keywords or 'safe' strings.
835842
/// Note: depending on your default codepage, chars from 128 to 255 may be preserved, but only if they are decoded using the same codepage at the other end !</remarks>
836843
public static Slice FromAscii(string text)
837844
{
838-
return text == null ? Slice.Nil : text.Length == 0 ? Slice.Empty : Slice.Create(Encoding.Default.GetBytes(text));
845+
return text == null ? Slice.Nil : text.Length == 0 ? Slice.Empty : Slice.Create(DefaultEncoding.GetBytes(text));
839846
}
840847

841848
/// <summary>Create a slice containing the UTF-8 bytes of the string <paramref name="value"/></summary>
@@ -964,7 +971,7 @@ public string ToAscii()
964971
{
965972
if (this.Count == 0) return this.HasValue ? String.Empty : default(string);
966973
SliceHelpers.EnsureSliceIsValid(ref this);
967-
return Encoding.Default.GetString(this.Array, this.Offset, this.Count);
974+
return Slice.DefaultEncoding.GetString(this.Array, this.Offset, this.Count);
968975
}
969976

970977
/// <summary>Stringify a slice containing an UTF-8 encoded string</summary>

0 commit comments

Comments
 (0)