コード例 #1
0
        public static Type GetOrCreate(MethodInfo mi)
        {
            var mpia        = mi.GetAttribute <PInvokeAttribute>() ?? mi.DeclaringType.GetAttribute <PInvokeAttribute>();
            var dyndelegate =
                new DynamicDelegate(
                    mi.GetParameters().Select(p => DynamicDelegateParameter.FromParameterInfo(p, mpia)).ToArray(),
                    DynamicDelegateParameter.FromParameterInfo(mi.ReturnParameter, mpia), mpia?.CallingConvention ?? 0);

            return(dyndelegate.GetOrCreate());
        }
コード例 #2
0
        public DynamicDelegate(DynamicDelegateParameter[] parameters, DynamicDelegateParameter returnParameter, CallingConvention callingConvention)
        {
            ReturnParameter   = returnParameter ?? DynamicDelegateParameter.Void;
            Parameters        = parameters;
            CallingConvention = callingConvention;
            var id = new StringBuilder("D_");

            ReturnParameter.AppendId(id);
            foreach (var par in Parameters)
            {
                id.Append('_');
                par.AppendId(id);
            }
            Id = id.ToString();
        }