public VectorType(T value, IEnumerable <string> fieldNames, Func <T, int, V> getField, SetFieldDelegate setField) { m_Value = value; m_GetField = getField; m_SetField = setField; m_FieldNames = fieldNames.ToList(); }
public static void initFields(Type type, SetFieldDelegate setFieldDelegate) { //FieldInfo[] fields = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly); //for (int a = fields.Length; a-- > 0;) //{ // FieldInfo field = fields[a]; // Type fieldType = field.FieldType; // if (!fieldType.IsGenericType) // { // continue; // } // Type[] genericArgTypes = fieldType.GetGenericArguments(); // if (genericArgTypes == null || genericArgTypes.Length != 1) // { // continue; // } // Object eventDelegate = Activator.CreateInstance(EventDelegateType.MakeGenericType(genericArgTypes), field.Name); // setFieldDelegate(field, eventDelegate); //} PropertyInfo[] properties = type.GetProperties(BindingFlags.Static | BindingFlags.Public | BindingFlags.DeclaredOnly); for (int a = properties.Length; a-- > 0;) { PropertyInfo property = properties[a]; Type propertyType = property.PropertyType; if (!propertyType.IsGenericType || !property.CanWrite) { continue; } Type[] genericArgTypes = propertyType.GetGenericArguments(); if (genericArgTypes == null || genericArgTypes.Length != 1) { continue; } if (property.CanRead) { Object existingValue = property.GetValue(null, null); if (existingValue != null) { // This property already has a valid value so we are skipping it here continue; } } //"<GotFocus>k__BackingField" String fieldName = "<" + property.Name + ">k__BackingField"; FieldInfo field = type.GetField(fieldName, BindingFlags.Static | BindingFlags.NonPublic); Object eventDelegate = Activator.CreateInstance(EventDelegateType.MakeGenericType(genericArgTypes), property.Name); setFieldDelegate.Invoke(field, eventDelegate); } }
static SecuredReflectionMethods() { if (!SecuredReflection.HasReflectionPermission) { if (!ProfilerInterceptor.IsProfilerAttached) { ProfilerInterceptor.ThrowElevatedMockingException(); } ProfilerInterceptor.CreateDelegateFromBridge("ReflectionInvoke", out Invoke); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetProperty", out GetProperty); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetProperty", out SetProperty); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetField", out GetField); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetField", out SetField); } else { Invoke = (method, instance, args) => method.Invoke(instance, args); GetProperty = (prop, instance, indexArgs) => prop.GetValue(instance, indexArgs); SetProperty = (prop, instance, value, indexArgs) => prop.SetValue(instance, value, indexArgs); GetField = (field, instance) => field.GetValue(instance); SetField = (field, instance, value) => field.SetValue(instance, value); } }
/// <summary> /// Initialize a new instance of this class with the provided field info /// </summary> /// <param name="fieldInfo">The field info</param> private RuntimeFieldProxy(FieldInfo fieldInfo, GetFieldDelegate getProxy, SetFieldDelegate setProxy) { Field = fieldInfo; GetProxy = getProxy; SetProxy = setProxy; }
static SecuredReflectionMethods() { if (!SecuredReflection.HasReflectionPermission) { if (!ProfilerInterceptor.IsProfilerAttached) ProfilerInterceptor.ThrowElevatedMockingException(); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionInvoke", out Invoke); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetProperty", out GetProperty); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetProperty", out SetProperty); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionGetField", out GetField); ProfilerInterceptor.CreateDelegateFromBridge("ReflectionSetField", out SetField); } else { Invoke = (method, instance, args) => method.Invoke(instance, args); GetProperty = (prop, instance, indexArgs) => prop.GetValue(instance, indexArgs); SetProperty = (prop, instance, value, indexArgs) => prop.SetValue(instance, value, indexArgs); GetField = (field, instance) => field.GetValue(instance); SetField = (field, instance, value) => field.SetValue(instance, value); } }