2
// Copyright (c) 2007 James Newton-King
4
// Permission is hereby granted, free of charge, to any person
5
// obtaining a copy of this software and associated documentation
6
// files (the "Software"), to deal in the Software without
7
// restriction, including without limitation the rights to use,
8
// copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the
10
// Software is furnished to do so, subject to the following
13
// The above copyright notice and this permission notice shall be
14
// included in all copies or substantial portions of the Software.
16
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
// OTHER DEALINGS IN THE SOFTWARE.
27
using System.Globalization;
28
using System.Reflection;
30
namespace Newtonsoft.Json.Utilities
32
internal abstract class ReflectionDelegateFactory
34
public Func<T, object> CreateGet<T>(MemberInfo memberInfo)
36
PropertyInfo propertyInfo = memberInfo as PropertyInfo;
37
if (propertyInfo != null)
38
return CreateGet<T>(propertyInfo);
40
FieldInfo fieldInfo = memberInfo as FieldInfo;
41
if (fieldInfo != null)
42
return CreateGet<T>(fieldInfo);
44
throw new Exception("Could not create getter for {0}.".FormatWith(CultureInfo.InvariantCulture, memberInfo));
47
public Action<T, object> CreateSet<T>(MemberInfo memberInfo)
49
PropertyInfo propertyInfo = memberInfo as PropertyInfo;
50
if (propertyInfo != null)
51
return CreateSet<T>(propertyInfo);
53
FieldInfo fieldInfo = memberInfo as FieldInfo;
54
if (fieldInfo != null)
55
return CreateSet<T>(fieldInfo);
57
throw new Exception("Could not create setter for {0}.".FormatWith(CultureInfo.InvariantCulture, memberInfo));
60
public abstract MethodCall<T, object> CreateMethodCall<T>(MethodBase method);
61
public abstract Func<T> CreateDefaultConstructor<T>(Type type);
62
public abstract Func<T, object> CreateGet<T>(PropertyInfo propertyInfo);
63
public abstract Func<T, object> CreateGet<T>(FieldInfo fieldInfo);
64
public abstract Action<T, object> CreateSet<T>(FieldInfo fieldInfo);
65
public abstract Action<T, object> CreateSet<T>(PropertyInfo propertyInfo);
2
// Copyright (c) 2007 James Newton-King
4
// Permission is hereby granted, free of charge, to any person
5
// obtaining a copy of this software and associated documentation
6
// files (the "Software"), to deal in the Software without
7
// restriction, including without limitation the rights to use,
8
// copy, modify, merge, publish, distribute, sublicense, and/or sell
9
// copies of the Software, and to permit persons to whom the
10
// Software is furnished to do so, subject to the following
13
// The above copyright notice and this permission notice shall be
14
// included in all copies or substantial portions of the Software.
16
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
18
// OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
20
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21
// WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23
// OTHER DEALINGS IN THE SOFTWARE.
27
using System.Globalization;
28
using System.Reflection;
29
using Newtonsoft.Json.Serialization;
31
using Newtonsoft.Json.Utilities.LinqBridge;
34
namespace Newtonsoft.Json.Utilities
36
internal abstract class ReflectionDelegateFactory
38
public Func<T, object> CreateGet<T>(MemberInfo memberInfo)
40
PropertyInfo propertyInfo = memberInfo as PropertyInfo;
41
if (propertyInfo != null)
42
return CreateGet<T>(propertyInfo);
44
FieldInfo fieldInfo = memberInfo as FieldInfo;
45
if (fieldInfo != null)
46
return CreateGet<T>(fieldInfo);
48
throw new Exception("Could not create getter for {0}.".FormatWith(CultureInfo.InvariantCulture, memberInfo));
51
public Action<T, object> CreateSet<T>(MemberInfo memberInfo)
53
PropertyInfo propertyInfo = memberInfo as PropertyInfo;
54
if (propertyInfo != null)
55
return CreateSet<T>(propertyInfo);
57
FieldInfo fieldInfo = memberInfo as FieldInfo;
58
if (fieldInfo != null)
59
return CreateSet<T>(fieldInfo);
61
throw new Exception("Could not create setter for {0}.".FormatWith(CultureInfo.InvariantCulture, memberInfo));
64
public abstract MethodCall<T, object> CreateMethodCall<T>(MethodBase method);
65
public abstract Func<T> CreateDefaultConstructor<T>(Type type);
66
public abstract Func<T, object> CreateGet<T>(PropertyInfo propertyInfo);
67
public abstract Func<T, object> CreateGet<T>(FieldInfo fieldInfo);
68
public abstract Action<T, object> CreateSet<T>(FieldInfo fieldInfo);
69
public abstract Action<T, object> CreateSet<T>(PropertyInfo propertyInfo);
b'\\ No newline at end of file'