Skip to content

Latest commit

 

History

History
64 lines (47 loc) · 1.94 KB

README.md

File metadata and controls

64 lines (47 loc) · 1.94 KB

ObjPropsDynamicSetter

Coverage Mutation Score

A small library providing object extensions for getting properties information and manipulating their values via property names known at runtime. Uses reflection under the hood. Might be useful for playing with models properties in data-driven testing, but not limited to it. Supports nested properties access and access to non-public properties.

Use

Simple usage examples:

var model = new Model();
var propertyName = "Foo";

// PropertyInfo retrieval from a property
var propertyInfo = model.GetPropertyInfo(propertyName);

// Property value retrieval
var propertyValue = model.GetPropertyValue(propertyName);

// Setting new value to a property
var value = 1000;
model.SetPropertyValue(propertyName, value);

Public properties are accessible by default. To access non-public ones, optional parameter 'includeNonPublic' should be set to 'true':

model.SetPropertyValue(propertyName, value, true);

To access nested property, full path should be specified with dot ('.') as delimiter:

public class Model
{
    public NestedModel NestedModel { get; set; }
}

public class NestedModel
{
    public int Bar { get; set; }
}

// Internal initialization logic skipped for simplicity
var model = new Model();
var propertyName = "NestedModel.Bar";

var value = model.GetPropertyValue(propertyName);

Download

The latest release is on NuGet and GitHub.