public void ProcessMember(MemberInfo memberInfo, Type type, IBoundInstance instance = null) { if (!CheckAlreadyProcessed(memberInfo.ReflectedType.FullName + memberInfo.Name, instance)) { DoProcessMember(memberInfo, type, instance); } }
public void ProcessAttribute(TweakableAttribute input, MemberInfo memberInfo, IBoundInstance instance = null) { ITweakable tweakable = null; AutoTweakableResult autoTweakableResult = null; if (memberInfo.MemberType == MemberTypes.Field) { FieldInfo fieldInfo = (FieldInfo)memberInfo; if (fieldInfo.FieldType.IsSubclassOf(typeof(AutoTweakable))) { AutoTweakable instance2 = fieldInfo.GetValue(instance.Instance) as AutoTweakable; FieldInfo field = fieldInfo.FieldType.GetField("value", BindingFlags.Instance | BindingFlags.Public); IBoundInstance boundInstance = BoundInstanceFactory.Create(instance2, instance.UniqueId); tweakable = TweakableFactory.MakeTweakable(input, field, boundInstance, memberInfo); autoTweakableResult = new AutoTweakableResult(); autoTweakableResult.autoTweakable = boundInstance.Instance as AutoTweakable; autoTweakableResult.tweakble = tweakable; autoTweakableResult.uniqueId = boundInstance.UniqueId; } if (autoTweakableResult != null) { ProvideResult(autoTweakableResult); } return; } throw new ProcessorException("AutoTweakableProcessor cannot process non FieldInfo types"); }
public void ProcessAttribute(Attribute attribute, Type type, IBoundInstance instance = null) { if (!CheckAlreadyProcessed(attribute.GetType().FullName + type.FullName, instance)) { DoProcessAttribute(attribute, type, instance); } }
public void ProcessType(Type type, IBoundInstance instance = null) { if (this.ResultProvided != null) { this.ResultProvided(this, new ScanResultArgs <CustomSerializerResult>(new CustomSerializerResult(type))); } }
public void ProcessType(Type type, IBoundInstance instance = null) { if (!CheckAlreadyProcessed(type.FullName, instance)) { DoProcessType(type, instance); } }
public void ProcessAttribute(Attribute attribute, MemberInfo memberInfo, IBoundInstance instance = null) { if (!CheckAlreadyProcessed(attribute.GetType().FullName + memberInfo.ReflectedType.FullName + memberInfo.Name, instance)) { DoProcessAttribute(attribute, memberInfo, instance); } }
private static string GetFinalName(string name, IBoundInstance instance) { if (instance == null) { return(name); } return($"{name}#{instance.UniqueId}"); }
public AutoInvokable(string name, Delegate del, IBoundInstance instance = null, string description = "", string[] argDescriptions = null, string returnDescription = "") { if (CheckForManager()) { uint num = instance?.UniqueId ?? 0; string name2 = $"{name}#{num}"; invokable = AutoInvokableBase.Manager.RegisterInvokable(new InvokableInfo(name2, num, CustomTweakerAttributes.Get(del.Method), description, argDescriptions, returnDescription), del); } }
public IBoundInstance ScanInstance(object instance, ScanOptions options = null) { if (instance == null) { throw new ArgumentNullException("instance", "Cannot scan null instance."); } IBoundInstance result = BoundInstanceFactory.Create(instance); ScanType(instance.GetType(), result, options); return(result); }
public void ProcessAttribute(InvokableAttribute input, Type type, IBoundInstance instance = null) { MemberInfo[] members = type.GetMembers(ReflectionUtil.GetBindingFlags(instance)); foreach (MemberInfo memberInfo in members) { if ((memberInfo.MemberType == MemberTypes.Method || memberInfo.MemberType == MemberTypes.Event) && memberInfo.GetCustomAttributes(typeof(InvokableAttribute), inherit: false).Length == 0) { InvokableAttribute input2 = new InvokableAttribute(input.Name + "." + memberInfo.Name); ProcessAttribute(input2, memberInfo, instance); } } }
private bool CheckAlreadyProcessed(object obj, IBoundInstance instance) { if (instance != null) { return(false); } if (!processedObjects.Contains(obj)) { processedObjects.Add(obj); return(false); } return(true); }
public AutoInvokable(string invokableName, string methodName, IBoundInstance instance, string description = "", string[] argDescriptions = null, string returnDescription = "") { if (!CheckForManager()) { return; } MethodInfo[] methods = instance.Type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); foreach (MethodInfo methodInfo in methods) { if (methodInfo.Name == methodName) { uint uniqueId = instance.UniqueId; string name = $"{invokableName}#{uniqueId}"; invokable = AutoInvokableBase.Manager.RegisterInvokable(new InvokableInfo(name, uniqueId, CustomTweakerAttributes.Get(methodInfo), description, argDescriptions, returnDescription), methodInfo, instance.Instance); } } }
public void ScanAttribute(Attribute attribute, object reflectedObject, IBoundInstance instance, ScanOptions options = null) { Type type = attribute.GetType(); if (!processors.ContainsKey(type)) { return; } List <BaseProcessorWrapper> list = processors[type]; foreach (BaseProcessorWrapper item in list) { if (reflectedObject is MemberInfo) { item.ProcessAttribute(attribute, (MemberInfo)reflectedObject, instance); } else if (reflectedObject is Type) { item.ProcessAttribute(attribute, (Type)reflectedObject, instance); } } }
public void ProcessAttribute(TweakableAttribute input, Type type, IBoundInstance instance = null) { try { MemberInfo[] members = type.GetMembers(ReflectionUtil.GetBindingFlags(instance)); foreach (MemberInfo memberInfo in members) { if ((memberInfo.MemberType == MemberTypes.Property || memberInfo.MemberType == MemberTypes.Field) && memberInfo.GetCustomAttributes(typeof(TweakableAttribute), inherit: false).Length == 0) { TweakableAttribute input2 = new TweakableAttribute(input.Name + "." + memberInfo.Name); ProcessAttribute(input2, memberInfo, instance); } } } catch (ProcessorException) { throw; } catch (Exception ex2) { Log.LogException(this, ex2); } }
public void ScanType(Type type, IBoundInstance instance, ScanOptions options = null) { try { BindingFlags bindingFlags = BindingFlags.Public | BindingFlags.NonPublic; bindingFlags = ((options != null && options.ScanStaticAndInstanceMembers) ? (bindingFlags | (BindingFlags.Instance | BindingFlags.Static)) : ((instance != null) ? (bindingFlags | BindingFlags.Instance) : (bindingFlags | BindingFlags.Static))); MemberInfo[] members = type.GetMembers(bindingFlags); MemberInfo[] array = members; foreach (MemberInfo member in array) { if (options == null || options.CheckMatch(member)) { ScanMember(member, instance, options); } } if (options != null && !options.CheckMatch(type)) { return; } foreach (Type key in processors.Keys) { if (!type.IsSubclassOf(key)) { continue; } List <BaseProcessorWrapper> list = processors[key]; foreach (BaseProcessorWrapper item in list) { item.ProcessType(type, instance); } } } catch (TypeLoadException) { } }
public void ScanMember(MemberInfo member, IBoundInstance instance, ScanOptions options = null) { object[] customAttributes = member.GetCustomAttributes(inherit: false); foreach (object obj in customAttributes) { Attribute attribute = obj as Attribute; if ((options == null || options.CheckMatch(attribute)) && member.MemberType != MemberTypes.NestedType) { ScanAttribute(attribute, member, instance, options); } } Type baseType = member.GetType().BaseType; if (!processors.ContainsKey(baseType)) { return; } List <BaseProcessorWrapper> list = processors[baseType]; foreach (BaseProcessorWrapper item in list) { item.ProcessMember(member, member.ReflectedType, instance); } }
protected virtual void DoProcessAttribute(Attribute attribute, Type type, IBoundInstance instance = null) { }
public void ScanGenericType(Type type, IBoundInstance instance, ScanOptions options = null) { }
public void ProcessAttribute(TweakableAttribute input, MemberInfo memberInfo, IBoundInstance instance = null) { ITweakable tweakable = null; try { if (memberInfo.MemberType == MemberTypes.Property) { PropertyInfo propertyInfo = (PropertyInfo)memberInfo; tweakable = TweakableFactory.MakeTweakable(input, propertyInfo, instance); } else { if (memberInfo.MemberType != MemberTypes.Field) { throw new ProcessorException("TweakableProcessor cannot process non PropertyInfo or FieldInfo types"); } FieldInfo fieldInfo = (FieldInfo)memberInfo; tweakable = TweakableFactory.MakeTweakable(input, fieldInfo, instance); } } catch (ProcessorException) { throw; } catch (Exception ex2) { Log.LogException(this, ex2); } if (tweakable != null) { ProvideResult(tweakable); } }
public void ProcessAttribute(InvokableAttribute input, MemberInfo memberInfo, IBoundInstance instance = null) { IInvokable invokable = null; if (memberInfo.MemberType == MemberTypes.Method) { MethodInfo methodInfo = (MethodInfo)memberInfo; invokable = InvokableFactory.MakeInvokable(input, methodInfo, instance); } else { if (memberInfo.MemberType != MemberTypes.Event) { throw new ProcessorException("InvokableProcessor cannot process non MethodInfo or EventInfo types"); } EventInfo eventInfo = (EventInfo)memberInfo; invokable = InvokableFactory.MakeInvokable(input, eventInfo, instance); } if (invokable != null) { ProvideResult(invokable); } }
public static ITweakable MakeTweakable(TweakableAttribute attribute, PropertyInfo propertyInfo, IBoundInstance instance, MemberInfo containerMemberInfo = null) { return(MakeTweakable(attribute, propertyInfo.PropertyType, propertyInfo, instance, containerMemberInfo)); }
public static ITweakable MakeTweakable(TweakableAttribute attribute, FieldInfo fieldInfo, IBoundInstance instance, MemberInfo containerMemberInfo = null) { return(MakeTweakable(attribute, fieldInfo.FieldType, fieldInfo, instance, containerMemberInfo)); }
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); }
protected override void DoProcessAttribute(Attribute attribute, MemberInfo memberInfo, IBoundInstance instance = null) { (Processor as IAttributeScanProcessor <TInput, TResult>)?.ProcessAttribute(attribute as TInput, memberInfo, instance); }
protected override void DoProcessAttribute(Attribute attribute, Type type, IBoundInstance instance = null) { (Processor as IAttributeScanProcessor <TInput, TResult>)?.ProcessAttribute(attribute as TInput, type, instance); }
protected virtual void DoProcessType(Type type, IBoundInstance instance = null) { }
protected virtual void DoProcessAttribute(Attribute attribute, MemberInfo memberInfo, IBoundInstance instance = null) { }
protected override void DoProcessType(Type type, IBoundInstance instance = null) { (Processor as ITypeScanProcessor <TInput, TResult>)?.ProcessType(type, instance); }
protected virtual void DoProcessMember(MemberInfo memberInfo, Type type, IBoundInstance instance = null) { }
protected override void DoProcessMember(MemberInfo memberInfo, Type type, IBoundInstance instance = null) { (Processor as IMemberScanProcessor <TInput, TResult>)?.ProcessMember(memberInfo as TInput, type, instance); }