Skip to content

Commit c1bd399

Browse files
Update CSharpPlugin constructor
1 parent f615ed8 commit c1bd399

2 files changed

Lines changed: 43 additions & 33 deletions

File tree

src/CSharpPlugin.cs

Lines changed: 42 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -222,48 +222,58 @@ public CSharpPlugin()
222222
timer = new PluginTimers(this);
223223

224224
Type type = GetType();
225-
foreach (MemberInfo member in type.GetMembers(BindingFlags.NonPublic | BindingFlags.Instance))
225+
MemberInfo[] members = type.GetMembers(BindingFlags.NonPublic | BindingFlags.Instance);
226+
int memberCount = members.Length;
227+
for (int i = 0; i < memberCount; i++)
226228
{
227-
if (member.MemberType == MemberTypes.Property || member.MemberType == MemberTypes.Field)
229+
MemberInfo member = members[i];
230+
switch (member.MemberType)
228231
{
229-
if (member.MemberType == MemberTypes.Property)
232+
case MemberTypes.Property or MemberTypes.Field:
230233
{
231-
PropertyInfo property = member as PropertyInfo;
232-
if (!property.CanWrite)
234+
if (member.MemberType == MemberTypes.Property)
233235
{
234-
continue;
236+
PropertyInfo property = (PropertyInfo)member;
237+
if (!property.CanWrite)
238+
{
239+
continue;
240+
}
241+
}
242+
else
243+
{
244+
// FieldInfo field = member as FieldInfo;
235245
}
236-
}
237-
else
238-
{
239-
FieldInfo field = member as FieldInfo;
240-
}
241246

242-
object[] reference_attributes = member.GetCustomAttributes(typeof(PluginReferenceAttribute), true);
247+
object[] referenceAttributes = member.GetCustomAttributes(typeof(PluginReferenceAttribute), true);
248+
if (referenceAttributes.Length > 0)
249+
{
250+
PluginReferenceAttribute pluginReference = (PluginReferenceAttribute)referenceAttributes[0];
251+
pluginReferenceMembers[pluginReference.Name ?? member.Name] = member;
252+
}
243253

244-
if (reference_attributes.Length > 0)
245-
{
246-
PluginReferenceAttribute pluginReference = reference_attributes[0] as PluginReferenceAttribute;
247-
pluginReferenceMembers[pluginReference.Name ?? member.Name] = member;
254+
break;
248255
}
249-
}
250-
else if (member.MemberType == MemberTypes.Method)
251-
{
252-
MethodInfo method = member as MethodInfo;
253-
object[] info_attributes = method.GetCustomAttributes(typeof(HookMethodAttribute), true);
254-
if (info_attributes.Length > 0)
256+
case MemberTypes.Method:
255257
{
256-
continue;
257-
}
258+
MethodInfo method = (MethodInfo)member;
259+
object[] hookMethodAttributes = method.GetCustomAttributes(typeof(HookMethodAttribute), true);
260+
if (hookMethodAttributes.Length > 0)
261+
{
262+
continue;
263+
}
258264

259-
if (method.Name.Equals("OnFrame"))
260-
{
261-
HookedOnFrame = true;
262-
}
263-
// Assume all private instance methods which are not explicitly hooked could be hooks
264-
if (method.DeclaringType.Name == type.Name)
265-
{
266-
AddHookMethod(method.Name, method);
265+
if (method.Name.Equals("OnFrame"))
266+
{
267+
HookedOnFrame = true;
268+
}
269+
270+
// Assume all private instance methods which are not explicitly hooked could be hooks
271+
if (method.DeclaringType.Name == type.Name)
272+
{
273+
AddHookMethod(method.Name, method);
274+
}
275+
276+
break;
267277
}
268278
}
269279
}

src/CompilerStream/CompilerData.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ public class CompilerData
1010
public bool LoadDefaultReferences { get; set; }
1111
public string OutputFile { get; set; }
1212
public CompilerPlatform Platform { get; set; }
13+
public List<CompilerFile> SourceFiles { get; set; }
1314
public CompilerFile[] ReferenceFiles { get; set; }
1415
public string SdkVersion { get; set; }
15-
public List<CompilerFile> SourceFiles { get; set; }
1616
public bool StdLib { get; set; }
1717
public CompilerTarget Target { get; set; }
1818
public CompilerLanguageVersion Version { get; set; }

0 commit comments

Comments
 (0)