-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added dynamic property binding for VObject
- Borrowed a few MIT licensed utils from Json.Net.
- Loading branch information
Showing
8 changed files
with
725 additions
and
3 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#region License | ||
// Copyright (c) 2007 James Newton-King | ||
// | ||
// Permission is hereby granted, free of charge, to any person | ||
// obtaining a copy of this software and associated documentation | ||
// files (the "Software"), to deal in the Software without | ||
// restriction, including without limitation the rights to use, | ||
// copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the | ||
// Software is furnished to do so, subject to the following | ||
// conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
// OTHER DEALINGS IN THE SOFTWARE. | ||
#endregion | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using System.Diagnostics; | ||
using System.Linq; | ||
|
||
namespace Gameloop.Vdf.Utilities | ||
{ | ||
internal static class CollectionUtils | ||
{ | ||
/// <summary> | ||
/// Adds the elements of the specified collection to the specified generic <see cref="IList{T}"/>. | ||
/// </summary> | ||
/// <param name="initial">The list to add to.</param> | ||
/// <param name="collection">The collection of elements to add.</param> | ||
public static void AddRange<T>(this IList<T> initial, IEnumerable<T> collection) | ||
{ | ||
if (initial == null) | ||
{ | ||
throw new ArgumentNullException(nameof(initial)); | ||
} | ||
|
||
if (collection == null) | ||
{ | ||
return; | ||
} | ||
|
||
foreach (T value in collection) | ||
{ | ||
initial.Add(value); | ||
} | ||
} | ||
|
||
public static T[] ArrayEmpty<T>() | ||
{ | ||
T[] array = Enumerable.Empty<T>() as T[]; | ||
Debug.Assert(array != null); | ||
// Defensively guard against a version of Linq where Enumerable.Empty<T> doesn't | ||
// return an array, but throw in debug versions so a better strategy can be | ||
// used if that ever happens. | ||
return array ?? new T[0]; | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#region License | ||
// Copyright (c) 2007 James Newton-King | ||
// | ||
// Permission is hereby granted, free of charge, to any person | ||
// obtaining a copy of this software and associated documentation | ||
// files (the "Software"), to deal in the Software without | ||
// restriction, including without limitation the rights to use, | ||
// copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
// copies of the Software, and to permit persons to whom the | ||
// Software is furnished to do so, subject to the following | ||
// conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES | ||
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT | ||
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR | ||
// OTHER DEALINGS IN THE SOFTWARE. | ||
#endregion | ||
|
||
using System.Collections.Generic; | ||
using System.Dynamic; | ||
|
||
namespace Gameloop.Vdf.Utilities | ||
{ | ||
internal class DynamicProxy<T> | ||
{ | ||
public virtual IEnumerable<string> GetDynamicMemberNames(T instance) | ||
{ | ||
return CollectionUtils.ArrayEmpty<string>(); | ||
} | ||
|
||
public virtual bool TryBinaryOperation(T instance, BinaryOperationBinder binder, object arg, out object result) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
|
||
public virtual bool TryConvert(T instance, ConvertBinder binder, out object result) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
|
||
public virtual bool TryCreateInstance(T instance, CreateInstanceBinder binder, object[] args, out object result) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
|
||
public virtual bool TryDeleteIndex(T instance, DeleteIndexBinder binder, object[] indexes) | ||
{ | ||
return false; | ||
} | ||
|
||
public virtual bool TryDeleteMember(T instance, DeleteMemberBinder binder) | ||
{ | ||
return false; | ||
} | ||
|
||
public virtual bool TryGetIndex(T instance, GetIndexBinder binder, object[] indexes, out object result) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
|
||
public virtual bool TryGetMember(T instance, GetMemberBinder binder, out object result) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
|
||
public virtual bool TryInvoke(T instance, InvokeBinder binder, object[] args, out object result) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
|
||
public virtual bool TryInvokeMember(T instance, InvokeMemberBinder binder, object[] args, out object result) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
|
||
public virtual bool TrySetIndex(T instance, SetIndexBinder binder, object[] indexes, object value) | ||
{ | ||
return false; | ||
} | ||
|
||
public virtual bool TrySetMember(T instance, SetMemberBinder binder, object value) | ||
{ | ||
return false; | ||
} | ||
|
||
public virtual bool TryUnaryOperation(T instance, UnaryOperationBinder binder, out object result) | ||
{ | ||
result = null; | ||
return false; | ||
} | ||
} | ||
} |
Oops, something went wrong.