using Robust.Client.UserInterface; namespace Content.Client.Stylesheets; public abstract partial class BaseStylesheet { public StyleRule[] GetSheetletRules(Type sheetletTy, StylesheetManager man) { Sheetlet? sheetlet = null; try { if (sheetletTy.ContainsGenericParameters) { if (SandboxHelper.CreateInstance(sheetletTy.MakeGenericType(typeof(TSheetTy))) is Sheetlet sheetlet1) sheetlet = sheetlet1; } else if (SandboxHelper.CreateInstance(sheetletTy) is Sheetlet sheetlet2) { sheetlet = sheetlet2; } } // thrown when `sheetletTy.MakeGenericType` is given a type that does not satisfy the type constraints of // `sheetletTy` catch (ArgumentException) { } if (sheetlet is not null) { man.UnusedSheetlets.Remove(sheetletTy); return sheetlet.GetRules((TSheetTy)(object)this, _config); } else return []; } public StyleRule[] GetAllSheetletRules(StylesheetManager man) where TAttrib : Attribute { var tys = ReflectionManager.FindTypesWithAttribute(); var rules = new List(); foreach (var ty in tys) { rules.AddRange(GetSheetletRules(ty, man)); } return rules.ToArray(); } }