protected override void Ready() { Receive <GetAllTypesMessage>(r => { Console.WriteLine("WORKING"); var self = Self; var sender = Sender; Task.Run <IEnumerable <TypeDescriptor> >(() => { var assembly = Assembly.LoadFrom(r.AssemblyLocation); return(assembly.GetTypes() .Select(t => TypeDescriptor.Create(t)) .ToList()); }, CancellationToken) .ContinueWith <object>(x => { if (x.IsCanceled) { return(new CanceledMessage()); } if (x.IsFaulted) { // https://github.com/akkadotnet/akka.net/issues/1409 // -> exceptions are currently not serializable in raw version //return x.Exception; return(new FailedMessage { Error = x.Exception.Dump() }); } return(new AllTypesMessage { Types = x.Result }); }, TaskContinuationOptions.ExecuteSynchronously) .PipeTo(self, sender); Become(Working); }); }
/// <summary> /// Handles the return value of adapter. /// </summary> /// <param name="adapterCall">The adapter call.</param> /// <returns>Expression.</returns> private Expression handleReturn(MethodCallExpression adapterCall) { var returnType = adapterCall.Method.ReturnType; if (returnType == typeof(void)) { //there is no need for unwrapping logic return(adapterCall); } var needReturnUnWrapping = returnType == typeof(InstanceWrap); Expression returnValue = adapterCall; if (needReturnUnWrapping) { //Wrapped instance has been returned - unwrap it returnValue = Expression.Call(typeof(MethodBuilder).GetMethod("unwrap", BindingFlags.NonPublic | BindingFlags.Static), returnValue); } else { //Direct object has been returned - create its direct instance var machine = Expression.PropertyOrField(_contextParam, "Machine"); if (returnType.IsArray) { var arrayWrapType = typeof(Array <InstanceWrap>); var arrayWrapCtor = arrayWrapType.GetConstructor(new Type[] { typeof(IEnumerable), _contextType }); returnValue = Expression.New(arrayWrapCtor, returnValue, _contextParam); } if (!typeof(Instance).IsAssignableFrom(returnType)) { //Instance needs to be converted to direct instance var instanceInfo = Expression.Constant(TypeDescriptor.Create(returnType)); returnValue = Expression.Convert(returnValue, typeof(object)); returnValue = Expression.Call(machine, typeof(Machine).GetMethod("CreateDirectInstance"), returnValue, instanceInfo); } } //return value is reported via Context.Return call return(Expression.Call(_contextParam, _contextType.GetMethod("Return"), returnValue)); }
public void Partition_sequence_values_only() { var expected = new[] { Token.Name("seq"), Token.Value("seqval0"), Token.Value("seqval1") }; var tokens = TokenPartitioner.PartitionTokensByType( new[] { Token.Name("seq"), Token.Value("seqval0"), Token.Value("seqval1") }, name => new[] { "seq" }.Contains(name) ? Maybe.Just(TypeDescriptor.Create(TargetType.Sequence, Maybe.Nothing <int>())) : Maybe.Nothing <TypeDescriptor>()); var result = tokens.Item3; // Switch, Scalar, *Sequence*, NonOption expected.Should().BeEquivalentTo(result); }
private object findMetaData(InstanceInfo getterType, IEnumerable <object> metaData, bool isMultiple) { if (metaData == null) { return(null); } int metaDataCount = 0; foreach (var item in metaData) { ++metaDataCount; if (item == null) { //null is not supported metadata info return(null); } var typeInfo = TypeDescriptor.Create(item.GetType()); if (!testTypeArrayMatch(typeInfo, getterType, isMultiple)) { //not matching type return(null); } } if (metaDataCount != 1 && !isMultiple) { //metadata item is not multiple - we cannot load //multiple matching data return(null); } if (!isMultiple) { return(metaData.First()); } return(metaData.ToArray()); }
/// <summary> /// Gets the chain. /// </summary> /// <param name="type">The type.</param> /// <returns>InheritanceChain.</returns> internal InheritanceChain GetChain(Type type) { if (type == null) { return(null); } var path = new PathInfo(type); InheritanceChain existingChain; if (_inheritanceChains.TryGetValue(path.Signature, out existingChain)) { return(existingChain); } //we have to create new chain var subChains = new List <InheritanceChain>(); var baseChain = GetChain(type.BaseType); if (baseChain != null) { subChains.Add(baseChain); } foreach (var iface in type.GetInterfaces()) { var subChain = GetChain(iface); if (subChain != null) { subChains.Add(subChain); } } var info = TypeDescriptor.Create(type); var createdChain = new InheritanceChain(info, subChains); _inheritanceChains.Add(createdChain.Path.Signature, createdChain); return(createdChain); }
public void Partition_sequence_values() { var expected = new[] { Token.Name("seq"), Token.Value("seqval0"), Token.Value("seqval1") }; var result = Sequence.Partition( new[] { Token.Name("str"), Token.Value("strvalue"), Token.Value("freevalue"), Token.Name("seq"), Token.Value("seqval0"), Token.Value("seqval1"), Token.Name("x"), Token.Value("freevalue2") }, name => new[] { "seq" }.Contains(name) ? Maybe.Just(TypeDescriptor.Create(TargetType.Sequence, Maybe.Nothing <int>())) : Maybe.Nothing <TypeDescriptor>()); expected.Should().BeEquivalentTo(result); }
public void Partition_sequence_multi_instance_with_max() { var incorrect = new[] { Token.Name("seq"), Token.Value("seqval0"), Token.Value("seqval1"), Token.Value("seqval2"), Token.Value("seqval3"), Token.Value("seqval4"), Token.Value("seqval5"), }; var expected = new[] { Token.Name("seq"), Token.Value("seqval0"), Token.Value("seqval1"), Token.Value("seqval2"), }; var tokens = TokenPartitioner.PartitionTokensByType( new[] { Token.Name("str"), Token.Value("strvalue"), Token.Value("freevalue"), Token.Name("seq"), Token.Value("seqval0"), Token.Value("seqval1"), Token.Name("x"), Token.Value("freevalue2"), Token.Name("seq"), Token.Value("seqval2"), Token.Value("seqval3"), Token.Name("seq"), Token.Value("seqval4"), Token.Value("seqval5"), }, name => new[] { "seq" }.Contains(name) ? Maybe.Just(TypeDescriptor.Create(TargetType.Sequence, Maybe.Just <int>(3))) : Maybe.Nothing <TypeDescriptor>()); var result = tokens.Item3; // Switch, Scalar, *Sequence*, NonOption // Max of 3 will apply to the total values, so there should only be 3 values, not 6 Assert.NotEqual(incorrect, result); Assert.Equal(expected, result); }
public SimpleAssemblyProvider(string testFileFullPath) { //uchováme cestu k "definujícímu" souboru _fullPath = testFileFullPath; //jméno assembly odvodíme od názvu souboru _name = Path.GetFileName(_fullPath); //připravíme kontejner kam vložíme definovanou metodu _methods = new HashedMethodContainer(); //vytvoření metody začneme přípravou typu, kde je definovaná _declaringType = TypeDescriptor.Create("MEFEditor.ProviderTest"); //určíme jméno metody var methodName = "GetDefiningAssemblyName"; //návratový typ metody var returnType = TypeDescriptor.Create <string>(); //z definovaných údajů můžeme vytvořit popis //metody, která nebude mít žádné parametry a bude statická var methodInfo = new TypeMethodInfo( _declaringType, methodName, returnType, ParameterTypeInfo.NoParams, isStatic: true, methodTypeArguments: TypeDescriptor.NoDescriptors); //k dokončení definice metody stačí vytvořit //generátor jejích analyzačních instrukcí var methodGenerator = new DirectedGenerator(emitDirector); //definovanou metodu vytvoříme var method = new MethodItem(methodGenerator, methodInfo); //aby byla metoda dohledatelná, musíme ji ještě zaregistrovat _methods.AddItem(method); }
/// <summary> /// Get type descriptor available for given type /// </summary> /// <param name="type">Type which descriptor is recieved</param> /// <returns>Type descriptor</returns> private TypeDescriptor getDescriptor(Type type) { return(TypeDescriptor.Create(type)); }
/// <summary> /// Gets type descriptor from given <see cref="Type"/>. /// </summary> /// <param name="type">The type.</param> /// <returns>Type descriptor.</returns> internal virtual InstanceInfo GetInstanceInfo(Type type) { return(TypeDescriptor.Create(type)); }
/// <summary> /// Initializes a new instance of the <see cref="ReturnTypeAttribute"/> class. /// </summary> /// <param name="returnTypeFullname">Fullname of return type.</param> public ReturnTypeAttribute(string returnTypeFullname) { ReturnInfo = TypeDescriptor.Create(returnTypeFullname); }
/// <summary> /// Initializes a new instance of the <see cref="ReturnTypeAttribute"/> class. /// </summary> /// <param name="returnType">Type of the return value.</param> public ReturnTypeAttribute(Type returnType) { ReturnInfo = TypeDescriptor.Create(returnType); }
public static void AssertName <T>(string typeName) { var info = TypeDescriptor.Create <T>(); Assert.AreEqual(typeName, info.TypeName); }
/// <summary> /// Adds the binary predicate. /// </summary> /// <param name="methodName">Name of the operator method.</param> /// <param name="directOperator">The direct operator.</param> private void addBinaryPredicate(string methodName, DirectMethod directOperator) { var method = binaryInfo(methodName, TypeDescriptor.Create <bool>()); AddMethod(directOperator, method); }
/// <summary> /// Create default arguments /// </summary> /// <param name="machine">Machine used for arguments creation</param> /// <returns>Created arguments</returns> private IEnumerable <Instance> getDefaultArguments(Machine machine) { yield return(machine.CreateInstance(TypeDescriptor.Create(Method.EntryClass))); }
private static TypeDescriptor descriptorFromFullName(string fullname) { return(TypeDescriptor.Create(fullname)); }
/// <summary> /// Initializes a new instance of the <see cref="ParameterTypesAttribute"/> class. /// </summary> /// <param name="parameterTypes">The method definition parameter types.</param> public ParameterTypesAttribute(params string[] parameterTypes) { ParameterTypes = from parameterType in parameterTypes select TypeDescriptor.Create(parameterType); }