public void RegisterInstance(object instance) { void RegisterInstanceInternal() { Type instanceType = instance.GetType(); KlaxAssembly assembly = instanceType.Assembly.GetCustomAttribute <KlaxAssembly>(); //Register properties foreach (var property in instanceType.GetProperties()) { CVarAttribute attribute = property.GetCustomAttribute <CVarAttribute>(); if (attribute != null) { string name = string.IsNullOrEmpty(attribute.NameOverride) ? (assembly.ConsoleVariablePrefix + property.Name) : attribute.NameOverride; RegisterVariable(name, property.PropertyType, attribute.ValueOverride ?? property.GetValue(instance), property, instance, attribute.Callback != null ? instanceType.GetMethod(attribute.Callback, BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public) : null); } } } if (IsInAuthoritativeThread()) { RegisterInstanceInternal(); } else { Dispatch(EConfigDispatcherPriority.Update, RegisterInstanceInternal); } }
public StaticCVarField(CVarAttribute attribute, FieldInfo fieldInfo) { this.Name = attribute.Name; this.Flags = attribute.Flags; this.Help = attribute.Help; fieldInfo.SetValue(null, attribute.DefaultValue); this.field = fieldInfo; }
public StaticCVarProperty(CVarAttribute attribute, PropertyInfo propertyInfo) { this.Name = attribute.Name; this.Flags = attribute.Flags; this.Help = attribute.Help; this.property.SetValue(null, attribute.DefaultValue, null); this.property = propertyInfo; }
internal static CVar Register(CVarAttribute attribute, MemberInfo memberInfo, string value) { if (attribute.Name == null) { attribute.Name = memberInfo.Name; } Native.ConsoleInterop.RegisterCVarString(attribute.Name, value, (string)attribute.DefaultValue ?? string.Empty, attribute.Flags, attribute.Help); CVar.CVars.Add ( memberInfo.MemberType == MemberTypes.Field ? (CVar) new StaticCVarField(attribute, memberInfo as FieldInfo) : new StaticCVarProperty(attribute, memberInfo as PropertyInfo) ); return(CVars.Last()); }
internal static CVar Register(CVarAttribute attribute, MemberInfo memberInfo, ref float value) { if (attribute.Name == null) { attribute.Name = memberInfo.Name; } Native.ConsoleInterop.RegisterCVarFloat(attribute.Name, ref value, System.Convert.ToSingle(attribute.DefaultValue), attribute.Flags, attribute.Help); CVar.CVars.Add ( memberInfo.MemberType == MemberTypes.Field ? (CVar) new StaticCVarField(attribute, memberInfo as FieldInfo) : new StaticCVarProperty(attribute, memberInfo as PropertyInfo) ); return(CVars.Last()); }
internal static CVar Register(CVarAttribute attribute, MemberInfo memberInfo, string value) { if (attribute.Name == null) attribute.Name = memberInfo.Name; Native.ConsoleInterop.RegisterCVarString(attribute.Name, value, (string)attribute.DefaultValue ?? string.Empty, attribute.Flags, attribute.Help); CVar.CVars.Add ( memberInfo.MemberType == MemberTypes.Field ? (CVar)new StaticCVarField(attribute, memberInfo as FieldInfo) : new StaticCVarProperty(attribute, memberInfo as PropertyInfo) ); return CVars.Last(); }
internal static CVar Register(CVarAttribute attribute, MemberInfo memberInfo, ref float value) { if (attribute.Name == null) attribute.Name = memberInfo.Name; Native.ConsoleInterop.RegisterCVarFloat(attribute.Name, ref value, System.Convert.ToSingle(attribute.DefaultValue), attribute.Flags, attribute.Help); CVar.CVars.Add ( memberInfo.MemberType == MemberTypes.Field ? (CVar)new StaticCVarField(attribute, memberInfo as FieldInfo) : new StaticCVarProperty(attribute, memberInfo as PropertyInfo) ); return CVars.Last(); }