示例#1
1
 public FieldGetter(FieldInfo fieldInfo)
 {
     _fieldInfo = fieldInfo;
     _name = fieldInfo.Name;
     _memberType = fieldInfo.FieldType;
     _lateBoundFieldGet = DelegateFactory.CreateGet(fieldInfo);
 }
示例#2
0
 public FieldGetter(FieldInfo fieldInfo)
 {
     _fieldInfo         = fieldInfo;
     _name              = fieldInfo.Name;
     _memberType        = fieldInfo.FieldType;
     _lateBoundFieldGet = DelegateFactory.CreateGet(fieldInfo);
 }
        public void FieldTests()
        {
            FieldInfo         field    = typeof(Source).GetField("Value2");
            LateBoundFieldGet callback = DelegateFactory.CreateGet(field);

            var source = new Source {
                Value2 = 15
            };
            int result = (int)callback(source);

            result.ShouldEqual(15);
        }
示例#4
0
            internal FieldAccessor(string fieldName, Type type, LateBoundFieldGet getAccessor, LateBoundFieldSet setAccessor)
            {
                try
                {
                    //if field is a compiler generated backing field (i.e auto property), try to extract the property name
                    FieldName = fieldName.EndsWith(">k__BackingField")
                                    ? fieldName.Substring(1, fieldName.IndexOf(">", System.StringComparison.Ordinal) - 1)
                                    : fieldName;
                }
                catch
                {
                    FieldName = fieldName;
                }

                FieldType = type;
                FieldTypeName = type.ToString();
                GetAccessor = getAccessor;
                SetAccessor = setAccessor;
            }
示例#5
0
 public CachedFieldInfo(FieldInfo fieldInfo, LateBoundFieldSet setter, LateBoundFieldGet getter)
 {
     FieldInfo = fieldInfo;
     Getter    = getter;
     Setter    = setter;
 }