Пример #1
0
        public static TypeValueAccess Create(Type type, string name, MemberType memberType = MemberType.Instance | MemberType.Public | MemberType.Field | MemberType.Property)
        {
            //BindingFlags bindingFlags = BindingFlags.Instance;
            //if ((memberType & pb.Reflection.MemberType.Public) == pb.Reflection.MemberType.Public)
            //    bindingFlags |= BindingFlags.Public;
            //if ((memberType & pb.Reflection.MemberType.NonPublic) == pb.Reflection.MemberType.NonPublic)
            //    bindingFlags |= BindingFlags.NonPublic;
            //foreach (MemberInfo member in type.GetMember(name, bindingFlags))
            //{
            //    BindingFlags accessBindingFlag = 0;
            //    if (member.MemberType == MemberTypes.Field)
            //        accessBindingFlag = BindingFlags.GetField;
            //    else if (member.MemberType == MemberTypes.Property)
            //        accessBindingFlag = BindingFlags.GetProperty;
            //    //return new MemberAccess { SourceType = type, Name = member.Name, MemberTypes = member.MemberType, AccessBindingFlag = accessBindingFlag, MemberInfo = member };
            //    return new MemberAccess { SourceType = type, Name = member.Name, AccessBindingFlag = accessBindingFlag };
            //}
            //return null;
            TypeValueInfo typeValueInfo = type.zGetTypeValueInfo(name, memberType);

            if (typeValueInfo != null)
            {
                //return new MemberAccess { SourceType = type, Name = valueInfo.Name, AccessBindingFlag = GetAccessBindingFlag(valueInfo.MemberTypes) };
                return(new TypeValueAccess(typeValueInfo));
            }
            else
            {
                return(null);
            }
        }
Пример #2
0
        private bool GetSiblin()
        {
            if (!_enumerator.MoveNext())
            {
                return(false);
            }

            _typeValueInfo = _enumerator.Current;
            SetTreeName();
            return(true);
        }
Пример #3
0
 public TypeValueAccess(TypeValueInfo typeValueInfo, string treeName = null)
 {
     SourceType = typeValueInfo.SourceType;
     Name = typeValueInfo.Name;
     if (treeName == null)
         TreeName = typeValueInfo.Name;
     else
         TreeName = treeName;
     AccessBindingFlag = GetAccessBindingFlag(typeValueInfo.MemberTypes);
     ValueType = typeValueInfo.ValueType;
     IsValueType = typeValueInfo.IsValueType;
     IsEnumerable = typeValueInfo.IsEnumerable;
 }
Пример #4
0
 public TraceTypeValueInfo(TypeValueInfo typeValueInfo)
 {
     Name          = typeValueInfo.Name;
     TreeName      = typeValueInfo.TreeName;
     ParentName    = typeValueInfo.ParentName;
     ValueType     = typeValueInfo.ValueType.zGetTypeName();
     IsValueType   = typeValueInfo.IsValueType;
     IsEnumerable  = typeValueInfo.IsEnumerable;
     DeclaringType = typeValueInfo.DeclaringType.zGetTypeName();
     ReflectedType = typeValueInfo.ReflectedType.zGetTypeName();
     MemberType    = typeValueInfo.MemberTypes.ToString();
     MetadataToken = typeValueInfo.MetadataToken;
     Module        = typeValueInfo.Module.Name;
 }
Пример #5
0
 public TypeValueAccess(TypeValueInfo typeValueInfo, string treeName = null)
 {
     SourceType = typeValueInfo.SourceType;
     Name       = typeValueInfo.Name;
     if (treeName == null)
     {
         TreeName = typeValueInfo.Name;
     }
     else
     {
         TreeName = treeName;
     }
     AccessBindingFlag = GetAccessBindingFlag(typeValueInfo.MemberTypes);
     ValueType         = typeValueInfo.ValueType;
     IsValueType       = typeValueInfo.IsValueType;
     IsEnumerable      = typeValueInfo.IsEnumerable;
 }
Пример #6
0
        public TypeValueNode AddValue(string name, MemberType memberType = MemberType.Instance | MemberType.Public | MemberType.Field | MemberType.Property, bool notEnumerable = false)
        {
            string        parentName    = null;
            TypeValueNode parent        = null;
            Type          type          = _type;
            TypeValueNode typeValueNode = null;

            foreach (string valueName in name.Split('.'))
            {
                string treeName = valueName;
                if (parentName != null)
                {
                    treeName = parentName + "." + treeName;
                }
                typeValueNode = null;
                if (!_typeValueNodes.ContainsKey(treeName))
                {
                    TypeValueInfo typeValueInfo = type.zGetTypeValueInfo(valueName, memberType);
                    if (typeValueInfo == null)
                    {
                        throw new PBException("unknow value \"{0}\" from type {1} memberType {2}", valueName, type.zGetTypeName(), memberType.ToString());
                    }
                    typeValueNode = new TypeValueNode {
                        TypeValueAccess = new TypeValueAccess(typeValueInfo, treeName)
                    };
                    if (notEnumerable)
                    {
                        typeValueNode.TypeValueAccess.IsEnumerable = false;
                    }
                    typeValueNode.SetParent(parent);
                    _typeValueNodes.Add(treeName, typeValueNode);
                }
                else
                {
                    typeValueNode = _typeValueNodes[valueName];
                }
                parentName = treeName;
                parent     = typeValueNode;
                type       = typeValueNode.TypeValueAccess.ValueType;
            }
            return(typeValueNode);
        }
Пример #7
0
        private bool GetChild()
        {
            if (_typeValueInfo.IsValueType)
            {
                return(false);
            }

            if (_enumerator != null)
            {
                _stack.Push(_enumerator);
            }

            _level++;
            _enumerator = GetValuesInfos(_typeValueInfo.ValueType, _bindingFlags, _memberTypes).GetEnumerator();
            if (!_enumerator.MoveNext())
            {
                return(false);
            }

            _treeName      = _typeValueInfo.TreeName;
            _typeValueInfo = _enumerator.Current;
            SetTreeName();
            return(true);
        }
Пример #8
0
        private bool GetSiblin()
        {
            if (!_enumerator.MoveNext())
                return false;

            _typeValueInfo = _enumerator.Current;
            SetTreeName();
            return true;
        }
Пример #9
0
        private bool GetChild()
        {
            if (_typeValueInfo.IsValueType)
                return false;

            if (_enumerator != null)
                _stack.Push(_enumerator);

            _level++;
            _enumerator = GetValuesInfos(_typeValueInfo.ValueType, _bindingFlags, _memberTypes).GetEnumerator();
            if (!_enumerator.MoveNext())
                return false;

            _treeName = _typeValueInfo.TreeName;
            _typeValueInfo = _enumerator.Current;
            SetTreeName();
            return true;
        }
Пример #10
0
        private IEnumerable<TreeValue<TypeValueInfo>> _GetAllValuesInfos(Type type)
        {
            if (type == null)
                yield break;

            _typeValueInfo = new TypeValueInfo(type);

            TreeValue<TypeValueInfo> treeValue;

            treeValue = GetTreeValue(TreeOpe.Source);
            if (_returnSource)
            {
                _index++;
                yield return treeValue;
            }

            if (treeValue.Stop || treeValue.Skip)
                yield break;

            while (true)
            {
                // get child
                while (true)
                {
                    if (!GetChild())
                        break;

                    treeValue = GetTreeValue(TreeOpe.Child);
                    //if (_verbose || _valueInfo.IsValueType)
                    if ((_typeValueInfo.IsValueType && _returnValueType) || (!_typeValueInfo.IsValueType && _returnNotValueType))
                    {
                        _index++;
                        yield return treeValue;
                    }

                    if (treeValue.Stop)
                        yield break;

                    if (treeValue.Skip)
                        break;
                }

                if (_enumerator == null)
                    break;

                // get next sibling node or next sibling node of parent node
                bool getChild = false;
                while (true)
                {
                    // next sibling node
                    while (true)
                    {
                        if (!GetSiblin())
                            break;

                        treeValue = GetTreeValue(TreeOpe.Siblin);
                        //if (_verbose || _valueInfo.IsValueType)
                        if ((_typeValueInfo.IsValueType && _returnValueType) || (!_typeValueInfo.IsValueType && _returnNotValueType))
                        {
                            _index++;
                            yield return treeValue;
                        }

                        if (treeValue.Stop)
                            yield break;

                        if (!treeValue.Skip)
                        {
                            getChild = true;
                            break;
                        }
                    }
                    if (getChild)
                        break;

                    if (_returnParent)
                        yield return new TreeValue<TypeValueInfo> { Index = _index++, Value = null, Level = _level - 1, TreeOpe = TreeOpe.Parent, Selected = false, Skip = false, Stop = false };

                    if (!GetParent())
                        yield break;
                }
            }
        }
Пример #11
0
 public TraceTypeValueInfo(TypeValueInfo typeValueInfo)
 {
     Name = typeValueInfo.Name;
     TreeName = typeValueInfo.TreeName;
     ParentName = typeValueInfo.ParentName;
     ValueType = typeValueInfo.ValueType.zGetTypeName();
     IsValueType = typeValueInfo.IsValueType;
     IsEnumerable = typeValueInfo.IsEnumerable;
     DeclaringType = typeValueInfo.DeclaringType.zGetTypeName();
     ReflectedType = typeValueInfo.ReflectedType.zGetTypeName();
     MemberType = typeValueInfo.MemberTypes.ToString();
     MetadataToken = typeValueInfo.MetadataToken;
     Module = typeValueInfo.Module.Name;
 }
Пример #12
0
        private IEnumerable <TreeValue <TypeValueInfo> > _GetAllValuesInfos(Type type)
        {
            if (type == null)
            {
                yield break;
            }

            _typeValueInfo = new TypeValueInfo(type);

            TreeValue <TypeValueInfo> treeValue;

            treeValue = GetTreeValue(TreeOpe.Source);
            if (_returnSource)
            {
                _index++;
                yield return(treeValue);
            }

            if (treeValue.Stop || treeValue.Skip)
            {
                yield break;
            }

            while (true)
            {
                // get child
                while (true)
                {
                    if (!GetChild())
                    {
                        break;
                    }

                    treeValue = GetTreeValue(TreeOpe.Child);
                    //if (_verbose || _valueInfo.IsValueType)
                    if ((_typeValueInfo.IsValueType && _returnValueType) || (!_typeValueInfo.IsValueType && _returnNotValueType))
                    {
                        _index++;
                        yield return(treeValue);
                    }

                    if (treeValue.Stop)
                    {
                        yield break;
                    }

                    if (treeValue.Skip)
                    {
                        break;
                    }
                }

                if (_enumerator == null)
                {
                    break;
                }

                // get next sibling node or next sibling node of parent node
                bool getChild = false;
                while (true)
                {
                    // next sibling node
                    while (true)
                    {
                        if (!GetSiblin())
                        {
                            break;
                        }

                        treeValue = GetTreeValue(TreeOpe.Siblin);
                        //if (_verbose || _valueInfo.IsValueType)
                        if ((_typeValueInfo.IsValueType && _returnValueType) || (!_typeValueInfo.IsValueType && _returnNotValueType))
                        {
                            _index++;
                            yield return(treeValue);
                        }

                        if (treeValue.Stop)
                        {
                            yield break;
                        }

                        if (!treeValue.Skip)
                        {
                            getChild = true;
                            break;
                        }
                    }
                    if (getChild)
                    {
                        break;
                    }

                    if (_returnParent)
                    {
                        yield return new TreeValue <TypeValueInfo> {
                                   Index = _index++, Value = null, Level = _level - 1, TreeOpe = TreeOpe.Parent, Selected = false, Skip = false, Stop = false
                        }
                    }
                    ;

                    if (!GetParent())
                    {
                        yield break;
                    }
                }
            }
        }