public static GenericReferenceType ( |
||
definition | ||
Résultat |
internal static TypeDefinition GetDelegateTypeDefinition(TypeDefinition returnType, TypeDefinition[] parameterTypes) { var typeDefinition = FindDelegateType(returnType, parameterTypes); return (returnType.TryGetRuntimeType() == typeof(void) ? parameterTypes.Length == 0 ? typeDefinition : TypeDefinition.GenericReferenceType(typeDefinition, parameterTypes) : TypeDefinition.GenericReferenceType(typeDefinition, parameterTypes.Concat(new[] { returnType }).ToArray())); }
private IEnumerable <TConstruct> EmitCollectionUnpackFromStatements(TContext context, Type instanceType, PolymorphismSchema schema, bool isAsync) { // Header check yield return (this.CollectionTraits.CollectionType == CollectionKind.Array ? this.EmitCheckIsArrayHeaderExpression(context, context.Unpacker) : this.EmitCheckIsMapHeaderExpression(context, context.Unpacker)); var itemsCount = this.DeclareLocal(context, typeof(int), "itemsCount"); // Unpack items count and store it yield return(itemsCount); yield return (this.EmitStoreVariableStatement( context, itemsCount, this.EmitGetItemsCountExpression(context, context.Unpacker) )); var createInstance = this.EmitInvokeMethodExpression( context, this.EmitThisReferenceExpression(context), context.GetDeclaredMethod(MethodName.CreateInstance), itemsCount ); var collection = instanceType == this.TargetType ? createInstance : this.EmitUnboxAnyExpression(context, instanceType, createInstance); // Get delegates to UnpackHelpers TConstruct iterative; TConstruct bulk; if (this.CollectionTraits.CollectionType == CollectionKind.Array && this.CollectionTraits.AddMethod == null) { // Try to use concrete collection's Add. var traitsOfTheCollection = instanceType.GetCollectionTraits(CollectionTraitOptions.Full, context.SerializationContext.CompatibilityOptions.AllowNonCollectionEnumerableTypes); bulk = this.MakeNullLiteral( context, #if FEATURE_TAP isAsync ? TypeDefinition.GenericReferenceType(typeof(Func <, , , ,>), typeof(Unpacker), this.TargetType, typeof(int), typeof(CancellationToken), typeof(Task)) : #endif // FEATURE_TAP TypeDefinition.GenericReferenceType(typeof(Action <, ,>), typeof(Unpacker), this.TargetType, typeof(int)) ); var indexOfItemParameter = context.IndexOfItem; var itemsCountParameter = context.ItemsCount; var appendToTargetParameter = context.CollectionToBeAdded; var unpackedItemParameter = context.DefineUnpackedItemParameterInSetValueMethods(this.CollectionTraits.ElementType); var unpackItemValueArguments = new[] { context.Unpacker, context.UnpackToTarget, indexOfItemParameter, itemsCountParameter } #if FEATURE_TAP .Concat(isAsync ? new[] { this.ReferCancellationToken(context, 2) } : NoConstructs).ToArray() #endif // FEATURE_TAP ; iterative = this.ExtractPrivateMethod( context, AdjustName(MethodName.UnpackCollectionItem, isAsync), false, // isStatic #if FEATURE_TAP isAsync ? typeof(Task) : #endif // FEATURE_TAP typeof(void), () => this.EmitUnpackItemValueStatement( context, traitsOfTheCollection.ElementType, this.EmitInvariantStringFormat(context, "item{0}", indexOfItemParameter), context.CollectionItemNilImplication, null, (schema ?? PolymorphismSchema.Default).ItemSchema, context.Unpacker, context.UnpackToTarget, indexOfItemParameter, itemsCountParameter, this.ExtractPrivateMethod( context, MethodName.AppendUnpackedItem, false, // isStatic typeof(void), () => this.EmitAppendCollectionItem( context, null, traitsOfTheCollection, appendToTargetParameter, unpackedItemParameter ), appendToTargetParameter, unpackedItemParameter ), isAsync ), unpackItemValueArguments ); } else { // Invoke UnpackToCore because AddItem override/inheritance is available. bulk = this.EmitGetActionsExpression(context, ActionType.UnpackTo, isAsync); context.IsUnpackToUsed = true; iterative = this.MakeNullLiteral( context, #if FEATURE_TAP isAsync ? TypeDefinition.GenericReferenceType(typeof(Func <, , , , ,>), typeof(Unpacker), this.TargetType, typeof(int), typeof(int), typeof(CancellationToken), typeof(Task)) : #endif // FEATURE_TAP TypeDefinition.GenericReferenceType(typeof(Action <, , ,>), typeof(Unpacker), this.TargetType, typeof(int), typeof(int)) ); } var unpackHelperArguments = new Dictionary <string, TConstruct> { { "Unpacker", context.Unpacker }, { "ItemsCount", itemsCount }, { "Collection", collection }, { "BulkOperation", bulk }, { "EachOperation", iterative }, }; #if FEATURE_TAP if (isAsync) { unpackHelperArguments.Add("CancellationToken", this.ReferCancellationToken(context, 2)); } #endif // FEATURE_TAP var unpackHelperParametersType = ( #if FEATURE_TAP isAsync ? typeof(UnpackCollectionAsyncParameters <>) : #endif // FEATURE_TAP typeof(UnpackCollectionParameters <>) ).MakeGenericType(this.TargetType); var unpackHelperParameters = this.DeclareLocal(context, unpackHelperParametersType, "unpackHelperParameters"); yield return(unpackHelperParameters); foreach (var construct in this.CreatePackUnpackHelperArgumentInitialization(context, unpackHelperParameters, unpackHelperArguments)) { yield return(construct); } // Call UnpackHelpers yield return (this.EmitRetrunStatement( context, this.EmitInvokeMethodExpression( context, null, #if FEATURE_TAP isAsync ? Metadata._UnpackHelpers.UnpackCollectionAsync_1Method.MakeGenericMethod(this.TargetType) : #endif // FEATURE_TAP Metadata._UnpackHelpers.UnpackCollection_1Method.MakeGenericMethod(this.TargetType), this.EmitMakeRef(context, unpackHelperParameters) ) )); }