Beispiel #1
0
        private IReadOnlyList <MethodSignature> GetMethodSignatures(IComponentProvider provider)
        {
            var boolSymbol = _symbols.GetSymbol <bool>();
            var intSymbol  = _symbols.GetSymbol <int>();
            var memberType = _member.ReturnType !.Symbol;

            // Incoming Data type
            var discovery  = new MethodArg(RefKind.In, provider.DiscoveryType, "parent");
            var sourceType = new MethodArg(RefKind.In, _member.ContainingFullType.Symbol, "source");

            // Buffers
            var readOnlySpan = new MethodArg(_symbols.GetSymbol(typeof(ReadOnlySpan <byte>)), "readOnlySpan");
            var span         = new MethodArg(_symbols.GetSymbol(typeof(Span <byte>)), "span");
            var cursor       = new MethodArg(RefKind.Ref, _symbols.GetSymbol(typeof(SequenceCursor <byte>)), "cursor");

            // Return Data
            var readBytes    = new MethodArg(RefKind.Out, intSymbol, "readBytes");
            var writtenBytes = new MethodArg(RefKind.Out, intSymbol, "writtenBytes");
            var result       = new MethodArg(RefKind.Out, memberType, "result");

            return(new MethodSignature[] {
                MethodSignatureBuilder.CreateConstructor(_typeName, (provider.DiscoveryType, "parser")),
                MethodSignatureBuilder.CreateConstructor(_typeName, (provider.DiscoveryType, "parser"), (RefKind.Out, boolSymbol, "isSuccess")),

                MethodSignatureBuilder.CreateMethod(_typeName, MemberMethod.TryDeserializeState(0))
                .AddArgument(discovery, readOnlySpan, readBytes, result)
                .WithReturn <bool>(),

                MethodSignatureBuilder.CreateMethod(_typeName, MemberMethod.TryDeserializeState(0))
                .AddArgument(discovery, cursor, result)
                .WithReturn <bool>(),

                MethodSignatureBuilder.CreateMethod(_typeName, MemberMethod.DeserializeState(0))
                .AddArgument(discovery, readOnlySpan, result)
                .WithReturn(memberType),

                MethodSignatureBuilder.CreateMethod(_typeName, MemberMethod.DeserializeState(0))
                .AddArgument(discovery, cursor)
                .WithReturn(memberType),

                MethodSignatureBuilder.CreateMethod(_typeName, MemberMethod.TrySerializeState(0))
                .AddArgument(discovery, sourceType, span, writtenBytes)
                .WithReturn(boolSymbol),

                MethodSignatureBuilder.CreateMethod(_typeName, MemberMethod.SerializeState(0))
                .AddArgument(discovery, sourceType, span)
                .WithReturn(intSymbol),

                MethodSignatureBuilder.CreateMethod(_typeName, MemberMethod.GetLengthState(0))
                .AddArgument(discovery, sourceType)
                .WithReturn(intSymbol)
            });
Beispiel #2
0
        /// <summary>
        /// 建造参数信息
        /// </summary>
        /// <param name="log">日志</param>
        /// <param name="context">方法元数据</param>
        public static void BuildParametersInfo(this BaseLog log, MethodAdviceContext context)
        {
            IList <object> arguments = context.Arguments ?? new List <object>();

            ParameterInfo[] parameters = context.TargetMethod.GetParameters();

            IList <MethodArg> methodArgs = new List <MethodArg>();

            for (int index = 0; index < arguments.Count; index++)
            {
                string    argTypeName = parameters[index].ParameterType.FullName;
                MethodArg methodArg   = new MethodArg(parameters[index].Name, argTypeName, arguments[index].ToJson());

                methodArgs.Add(methodArg);
            }

            log.ArgsJson = methodArgs.ToJson();
        }
Beispiel #3
0
        /// <summary>
        /// 建造方法参数信息
        /// </summary>
        /// <param name="log">日志</param>
        /// <param name="context">方法元数据</param>
        public static void BuildMethodArgsInfo(this BaseLog log, MethodAdviceContext context)
        {
            IList <object> arguments = context.Arguments;

            ParameterInfo[] parameters = context.TargetMethod.GetParameters();

            List <MethodArg> argList = new List <MethodArg>();

            for (int i = 0; arguments != null && i < arguments.Count; i++)
            {
                string    argTypeName = string.Format("{0}.{1}", parameters[i].ParameterType.Namespace, parameters[i].ParameterType.Name);
                MethodArg arg         = new MethodArg(parameters[i].Name, argTypeName, arguments[i].ToJson());

                argList.Add(arg);
            }

            log.ArgsJson = argList.ToJson();
        }
Beispiel #4
0
 public string GetArgTypeString(MethodArg arg) =>
 arg.Type switch
 {
Beispiel #5
0
        public void GetSetIndexes()
        {
            // arrange
            var key1 = new MethodArg[] { new MethodArg<object>(new object(), string.Empty), new MethodArg<string>("asdsadoihasoid", string.Empty) };
            var key2 = new MethodArg[] { new MethodArg<int>(4, string.Empty), new MethodArg<List>(new List(), string.Empty) };
            var val1 = new object();
            var val2 = new object();
            var val3 = new object();
            var values = new MockBuilder();
            ((dynamic)values)[key1[0].Arg, key1[1].Arg] = val1;
            var subject = new ObjectBase(DxSettings.GlobalSettings, values);

            // act
            Assert.AreEqual(val1, subject.GetIndex<object>(key1, false));
            subject.SetIndex(key1, val2);
            Assert.AreEqual(val2, subject.GetIndex<object>(key1, false));
            subject.SetIndex(key2, val3);
            Assert.AreEqual(val3, subject.GetIndex<object>(key2, false));
        }