Exemplo n.º 1
0
 /// <summary>
 /// 检测异步回调方法
 /// </summary>
 protected override void checkAsynchronousReturn()
 {
     if (methodParameters == null)
     {
         base.checkAsynchronousReturn();
         if (methodParameters.Length != 0)
         {
             if (!methodParameters[0].IsRefOrOut && methodParameters[0].ParameterType.Type == typeof(serverSocketSenderType))
             {
                 clientParameterName = methodParameters[0].ParameterName;
                 methodParameters    = MethodParameter.Get(methodParameters.getSub(1, methodParameters.Length - 1));
             }
         }
     }
 }
Exemplo n.º 2
0
 /// <summary>
 /// 检测异步回调方法
 /// </summary>
 protected virtual void checkAsynchronousReturn()
 {
     if (methodParameters == null)
     {
         methodParameters = Method.Parameters;
         methodReturnType = Method.ReturnType;
         if (Method.ReturnType.Type == typeof(void) && methodParameters.Length != 0)
         {
             Type type = methodParameters[methodParameters.Length - 1].ParameterType.Type;
             if (type.IsGenericType)
             {
                 Type parameterType = null;
                 if (isAsynchronousFunc && type.GetGenericTypeDefinition() == typeof(Func <,>))
                 {
                     Type[] types = type.GetGenericArguments();
                     if (types[1] == typeof(bool))
                     {
                         parameterType = types[0];
                     }
                 }
                 else if (type.GetGenericTypeDefinition() == typeof(Action <>))
                 {
                     parameterType = type.GetGenericArguments()[0];
                 }
                 if (parameterType != null)
                 {
                     if (parameterType == typeof(AutoCSer.Net.TcpServer.ReturnValue))
                     {
                         isAsynchronousCallback = true;
                     }
                     else if (parameterType.IsGenericType && parameterType.GetGenericTypeDefinition() == typeof(AutoCSer.Net.TcpServer.ReturnValue <>))
                     {
                         methodReturnType       = parameterType.GetGenericArguments()[0];
                         isAsynchronousCallback = true;
                     }
                     if (isAsynchronousCallback)
                     {
                         methodParameters = MethodParameter.Get(methodParameters.AsSpan(0, methodParameters.Length - 1).GetArray());
                     }
                 }
             }
         }
     }
 }
Exemplo n.º 3
0
                /// <summary>
                /// 获取成员集合
                /// </summary>
                /// <param name="type"></param>
                /// <returns></returns>
                private static cache getCache(Type type)
                {
                    cache members;

                    if (!memberCache.TryGetValue(type, out members))
                    {
                        LeftArray <RemoteLink> remoteMembers = new LeftArray <RemoteLink>(0);
                        foreach (MemberIndex member in MemberIndex.GetMembers <AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute>(type, AutoCSer.Metadata.MemberFilters.Instance, true, false))
                        {
                            if (member.CanGet)
                            {
                                AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute remoteAttribute = member.GetSetupAttribute <AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute>(false);
                                if (remoteAttribute != null)
                                {
                                    remoteMembers.Add(new RemoteLink {
                                        Member = member, PropertyParameters = member.IsField ? EmptyArray <MethodParameter> .Array : MethodParameter.Get(((PropertyInfo)member.Member).GetGetMethod(true), EmptyArray <Type> .Array), Attribute = remoteAttribute
                                    });
                                }
                            }
                        }
                        foreach (MethodIndex member in MethodIndex.GetMethods <AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute>(type, AutoCSer.Metadata.MemberFilters.Instance, false, true, false))
                        {
                            if (!member.Method.IsGenericMethodDefinition)
                            {
                                AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute remoteAttribute = member.GetSetupAttribute <AutoCSer.Net.TcpStaticServer.RemoteMemberAttribute>(false);
                                if (remoteAttribute != null)
                                {
                                    remoteMembers.Add(new RemoteLink {
                                        Method = member, Attribute = remoteAttribute
                                    });
                                }
                            }
                        }
                        memberCache.Add(type, members = new cache {
                            Members = remoteMembers.ToArray(), Caches = MemberIndex.GetMembers <AutoCSer.Net.TcpStaticServer.RemoteLinkAttribute>(type, AutoCSer.Metadata.MemberFilters.Instance, true, false)
                        });
                    }
                    return(members);
                }
Exemplo n.º 4
0
                /// <summary>
                /// 表达式成员集合
                /// </summary>
                /// <param name="type"></param>
                /// <param name="memberNodeTypeName"></param>
                internal ExpressionMemberGroup(ExtensionType type, string memberNodeTypeName)
                {
                    this.type = type;
                    this.memberNodeTypeName = memberNodeTypeName;
                    LeftArray <Expression> members = new LeftArray <Expression>(0);

                    nodeTypeNames.Clear();
                    foreach (MemberIndex member in MemberIndex.GetMembers <AutoCSer.Net.RemoteExpression.MemberAttribute>(type, AutoCSer.Metadata.MemberFilters.Instance, true, false))
                    {
                        if (!member.IsIgnore && member.CanGet)
                        {
                            AutoCSer.Net.RemoteExpression.MemberAttribute attribute = member.GetAttribute <AutoCSer.Net.RemoteExpression.MemberAttribute>(false);
                            IsMember &= addMember(ref members, new Expression {
                                Attribute = attribute, Member = member, IntputParameters = member.IsField ? EmptyArray <ExpressionParameter> .Array : ExpressionParameter.Get(MethodParameter.Get(((PropertyInfo)member.Member).GetGetMethod(true), EmptyArray <Type> .Array))
                            });
                        }
                    }
                    foreach (MethodIndex member in MethodIndex.GetMethods <AutoCSer.Net.RemoteExpression.MemberAttribute>(type, AutoCSer.Metadata.MemberFilters.Instance, false, true, false))
                    {
                        if (!member.IsIgnore)
                        {
                            AutoCSer.Net.RemoteExpression.MemberAttribute attribute = member.GetAttribute <AutoCSer.Net.RemoteExpression.MemberAttribute>(false);
                            IsMember &= addMember(ref members, new Expression {
                                Attribute = attribute, Method = member, IntputParameters = ExpressionParameter.Get(member.Parameters)
                            });
                        }
                    }
                    Members = members.ToArray();
                    if (memberNodeTypeName == null)
                    {
                        LeftArray <StaticExpression> staticMembers = new LeftArray <StaticExpression>(0);
                        foreach (MemberIndex member in MemberIndex.GetStaticMembers <AutoCSer.Net.RemoteExpression.MemberAttribute>(type, AutoCSer.Metadata.MemberFilters.Static, true, false))
                        {
                            if (!member.IsIgnore && member.CanGet)
                            {
                                AutoCSer.Net.RemoteExpression.MemberAttribute attribute = member.GetAttribute <AutoCSer.Net.RemoteExpression.MemberAttribute>(false);
                                IsMember &= addMember(ref staticMembers, new StaticExpression {
                                    Attribute = attribute, Member = member, IntputParameters = EmptyArray <ExpressionParameter> .Array
                                });
                            }
                        }
                        foreach (MethodIndex member in MethodIndex.GetMethods <AutoCSer.Net.RemoteExpression.MemberAttribute>(type, AutoCSer.Metadata.MemberFilters.Static, false, true, false))
                        {
                            if (!member.IsIgnore)
                            {
                                AutoCSer.Net.RemoteExpression.MemberAttribute attribute = member.GetAttribute <AutoCSer.Net.RemoteExpression.MemberAttribute>(false);
                                IsMember &= addMember(ref staticMembers, new StaticExpression {
                                    Attribute = attribute, Method = member, IntputParameters = ExpressionParameter.Get(member.Parameters)
                                });
                            }
                        }
                        StaticMembers = staticMembers.ToArray();
                    }
                    else
                    {
                        StaticMembers = EmptyArray <StaticExpression> .Array;
                    }
                    if ((IsMember &= (Members.Length | StaticMembers.Length) != 0) && memberNodeTypeName == null)
                    {
                        foreach (Expression member in Members)
                        {
                            member.CheckGenericMemberGroup();
                        }
                        foreach (StaticExpression member in StaticMembers)
                        {
                            member.CheckGenericMemberGroup();
                        }
                    }
                }
Exemplo n.º 5
0
 /// <summary>
 /// 安装下一个类型
 /// </summary>
 protected override void nextCreate()
 {
     if (!Type.Type.IsInterface)
     {
         LeftArray <MemberExpression> members = default(LeftArray <MemberExpression>);
         nodeTypeNames.Clear();
         bool isMember = true;
         foreach (MemberIndex member in MemberIndex.GetMembers <AutoCSer.Net.RemoteExpression.MemberAttribute>(Type, AutoCSer.Metadata.MemberFilters.Instance, true, false))
         {
             if (!member.IsIgnore && member.CanGet)
             {
                 AutoCSer.Net.RemoteExpression.MemberAttribute attribute = member.GetAttribute <AutoCSer.Net.RemoteExpression.MemberAttribute>(false);
                 isMember &= addMember(ref members, new MemberExpression {
                     Attribute = attribute, Member = member, IntputParameters = member.IsField ? NullValue <ExpressionParameter> .Array : ExpressionParameter.Get(MethodParameter.Get(((PropertyInfo)member.Member).GetGetMethod(true), NullValue <Type> .Array))
                 });
             }
         }
         Members = members.ToArray();
         LeftArray <MethodExpression> methods = default(LeftArray <MethodExpression>);
         foreach (MethodIndex member in MethodIndex.GetMethods <AutoCSer.Net.RemoteExpression.MemberAttribute>(Type, AutoCSer.Metadata.MemberFilters.Instance, false, true, false))
         {
             if (!member.IsIgnore)
             {
                 AutoCSer.Net.RemoteExpression.MemberAttribute attribute = member.GetAttribute <AutoCSer.Net.RemoteExpression.MemberAttribute>(false);
                 isMember &= addMember(ref methods, new MethodExpression {
                     Attribute = attribute, Method = member, IntputParameters = ExpressionParameter.Get(member.Parameters)
                 });
             }
         }
         Methods = methods.ToArray();
         LeftArray <StaticMemberExpression> staticMembers = default(LeftArray <StaticMemberExpression>);
         foreach (MemberIndex member in MemberIndex.GetStaticMembers <AutoCSer.Net.RemoteExpression.MemberAttribute>(Type, AutoCSer.Metadata.MemberFilters.Static, true, false))
         {
             if (!member.IsIgnore && member.CanGet)
             {
                 AutoCSer.Net.RemoteExpression.MemberAttribute attribute = member.GetAttribute <AutoCSer.Net.RemoteExpression.MemberAttribute>(false);
                 isMember &= addMember(ref staticMembers, new StaticMemberExpression {
                     Attribute = attribute, Member = member, IntputParameters = NullValue <ExpressionParameter> .Array
                 });
             }
         }
         StaticMembers = staticMembers.ToArray();
         LeftArray <StaticMethodExpression> staticMethods = default(LeftArray <StaticMethodExpression>);
         foreach (MethodIndex member in MethodIndex.GetMethods <AutoCSer.Net.RemoteExpression.MemberAttribute>(Type, AutoCSer.Metadata.MemberFilters.Static, false, true, false))
         {
             if (!member.IsIgnore)
             {
                 AutoCSer.Net.RemoteExpression.MemberAttribute attribute = member.GetAttribute <AutoCSer.Net.RemoteExpression.MemberAttribute>(false);
                 isMember &= addMember(ref staticMethods, new StaticMethodExpression {
                     Attribute = attribute, Method = member, IntputParameters = ExpressionParameter.Get(member.Parameters)
                 });
             }
         }
         StaticMethods = staticMethods.ToArray();
         if (isMember && (Members.Length | Methods.Length | StaticMemberCount) != 0)
         {
             create(true);
         }
     }
 }