protected Result <Adapter <T> > getAdapter(T entity, string child, Func <DataGroups, string, ISetup> setup) => tryTo(() => { var adapter = adapters.Find(child, an => new Adapter <T>(entity, setup(dataGroups, an)), true); adapter.Entity = entity; return(adapter.Success()); });
protected void initialize() { matcher = new Matcher(); matcher.Must().Match(source, regexInvocation, true, false).OrThrow($"Didn't understand invocation <[{source}]>"); var assemblyName = matcher.FirstGroup; var alias = matcher.SecondGroup; var sign = matcher.ThirdGroup; var typeName = matcher.FourthGroup; var dot = matcher.FifthGroup; member = matcher.SixthGroup; var parameterSource = matcher.SeventhGroup; var invocationMethod = matcher.EighthGroup; var assemblyPresent = assemblyName.IsNotEmpty(); if (assemblyPresent) { Color(index, 1, Structures); Color(assemblyName.Length, Variables); Color(1, Structures); if (alias.IsNotEmpty()) { Color(alias.Length, Variables); Color(sign.Length, Operators); } Color(typeName.Length, Variables); } else if (alias.IsNotEmpty()) { Color(index, alias.Length, Variables); Color(sign.Length, Operators); Color(typeName.Length, Variables); } else { Color(index, typeName.Length, Variables); } Color(1, Structures); Color(member.Length, Messaging); Color(1, Structures); Color(parameterSource.Length, Variables); Color(1, Structures); Color(invocationMethod.Length, Operators); if (!assemblyPresent) { assemblyName = "mscorlib"; } switch (member) { case "new": invocationType = New; bindingFlags = new Bits32 <BindingFlags>(Public); break; default: invocationType = dot == "." ? InvocationType.Instance : InvocationType.Static; bindingFlags = invocationType switch { InvocationType.Instance => BindingFlags.Instance, InvocationType.Static => BindingFlags.Static, _ => bindingFlags }; bindingFlags[Public] = true; switch (invocationMethod) { case "!": bindingFlags[SetProperty] = true; break; case "?": bindingFlags[GetProperty] = true; break; case ".!": bindingFlags[SetField] = true; break; case ".?": bindingFlags[GetField] = true; break; default: bindingFlags[InvokeMethod] = true; break; } break; } if (typeName.StartsWith("#")) { typeName = typeAliases.Find(typeName.Drop(1), _ => ""); } if (alias.IsNotEmpty()) { typeAliases[alias] = typeName; } typeName.Must().Not.BeNullOrEmpty().OrThrow(LOCATION, () => "Couldn't find type"); var fullAssemblyName = typeToAssemblies[typeName]; if (fullAssemblyName != null) { assemblyName = fullAssemblyName; } assembly = assemblies.Find(assemblyName, Assembly.Load); type = assembly.GetType(typeName, false, true); type.Must().Not.BeNull().OrThrow(LOCATION, () => $"Didn't understand .NET type {typeName}"); typeToAssemblies[typeName] = assemblyName; parameters = parameterSource.Split("/s* ',' /s*"); }
public Value Send(Value value, string messageName, Arguments arguments, bool reregister = false) { value.Must().Not.BeNull().OrThrow(LOCATION, () => MSG_NO_MESSAGE_RECIPIENT); arguments.Must().Not.BeNull().OrThrow(LOCATION, () => "No arguments passed in message"); Variable variable; if (value.IsVariable) { variable = (Variable)value; value = variable.MessageTarget(messageName); } else { variable = null; } LastValue = value; var type = value.ContainerType; if (!registeredTypes.Find(type, _ => false) || reregister) { value.RegisterMessages(); registeredTypes[type] = true; } Value result; bool handled; if (messagesUsed.Find(messageName, _ => false)) { var message = messages[MessageKey(value, messageName)]; if (message != null) { value.Arguments = arguments; Regions.Push("message-eval: " + messageName); result = message.Evaluate(value); Regions.Pop("message-eval"); return(result); } } if (variable != null && variable.Name == "super" && Regions["self"] is Object self) { return(self.InvokeSuper(messageName, arguments)); } if (value is IMessageHandler messageHandler) { var handlerResult = messageHandler.Send(value, messageName, arguments, out handled); if (handled) { return(handlerResult); } } result = DefaultSendMessage(value, messageName, arguments, out handled); if (handled) { return(result); } var alternate = value.AlternateValue(messageName); if (value.IsEmpty && variable != null) { variable.Value = alternate; } if (alternate != null) { RegisterMessageCall(messageName); alternate.RegisterMessages(); return(Send(alternate, messageName, arguments)); } throw LOCATION.ThrowsWithLocation(() => $"Didn't understand message {Unmangle(messageName)} sent to <{value}>({value.Type}) " + $"with arguments {arguments}"); }
internal static string getRegex(string source) => friendlyPatterns.Find(source, _ => new Parser().Parse(source), true);