1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
// ==++==
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//
// ==--==
/*============================================================
**
** Class: SerializationFieldInfo
**
**
** Purpose: Provides a methods of representing imaginary fields
** which are unique to serialization. In this case, what we're
** representing is the private members of parent classes. We
** aggregate the RuntimeFieldInfo associated with this member
** and return a managled form of the name. The name that we
** return is .parentname.fieldname
**
**
============================================================*/
namespace System.Runtime.Serialization {
using System;
using System.Reflection;
using System.Globalization;
using System.Diagnostics.Contracts;
using System.Threading;
#if FEATURE_REMOTING
using System.Runtime.Remoting.Metadata;
#endif //FEATURE_REMOTING
internal sealed class SerializationFieldInfo : FieldInfo {
internal const String FakeNameSeparatorString = "+";
private RuntimeFieldInfo m_field;
private String m_serializationName;
public override Module Module { get { return m_field.Module; } }
public override int MetadataToken { get { return m_field.MetadataToken; } }
internal SerializationFieldInfo(RuntimeFieldInfo field, String namePrefix) {
Contract.Assert(field!=null, "[SerializationFieldInfo.ctor]field!=null");
Contract.Assert(namePrefix!=null, "[SerializationFieldInfo.ctor]namePrefix!=null");
m_field = field;
m_serializationName = String.Concat(namePrefix, FakeNameSeparatorString, m_field.Name);
}
//
// MemberInfo methods
//
public override String Name {
get {
return m_serializationName;
}
}
public override Type DeclaringType {
get {
return m_field.DeclaringType;
}
}
public override Type ReflectedType {
get {
return m_field.ReflectedType;
}
}
public override Object[] GetCustomAttributes(bool inherit) {
return m_field.GetCustomAttributes(inherit);
}
public override Object[] GetCustomAttributes(Type attributeType, bool inherit) {
return m_field.GetCustomAttributes(attributeType, inherit);
}
public override bool IsDefined(Type attributeType, bool inherit) {
return m_field.IsDefined(attributeType, inherit);
}
//
// FieldInfo methods
//
public override Type FieldType {
get {
return m_field.FieldType;
}
}
public override Object GetValue(Object obj) {
return m_field.GetValue(obj);
}
[System.Security.SecurityCritical]
internal Object InternalGetValue(Object obj) {
RtFieldInfo field = m_field as RtFieldInfo;
if (field != null)
{
field.CheckConsistency(obj);
return field.UnsafeGetValue(obj);
}
else
return m_field.GetValue(obj);
}
public override void SetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture) {
m_field.SetValue(obj, value, invokeAttr, binder, culture);
}
[System.Security.SecurityCritical]
internal void InternalSetValue(Object obj, Object value, BindingFlags invokeAttr, Binder binder, CultureInfo culture) {
RtFieldInfo field = m_field as RtFieldInfo;
if (field != null)
{
field.CheckConsistency(obj);
field.UnsafeSetValue(obj, value, invokeAttr, binder, culture);
}
else
m_field.SetValue(obj, value, invokeAttr, binder, culture);
}
internal RuntimeFieldInfo FieldInfo {
get {
return m_field;
}
}
public override RuntimeFieldHandle FieldHandle {
get {
return m_field.FieldHandle;
}
}
public override FieldAttributes Attributes {
get {
return m_field.Attributes;
}
}
#if FEATURE_REMOTING
#region Legacy Remoting Cache
private RemotingFieldCachedData m_cachedData;
internal RemotingFieldCachedData RemotingCache
{
get
{
// This grabs an internal copy of m_cachedData and uses
// that instead of looking at m_cachedData directly because
// the cache may get cleared asynchronously. This prevents
// us from having to take a lock.
RemotingFieldCachedData cache = m_cachedData;
if (cache == null)
{
cache = new RemotingFieldCachedData(this);
RemotingFieldCachedData ret = Interlocked.CompareExchange(ref m_cachedData, cache, null);
if (ret != null)
cache = ret;
}
return cache;
}
}
#endregion
#endif //FEATURE_REMOTING
}
}
|