Applies 1 prop with name on the target.
147 {
148 if (target.Unreal) return;
149
150 if (target == null) { CUI.Warning($"Style target is null"); return; }
151
152 meta ??= CUITypeMetaData.Get(target.GetType());
153
154 PropertyInfo pi = meta.Assignable.GetValueOrDefault(name);
155
156 if (pi == null)
157 {
158 if (CUIPalette.NotifyExcessivePropStyles) CUI.Warning($"Can't apply style: Couldn't find {name} prop in {target}");
159
160 return;
161 }
162
163 string raw = style[name];
164
165 if (raw.StartsWith(CUIPalettePrefix))
166 {
167 PaletteExtractResult result = CUIPalette.Extract(raw.Substring(CUIPalettePrefix.Length), target.Palette);
168 if (result.Ok)
169 {
170 raw = result.Value;
171 }
172 else
173 {
174 if (CUIPalette.NotifiMissingPropStyles)
175 {
176 CUI.Warning($"Can't find {raw.Substring(CUIPalettePrefix.Length)} palette style for {target}");
177 }
178 return;
179 }
180 }
181
182 MethodInfo parse = CUIExtensions.Parse.GetValueOrDefault(pi.PropertyType);
183
184 parse ??= pi.PropertyType.GetMethod(
185 "Parse",
186 BindingFlags.Public | BindingFlags.Static,
187 new Type[] { typeof(string) }
188 );
189
190 if (parse == null)
191 {
192 CUI.Warning($"Can't parse style prop {name} for {target} because it's type {pi.PropertyType.Name} is missing Parse method");
193 return;
194 }
195
196 try
197 {
198 pi.SetValue(target, parse.Invoke(null, new object[] { raw }));
199 }
200 catch (Exception e)
201 {
202 CUI.Warning($"Can't parse {raw} into {pi.PropertyType.Name} for {target}");
203 CUI.Warning(e);
204 }
205 }