コード例 #1
0
        private object getMemberValue(WSEntity entity, WSParam eParam, MetaFunctions CFunc)
        {
            WSTableSource            xSource  = (WSTableSource)CFunc.GetSourceByType(entity.GetType());
            IEnumerable <MemberInfo> eMembers = xSource.ReturnType.GetMembers().Where(m => m is PropertyInfo || m is FieldInfo);
            MemberInfo eField = eMembers.FirstOrDefault(m => eParam.Match(m.Name));

            return(eField is PropertyInfo ? ((PropertyInfo)eField).GetValue(entity, null) : eField is FieldInfo ? ((FieldInfo)eField).GetValue(entity) : null);
        }
コード例 #2
0
ファイル: WSExtention.cs プロジェクト: odensebysmuseer/OBMWS
 public static bool ReadValue(this Dictionary <string, string> dict, WSParam key, out string value)
 {
     lock (ReadDictionaryLock)
     {
         value = null;
         try
         {
             if (dict != null && key != null)
             {
                 if (dict.Any(d => key.Match(d.Key)))
                 {
                     value = dict.FirstOrDefault(d => key.Match(d.Key)).Value;
                     return(true);
                 }
             }
         }
         catch (Exception) { }
         return(false);
     }
 }
コード例 #3
0
        private WSStatus WriteJMembers(IEnumerable <MemberInfo> members, JsonWriter writer, JsonSerializer serializer, WSEntitySchema eSchema, WSSource xSource, WSParamList outFields, List <Type> printedTypes, WSRequest Request, MetaFunctions CFunc, WSDataContext DBContext)
        {
            WSStatus status = WSStatus.NONE_Copy();

            try
            {
                Type    eType = GetType();
                object  obj   = null;
                WSParam param = null;
                if (this is WSDynamicEntity)
                {
                    foreach (WSSchema fieldSchema in eSchema.Fields /*.Items*/)
                    {
                        if (fieldSchema is WSFieldSchema)
                        {
                            param = ((WSFieldSchema)fieldSchema).param;
                        }
                        else if (fieldSchema is WSEntityBaseSchema)
                        {
                            param = GetParam(xSource, fieldSchema.Name);
                        }
                        //else if (childSchema is WSEntitySchema) { param = GetParam(childSchema.Name); }
                        //else if (childSchema is WSEntityListSchema) { param = GetParam(((WSEntityListSchema)childSchema).EntitySchema.Name); }

                        MemberInfo member = param == null ? null : members.FirstOrDefault(p => param.Match(p.Name, null, null, false));
                        obj = member == null ? null : member is PropertyInfo ? ((PropertyInfo)member).GetValue(this, null) : member is FieldInfo ? ((FieldInfo)member).GetValue(this) : null;

                        if (param != null)
                        {
                            status.childs.Add(WriteJProperty(obj, param, writer, serializer, fieldSchema, xSource, outFields, printedTypes, Request, CFunc, DBContext));
                        }
                    }
                }
                else if (this is WSStaticEntity)
                {
                    foreach (MemberInfo member in members)
                    {
                        param = GetParam(xSource, member.Name, member.ReflectedType);
                        obj   = member is PropertyInfo ? ((PropertyInfo)member).GetValue(this, null) : member is FieldInfo ? ((FieldInfo)member).GetValue(this) : null;

                        if (param != null)
                        {
                            status.childs.Add(WriteJProperty(obj, param, writer, serializer, null, xSource, outFields, printedTypes, Request, CFunc, DBContext));
                        }
                    }
                }

                status.AddNote("done", WSConstants.ACCESS_LEVEL.READ);
            }
            catch (Exception e)
            {
                status.CODE = WSStatus.ERROR.CODE;
                status.AddNote("Error(line" + e.LineNumber() + "- " + e.Message + ")");
                CFunc.RegError(GetType(), e, ref status);
            }
            return(status);
        }