public static ITweakable MakeTweakable(TweakableAttribute attribute, Type type, MemberInfo memberInfo, IBoundInstance instance, MemberInfo containerMemberInfo = null) { Type type2 = typeof(TweakableInfo <>).MakeGenericType(type); uint num = instance?.UniqueId ?? 0; MemberInfo memberInfo2 = ((containerMemberInfo != null) ? containerMemberInfo : memberInfo); TweakerRangeAttribute attribute2 = memberInfo2.GetCustomAttributes(typeof(TweakerRangeAttribute), inherit: false).FirstOrDefault() as TweakerRangeAttribute; StepSizeAttribute attribute3 = memberInfo2.GetCustomAttributes(typeof(StepSizeAttribute), inherit: false).FirstOrDefault() as StepSizeAttribute; NamedToggleValueAttribute[] source = memberInfo2.GetCustomAttributes(typeof(NamedToggleValueAttribute), inherit: false) as NamedToggleValueAttribute[]; ICustomTweakerAttribute[] array = memberInfo2.GetCustomAttributes(typeof(ICustomTweakerAttribute), inherit: true) as ICustomTweakerAttribute[]; source = source.OrderBy((NamedToggleValueAttribute toggle) => toggle.Order).ToArray(); object obj = MakeTweakableRange(type, attribute2); object obj2 = MakeTweakableStepSize(type, attribute3, attribute.Name); Array array2 = MakeTweakableToggleValues(type, source); WeakReference weakReference = null; if (instance != null) { weakReference = new WeakReference(instance.Instance); } string finalName = GetFinalName(attribute.Name, instance); object obj3 = Activator.CreateInstance(type2, finalName, obj, obj2, array2, num, array, attribute.Description); Type type3 = typeof(BaseTweakable <>).MakeGenericType(type); return(Activator.CreateInstance(type3, obj3, memberInfo, weakReference) as ITweakable); }
public static ITweakable MakeTweakable(Type tweakableType, string name, string description, Attribute[] attributes, out object virtualFieldRef) { TweakerRangeAttribute attribute = null; StepSizeAttribute attribute2 = null; List <NamedToggleValueAttribute> list = new List <NamedToggleValueAttribute>(); List <ICustomTweakerAttribute> list2 = new List <ICustomTweakerAttribute>(); if (attributes != null) { foreach (Attribute attribute3 in attributes) { if (attribute3 is TweakerRangeAttribute) { attribute = (TweakerRangeAttribute)attribute3; } else if (attribute3 is StepSizeAttribute) { attribute2 = (StepSizeAttribute)attribute3; } else if (attribute3 is NamedToggleValueAttribute) { list.Add((NamedToggleValueAttribute)attribute3); } else if (attribute3 is ICustomTweakerAttribute) { list2.Add((ICustomTweakerAttribute)attribute3); } } } object obj = MakeTweakableRange(tweakableType, attribute); object obj2 = MakeTweakableStepSize(tweakableType, attribute2, name); Array array = MakeTweakableToggleValues(tweakableType, list.ToArray()); Type type = typeof(TweakableInfo <>).MakeGenericType(tweakableType); Type type2 = typeof(VirtualField <>).MakeGenericType(tweakableType); Type type3 = typeof(BaseTweakable <>).MakeGenericType(tweakableType); object value = Activator.CreateInstance(type, name, obj, obj2, array, 0u, list2.ToArray(), description); object obj3 = Activator.CreateInstance(type2); ITweakable result = Activator.CreateInstance(type3, Convert.ChangeType(value, type), Convert.ChangeType(obj3, type2)) as ITweakable; virtualFieldRef = obj3; return(result); }
private static object MakeTweakableStepSize(Type type, StepSizeAttribute attribute, string tweakableName) { if (attribute == null) { return(null); } Type typeFromHandle = typeof(TweakableStepSize <>); typeFromHandle = typeFromHandle.MakeGenericType(type); object result = null; if (type.IsPrimitive) { result = Activator.CreateInstance(typeFromHandle, attribute.Size); } else { object obj = null; try { obj = Activator.CreateInstance(type, attribute.Size); } catch (MissingMethodException inner) { throw new StepTweakableInvalidException(tweakableName, "The type '" + type.FullName + "' must have a constructor that takes a single argument of type '" + attribute.Size.GetType().FullName + "'", inner); } catch (MethodAccessException inner2) { throw new StepTweakableInvalidException(tweakableName, "The type '" + type.FullName + "' has the a constructor that takes a single argument of type '" + attribute.Size.GetType().FullName + " but it is not public.", inner2); } if (obj != null) { result = Activator.CreateInstance(typeFromHandle, obj); } } return(result); }