public FieldGetter(FieldInfo fieldInfo) { _fieldInfo = fieldInfo; _name = fieldInfo.Name; _memberType = fieldInfo.FieldType; _lateBoundFieldGet = DelegateFactory.CreateGet(fieldInfo); _lateBoundFieldSet = DelegateFactory.CreateSet(fieldInfo); }
public void Should_set_field_when_field_is_a_reference_type() { var sourceType = typeof(Source); FieldInfo field = sourceType.GetField("Value3"); LateBoundFieldSet callback = DelegateFactory.CreateSet(field); var source = new Source(); callback(source, "hello"); source.Value3.ShouldEqual("hello"); }
public void Should_set_field_when_field_is_a_value_type() { var sourceType = typeof(Source); FieldInfo field = sourceType.GetField("Value2"); LateBoundFieldSet <Source, int> callback = DelegateFactory.CreateSet <Source, int>(field).Compile(); var source = new Source(); callback(source, 5); source.Value2.ShouldEqual(5); }
public FieldAccessor(FieldInfo fieldInfo) : base(fieldInfo) { _lateBoundFieldSet = DelegateFactory.CreateSet(fieldInfo); }
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; }
public CachedFieldInfo(FieldInfo fieldInfo, LateBoundFieldSet setter, LateBoundFieldGet getter) { FieldInfo = fieldInfo; Getter = getter; Setter = setter; }