public static Object ( |
||
type | ||
return |
public MethodDefinition(MethodInfo runtimeMethod, Type @interface) : this(runtimeMethod, @interface, runtimeMethod.GetParameters().Select(p => TypeDefinition.Object(p.ParameterType))) { }
public MethodDefinition(MethodInfo runtimeMethod) : this(runtimeMethod, null, runtimeMethod.GetParameters().Select(p => TypeDefinition.Object(p.ParameterType))) { }
private IEnumerable <TConstruct> BuildTuplePackToCore(TContext context, IList <Type> itemTypes, IList <PolymorphismSchema> itemSchemaList, bool isAsync) { // Note: cardinality is put as array length by PackHelper. var depth = -1; var tupleTypeList = TupleItems.CreateTupleTypeList(itemTypes); var propertyInvocationChain = new List <PropertyInfo>(itemTypes.Count % 7 + 1); var packValueArguments = new[] { context.Packer, context.PackToTarget } #if FEATURE_TAP .Concat(isAsync ? new[] { this.ReferCancellationToken(context, 3) } : NoConstructs).ToArray() #endif // FEATURE_TAP ; for (int i = 0; i < itemTypes.Count; i++) { if (i % 7 == 0) { depth++; } for (int j = 0; j < depth; j++) { // .TRest.TRest ... var restProperty = tupleTypeList[j].GetProperty("Rest"); #if DEBUG Contract.Assert(restProperty != null); #endif propertyInvocationChain.Add(restProperty); } var itemNProperty = tupleTypeList[depth].GetProperty("Item" + ((i % 7) + 1)); propertyInvocationChain.Add(itemNProperty); #if DEBUG Contract.Assert( itemNProperty != null, tupleTypeList[depth].GetFullName() + "::Item" + ((i % 7) + 1) + " [ " + depth + " ] @ " + i ); #endif var count = i; this.ExtractPrivateMethod( context, AdjustName(MethodNamePrefix.PackValue + SerializationTarget.GetTupleItemNameFromIndex(i), isAsync), #if FEATURE_TAP isAsync ? typeof(Task) : #endif // FEATURE_TAP typeof(void), () => this.EmitSequentialStatements( context, typeof(void), this.EmitPackTupleItemStatements( context, itemTypes[count], context.Packer, context.PackToTarget, propertyInvocationChain, itemSchemaList.Count == 0 ? null : itemSchemaList[count], isAsync ) ), packValueArguments ); propertyInvocationChain.Clear(); } var packHelperArguments = new[] { context.Packer, context.PackToTarget, this.EmitGetActionsExpression(context, ActionType.PackToArray, isAsync) } #if FEATURE_TAP .Concat(isAsync ? new[] { this.ReferCancellationToken(context, 3) } : NoConstructs).ToArray() #endif // FEATURE_TAP ; var packToArray = this.EmitInvokeMethodExpression( context, null, new MethodDefinition( AdjustName(MethodName.PackToArray, isAsync), new [] { TypeDefinition.Object(this.TargetType) }, typeof(PackHelpers), #if FEATURE_TAP isAsync ? typeof(Task) : #endif // FEATURE_TAP typeof(void), packHelperArguments.Select(a => a.ContextType).ToArray() ), packHelperArguments ); if (isAsync) { // Wrap with return to return Task packToArray = this.EmitRetrunStatement(context, packToArray); } yield return(packToArray); }
private IEnumerable <TConstruct> BuildTuplePackToCore(TContext context, IList <Type> itemTypes, IList <PolymorphismSchema> itemSchemaList, bool isAsync) { // Note: cardinality is put as array length by PackHelper. var depth = -1; var tupleTypeList = TupleItems.CreateTupleTypeList(itemTypes); var propertyInvocationChain = new List <PropertyInfo>(itemTypes.Count % 7 + 1); var packValueArguments = new[] { context.Packer, context.PackToTarget } #if FEATURE_TAP .Concat(isAsync ? new[] { this.ReferCancellationToken(context, 3) } : NoConstructs).ToArray() #endif // FEATURE_TAP ; for (int i = 0; i < itemTypes.Count; i++) { if (i % 7 == 0) { depth++; } for (int j = 0; j < depth; j++) { // .TRest.TRest ... var restProperty = tupleTypeList[j].GetProperty("Rest"); #if DEBUG Contract.Assert(restProperty != null); #endif propertyInvocationChain.Add(restProperty); } var itemNProperty = tupleTypeList[depth].GetProperty("Item" + ((i % 7) + 1)); propertyInvocationChain.Add(itemNProperty); #if DEBUG Contract.Assert( itemNProperty != null, tupleTypeList[depth].GetFullName() + "::Item" + ((i % 7) + 1) + " [ " + depth + " ] @ " + i ); #endif var count = i; DefinePrivateMethod( context, AdjustName(MethodNamePrefix.PackValue + SerializationTarget.GetTupleItemNameFromIndex(i), isAsync), false, // isStatic #if FEATURE_TAP isAsync ? TypeDefinition.TaskType : #endif // FEATURE_TAP TypeDefinition.VoidType, () => this.EmitSequentialStatements( context, TypeDefinition.VoidType, this.EmitPackTupleItemStatements( context, itemTypes[count], context.Packer, context.PackToTarget, propertyInvocationChain, itemSchemaList.Count == 0 ? null : itemSchemaList[count], isAsync ) ), packValueArguments ); propertyInvocationChain.Clear(); } var packHelperArguments = new Dictionary <string, TConstruct> { { "Packer", context.Packer }, { "Target", context.PackToTarget }, { "Operations", this.EmitGetActionsExpression(context, ActionType.PackToArray, isAsync) } }; #if FEATURE_TAP if (isAsync) { packHelperArguments.Add("CancellationToken", this.ReferCancellationToken(context, 3)); } #endif // FEATURE_TAP var packHelperParameterTypeDefinition = #if FEATURE_TAP isAsync ? typeof(PackToArrayAsyncParameters <>) : #endif // FEATURE_TAP typeof(PackToArrayParameters <>); var packHelperParameterType = TypeDefinition.GenericValueType(packHelperParameterTypeDefinition, this.TargetType); var packHelperMethod = new MethodDefinition( AdjustName(MethodName.PackToArray, isAsync), new [] { TypeDefinition.Object(this.TargetType) }, TypeDefinition.PackHelpersType, true, // isStatic #if FEATURE_TAP isAsync ? TypeDefinition.TaskType : #endif // FEATURE_TAP TypeDefinition.VoidType, packHelperParameterType ); var packHelperParameters = this.DeclareLocal(context, packHelperParameterType, "packHelperParameters"); yield return(packHelperParameters); foreach (var construct in this.CreatePackUnpackHelperArgumentInitialization(context, packHelperParameters, packHelperArguments)) { yield return(construct); } var methodInvocation = this.EmitInvokeMethodExpression( context, null, packHelperMethod, this.EmitMakeRef(context, packHelperParameters) ); if (isAsync) { // Wrap with return to return Task methodInvocation = this.EmitRetrunStatement(context, methodInvocation); } yield return(methodInvocation); }
public ConstructorDefinition(ConstructorInfo runtimeConstructor) : this(runtimeConstructor, runtimeConstructor.GetParameters().Select(p => TypeDefinition.Object(p.ParameterType))) { }