Esempio n. 1
0
 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");
        }
Esempio n. 3
0
 public void ProcessAttribute(Attribute attribute, Type type, IBoundInstance instance = null)
 {
     if (!CheckAlreadyProcessed(attribute.GetType().FullName + type.FullName, instance))
     {
         DoProcessAttribute(attribute, type, instance);
     }
 }
Esempio n. 4
0
 public void ProcessType(Type type, IBoundInstance instance = null)
 {
     if (this.ResultProvided != null)
     {
         this.ResultProvided(this, new ScanResultArgs <CustomSerializerResult>(new CustomSerializerResult(type)));
     }
 }
Esempio n. 5
0
 public void ProcessType(Type type, IBoundInstance instance = null)
 {
     if (!CheckAlreadyProcessed(type.FullName, instance))
     {
         DoProcessType(type, instance);
     }
 }
Esempio n. 6
0
 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);
     }
 }
Esempio n. 7
0
 private static string GetFinalName(string name, IBoundInstance instance)
 {
     if (instance == null)
     {
         return(name);
     }
     return($"{name}#{instance.UniqueId}");
 }
Esempio n. 8
0
 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);
     }
 }
Esempio n. 9
0
        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);
        }
Esempio n. 10
0
 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);
         }
     }
 }
Esempio n. 11
0
 private bool CheckAlreadyProcessed(object obj, IBoundInstance instance)
 {
     if (instance != null)
     {
         return(false);
     }
     if (!processedObjects.Contains(obj))
     {
         processedObjects.Add(obj);
         return(false);
     }
     return(true);
 }
Esempio n. 12
0
 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);
         }
     }
 }
Esempio n. 13
0
        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);
                }
            }
        }
Esempio n. 14
0
 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);
     }
 }
Esempio n. 15
0
 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)
     {
     }
 }
Esempio n. 16
0
        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);
            }
        }
Esempio n. 17
0
 protected virtual void DoProcessAttribute(Attribute attribute, Type type, IBoundInstance instance = null)
 {
 }
Esempio n. 18
0
 public void ScanGenericType(Type type, IBoundInstance instance, ScanOptions options = null)
 {
 }
Esempio n. 19
0
        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);
            }
        }
Esempio n. 20
0
        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);
            }
        }
Esempio n. 21
0
 public static ITweakable MakeTweakable(TweakableAttribute attribute, PropertyInfo propertyInfo, IBoundInstance instance, MemberInfo containerMemberInfo = null)
 {
     return(MakeTweakable(attribute, propertyInfo.PropertyType, propertyInfo, instance, containerMemberInfo));
 }
Esempio n. 22
0
 public static ITweakable MakeTweakable(TweakableAttribute attribute, FieldInfo fieldInfo, IBoundInstance instance, MemberInfo containerMemberInfo = null)
 {
     return(MakeTweakable(attribute, fieldInfo.FieldType, fieldInfo, instance, containerMemberInfo));
 }
Esempio n. 23
0
        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);
        }
Esempio n. 24
0
 protected override void DoProcessAttribute(Attribute attribute, MemberInfo memberInfo, IBoundInstance instance = null)
 {
     (Processor as IAttributeScanProcessor <TInput, TResult>)?.ProcessAttribute(attribute as TInput, memberInfo, instance);
 }
Esempio n. 25
0
 protected override void DoProcessAttribute(Attribute attribute, Type type, IBoundInstance instance = null)
 {
     (Processor as IAttributeScanProcessor <TInput, TResult>)?.ProcessAttribute(attribute as TInput, type, instance);
 }
Esempio n. 26
0
 protected virtual void DoProcessType(Type type, IBoundInstance instance = null)
 {
 }
Esempio n. 27
0
 protected virtual void DoProcessAttribute(Attribute attribute, MemberInfo memberInfo, IBoundInstance instance = null)
 {
 }
Esempio n. 28
0
 protected override void DoProcessType(Type type, IBoundInstance instance = null)
 {
     (Processor as ITypeScanProcessor <TInput, TResult>)?.ProcessType(type, instance);
 }
Esempio n. 29
0
 protected virtual void DoProcessMember(MemberInfo memberInfo, Type type, IBoundInstance instance = null)
 {
 }
Esempio n. 30
0
 protected override void DoProcessMember(MemberInfo memberInfo, Type type, IBoundInstance instance = null)
 {
     (Processor as IMemberScanProcessor <TInput, TResult>)?.ProcessMember(memberInfo as TInput, type, instance);
 }