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); }
private static object MakeTweakableRange(Type type, TweakerRangeAttribute attribute) { if (attribute == null) { return(null); } Type typeFromHandle = typeof(TweakableRange <>); typeFromHandle = typeFromHandle.MakeGenericType(type); return(Activator.CreateInstance(typeFromHandle, attribute.MinValue, attribute.MaxValue)); }
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); }