public SyncField(Type targetType, string memberPath) { this.targetType = targetType; this.memberPath = targetType + "/" + memberPath; fieldType = MpReflection.PathType(this.memberPath); indexType = MpReflection.IndexType(this.memberPath); }
public SyncMethod(Type targetType, string instancePath, string methodName, SyncType[] argTypes) { this.targetType = targetType; Type instanceType = targetType; if (!instancePath.NullOrEmpty()) { this.instancePath = instanceType + "/" + instancePath; instanceType = MpReflection.PathType(this.instancePath); } method = AccessTools.Method(instanceType, methodName, argTypes?.Select(t => t.type).ToArray()) ?? throw new Exception($"Couldn't find method {instanceType}::{methodName}"); this.argTypes = CheckArgs(argTypes); }
public SyncDelegate(Type delegateType, MethodInfo method, string[] fieldPaths) { this.delegateType = delegateType; this.method = method; argTypes = method.GetParameters().Types(); if (fieldPaths == null) { List <string> fieldList = new List <string>(); Sync.AllDelegateFieldsRecursive(delegateType, path => { fieldList.Add(path); return(false); }); this.fieldPaths = fieldList.ToArray(); } else { var temp = new UniqueList <string>(); foreach (string path in fieldPaths.Select(p => MpReflection.AppendType(p, delegateType))) { string[] parts = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); string increment = parts[0] + "/" + parts[1]; for (int i = 2; i < parts.Length; i++) { if (!MpReflection.PathType(increment).IsCompilerGenerated()) { break; } temp.Add(increment); increment += "/" + parts[i]; } temp.Add(path); } this.fieldPaths = temp.ToArray(); } fieldTypes = this.fieldPaths.Select(path => MpReflection.PathType(path)).ToArray(); }
public SyncDelegate(Type delegateType, MethodInfo method, string[] inPaths) : base(delegateType, null, method, null) { if (inPaths == null) { List <string> fieldList = new List <string>(); AllDelegateFieldsRecursive(delegateType, path => { fieldList.Add(path); return(false); }); fieldPaths = fieldList.ToArray(); } else { var temp = new UniqueList <string>(); foreach (string path in inPaths.Select(p => MpReflection.AppendType(p, delegateType))) { string[] parts = path.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries); string increment = parts[0] + "/" + parts[1]; for (int i = 2; i < parts.Length; i++) { if (!MpReflection.PathType(increment).IsCompilerGenerated()) { break; } temp.Add(increment); increment += "/" + parts[i]; } temp.Add(path); } fieldPaths = temp.ToArray(); } fieldTypes = fieldPaths.Select(path => MpReflection.PathType(path)).ToArray(); fieldPathsNoTypes = fieldPaths.Select(path => MpReflection.RemoveType(path)).ToArray(); fieldTransformers = new SyncTransformer[fieldTypes.Length]; }