Exemple #1
0
        public static IReadOnlyList <ReflectionPropertyInfo> GetPropertiesForType(Type targetType)
        {
            var properties = new List <ReflectionPropertyInfo> ();

            foreach (PropertyInfo property in targetType.GetProperties())
            {
                DebuggerBrowsableAttribute browsable = property.GetCustomAttribute <DebuggerBrowsableAttribute> ();
                if (browsable != null && browsable.State == DebuggerBrowsableState.Never)
                {
                    continue;
                }

                if (CheckAvailability(property))
                {
                    if (property.PropertyType.IsEnum)
                    {
                        properties.Add((ReflectionPropertyInfo)Activator.CreateInstance(typeof(ReflectionEnumPropertyInfo <>).MakeGenericType(Enum.GetUnderlyingType(property.PropertyType)), property));
                    }
                    else
                    {
                        properties.Add(new ReflectionPropertyInfo(property));
                    }
                }
            }

            return(properties);
        }
Exemple #2
0
        public void GettingAnAttribute_FromAMember_GetsTheAttribute()
        {
            MemberInfo prop = new PropertyFieldInfo <AttributesClass, string>(a => a.RandomAttributeTest).Member;

            DebuggerBrowsableAttribute attribute = prop.GetAttribute <DebuggerBrowsableAttribute>();

            Assert.AreEqual(AttributesClass.RandomAttributeTestBrowsableState, attribute.State);
        }
        public ReflectionObjectEditor(object target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            this.target = target;
            Type targetType = target.GetType();

            foreach (PropertyInfo property in targetType.GetProperties())
            {
                DebuggerBrowsableAttribute browsable = property.GetCustomAttribute <DebuggerBrowsableAttribute> ();
                if (browsable != null && browsable.State == DebuggerBrowsableState.Never)
                {
                    continue;
                }

                if (CheckAvailability(property))
                {
                    if (property.PropertyType.IsEnum)
                    {
                        this.properties.Add((ReflectionPropertyInfo)Activator.CreateInstance(typeof(ReflectionEnumPropertyInfo <>).MakeGenericType(Enum.GetUnderlyingType(property.PropertyType)), property));
                    }
                    else
                    {
                        this.properties.Add(new ReflectionPropertyInfo(property));
                    }
                }
            }

            foreach (EventInfo ev in targetType.GetEvents())
            {
                this.events.Add(new ReflectionEventInfo(ev));
            }
        }
        protected override List <IMember> BuildMemberList()
        {
            List <IMember> list = new List <IMember>();

            if (_target == null)
            {
                return(list);
            }
            if (Context == null)
            {
                return(base.BuildMemberList());
            }
            IEntityMetaDataProvider entityMetaDataProvider = Context.GetService <IEntityMetaDataProvider>();

            Type            type     = _target.GetType();
            IEntityMetaData metaData = entityMetaDataProvider.GetMetaData(type, true);

            if (metaData == null)
            {
                return(base.BuildMemberList());
            }
            HashSet <String> suppressedPropertyNames = new HashSet <String>();

            foreach (RelationMember member in metaData.RelationMembers)
            {
                suppressedPropertyNames.Add(ValueHolderIEC.GetObjRefsFieldName(member.Name));
                suppressedPropertyNames.Add(ValueHolderIEC.GetInitializedFieldName(member.Name));
            }
            HashMap <String, RelationMember> nameToRelationMap = new HashMap <String, RelationMember>();

            foreach (RelationMember member in metaData.RelationMembers)
            {
                nameToRelationMap.Put(member.Name + ValueHolderIEC.GetNoInitSuffix(), member);
            }
            ITypeInfoItem[] members = Context.GetService <ITypeInfoProvider>().GetTypeInfo(type).Members;
            foreach (ITypeInfoItem member in members)
            {
                if (!member.CanRead)
                {
                    continue;
                }
                DebuggerBrowsableAttribute att = member.GetAnnotation <DebuggerBrowsableAttribute>();
                if (att != null && att.State == DebuggerBrowsableState.Never)
                {
                    continue;
                }
                String propertyName = member.Name;
                if (suppressedPropertyNames.Contains(propertyName))
                {
                    continue;
                }
                RelationMember relMember = nameToRelationMap.Get(propertyName);
                Object         value     = null;
                if (relMember != null)
                {
                    propertyName = relMember.Name;
                    int relationIndex      = metaData.GetIndexByRelationName(propertyName);
                    ValueHolderState state = ((IObjRefContainer)_target).Get__State(relationIndex);
                    if (!ValueHolderState.INIT.Equals(state))
                    {
                        IObjRef[] objRefs = ((IObjRefContainer)_target).Get__ObjRefs(relationIndex);
                        if (objRefs == null)
                        {
                            list.Add(new LazyUnknownMember(propertyName, state, member.RealType));
                        }
                        else
                        {
                            list.Add(new LazyMember(propertyName, state, objRefs, member.RealType));
                        }
                        continue;
                    }
                }
                if (value == null)
                {
                    try
                    {
                        value = member.GetValue(_target);
                    }
                    catch (Exception ex)
                    {
                        value = ex;
                    }
                }
                list.Add(new FHPMember(propertyName, value, member.RealType));
            }
            return(list.OrderBy(m => m.Name).ToList());
        }
        public static TypeDisplayData GetTypeDisplayData(this Type type)
        {
            if (type == null)
            {
                return(null);
            }

            Dictionary <string, DebuggerBrowsableState> memberData = null;
            bool   isCompilerGenerated = false;
            string displayValue        = null;
            string displayName         = null;
            string displayType         = null;
            string proxyType           = null;

            try {
                foreach (var attr in type.GetCustomAttributes(true))
                {
                    if (attr is DebuggerDisplayAttribute display)
                    {
                        displayValue = display.Value;
                        displayName  = display.Name;
                        displayType  = display.Type;
                    }
                    else if (attr is DebuggerTypeProxyAttribute proxy)
                    {
                        proxyType = proxy.ProxyTypeName;
                    }
                    else if (attr is CompilerGeneratedAttribute)
                    {
                        isCompilerGenerated = true;
                    }
                }

                foreach (var field in type.GetFields())
                {
                    var attrs     = field.GetCustomAttributes(true);
                    var browsable = GetAttribute <DebuggerBrowsableAttribute> (attrs);

                    if (browsable == null)
                    {
                        var generated = GetAttribute <CompilerGeneratedAttribute> (attrs);
                        if (generated != null)
                        {
                            browsable = new DebuggerBrowsableAttribute(DebuggerBrowsableState.Never);
                        }
                    }

                    if (browsable != null)
                    {
                        if (memberData == null)
                        {
                            memberData = new Dictionary <string, DebuggerBrowsableState> ();
                        }
                        memberData[field.Name] = browsable.State;
                    }
                }

                foreach (var property in type.GetProperties())
                {
                    var browsable = GetAttribute <DebuggerBrowsableAttribute> (property.GetCustomAttributes(true));
                    if (browsable != null)
                    {
                        if (memberData == null)
                        {
                            memberData = new Dictionary <string, DebuggerBrowsableState> ();
                        }
                        memberData[property.Name] = browsable.State;
                    }
                }
            } catch (Exception ex) {
                LoggingService.LogError("GetTypeDisplayData error", ex);
            }

            return(new TypeDisplayData(proxyType, displayValue, displayType, displayName, isCompilerGenerated, memberData));
        }
Exemple #6
0
        protected override TypeDisplayData OnGetTypeDisplayData(EvaluationContext ctx, object gtype)
        {
            CorType type = (CorType)gtype;

            CorEvaluationContext wctx = (CorEvaluationContext)ctx;
            Type t = type.GetTypeInfo(wctx.Session);

            if (t == null)
            {
                return(null);
            }

            string proxyType          = null;
            string nameDisplayString  = null;
            string typeDisplayString  = null;
            string valueDisplayString = null;
            Dictionary <string, DebuggerBrowsableState> memberData = null;
            bool hasTypeData = false;

            foreach (object att in t.GetCustomAttributes(false))
            {
                DebuggerTypeProxyAttribute patt = att as DebuggerTypeProxyAttribute;
                if (patt != null)
                {
                    proxyType   = patt.ProxyTypeName;
                    hasTypeData = true;
                    continue;
                }
                DebuggerDisplayAttribute datt = att as DebuggerDisplayAttribute;
                if (datt != null)
                {
                    hasTypeData        = true;
                    nameDisplayString  = datt.Name;
                    typeDisplayString  = datt.Type;
                    valueDisplayString = datt.Value;
                    continue;
                }
            }

            ArrayList mems = new ArrayList();

            mems.AddRange(t.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance));
            mems.AddRange(t.GetProperties(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.Instance));

            foreach (MemberInfo m in mems)
            {
                object[] atts = m.GetCustomAttributes(typeof(DebuggerBrowsableAttribute), false);
                if (atts.Length == 0)
                {
                    atts = m.GetCustomAttributes(typeof(System.Runtime.CompilerServices.CompilerGeneratedAttribute), false);
                    if (atts.Length > 0)
                    {
                        atts[0] = new DebuggerBrowsableAttribute(DebuggerBrowsableState.Never);
                    }
                }
                if (atts.Length > 0)
                {
                    hasTypeData = true;
                    if (memberData == null)
                    {
                        memberData = new Dictionary <string, DebuggerBrowsableState> ();
                    }
                    memberData[m.Name] = ((DebuggerBrowsableAttribute)atts[0]).State;
                }
            }
            if (hasTypeData)
            {
                return(new TypeDisplayData(proxyType, valueDisplayString, typeDisplayString, nameDisplayString, false, memberData));
            }
            else
            {
                return(null);
            }
        }
        public void Ctor_State(DebuggerBrowsableState state)
        {
            var attribute = new DebuggerBrowsableAttribute(state);

            Assert.Equal(state, attribute.State);
        }
        protected override TypeDisplayData OnGetTypeDisplayData(EvaluationContext gctx, object type)
        {
            SoftEvaluationContext ctx = (SoftEvaluationContext)gctx;
            TypeDisplayData       td  = new TypeDisplayData();

            try {
                TypeMirror t = (TypeMirror)type;
                foreach (CustomAttributeDataMirror attr in t.GetCustomAttributes(true))
                {
                    string attName = attr.Constructor.DeclaringType.FullName;
                    if (attName == "System.Diagnostics.DebuggerDisplayAttribute")
                    {
                        DebuggerDisplayAttribute at = BuildAttribute <DebuggerDisplayAttribute> (attr);
                        td.NameDisplayString  = at.Name;
                        td.TypeDisplayString  = at.Type;
                        td.ValueDisplayString = at.Value;
                    }
                    else if (attName == "System.Diagnostics.DebuggerTypeProxyAttribute")
                    {
                        DebuggerTypeProxyAttribute at = BuildAttribute <DebuggerTypeProxyAttribute> (attr);
                        td.ProxyType = at.ProxyTypeName;
                        if (!string.IsNullOrEmpty(td.ProxyType))
                        {
                            ForceLoadType(ctx, td.ProxyType);
                        }
                    }
                }
                foreach (FieldInfoMirror fi in t.GetFields())
                {
                    CustomAttributeDataMirror[] attrs = fi.GetCustomAttributes(true);
                    DebuggerBrowsableAttribute  att   = GetAttribute <DebuggerBrowsableAttribute> (attrs);
                    if (att == null)
                    {
                        var cga = GetAttribute <System.Runtime.CompilerServices.CompilerGeneratedAttribute> (attrs);
                        if (cga != null)
                        {
                            att = new DebuggerBrowsableAttribute(DebuggerBrowsableState.Never);
                        }
                    }
                    if (att != null)
                    {
                        if (td.MemberData == null)
                        {
                            td.MemberData = new Dictionary <string, DebuggerBrowsableState> ();
                        }
                        td.MemberData [fi.Name] = att.State;
                    }
                }
                foreach (PropertyInfoMirror pi in t.GetProperties())
                {
                    DebuggerBrowsableAttribute att = GetAttribute <DebuggerBrowsableAttribute> (pi.GetCustomAttributes(true));
                    if (att != null)
                    {
                        if (td.MemberData == null)
                        {
                            td.MemberData = new Dictionary <string, DebuggerBrowsableState> ();
                        }
                        td.MemberData [pi.Name] = att.State;
                    }
                }
            } catch (Exception ex) {
                ctx.Session.WriteDebuggerOutput(true, ex.ToString());
            }
            return(td);
        }
Exemple #9
0
        protected virtual List <IMember> BuildMemberList()
        {
            List <IMember> list = new List <IMember>();

            if (_target == null)
            {
                return(list);
            }
            if (Context != null)
            {
                ITypeInfoItem[] members = Context.GetService <ITypeInfoProvider>().GetTypeInfo(_target.GetType()).Members;
                foreach (ITypeInfoItem member in members)
                {
                    DebuggerBrowsableAttribute att = member.GetAnnotation <DebuggerBrowsableAttribute>();
                    if (att != null && att.State == DebuggerBrowsableState.Never)
                    {
                        continue;
                    }
                    if (!member.CanRead)
                    {
                        continue;
                    }
                    Object value;
                    try
                    {
                        value = member.GetValue(_target);
                    }
                    catch (Exception ex)
                    {
                        value = ex;
                    }
                    list.Add(new FHPMember(member.Name, value, member.RealType));
                }
            }
            else
            {
                var  flags    = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.FlattenHierarchy;
                var  type     = _target.GetType();
                Type currType = type;
                while (currType != null && !typeof(Object).Equals(currType))
                {
                    foreach (var field in currType.GetFields(flags))
                    {
                        var debuggerBrowsableAtts = field.GetCustomAttributes(typeof(DebuggerBrowsableAttribute), true);
                        if (debuggerBrowsableAtts.Count() == 1)
                        {
                            var att = debuggerBrowsableAtts[0] as DebuggerBrowsableAttribute;
                            if (att.State == DebuggerBrowsableState.Never)
                            {
                                continue;
                            }
                        }
                        if (field.Name.EndsWith("k__BackingField"))
                        {
                            continue;
                        }
                        var value = field.GetValue(_target);
                        list.Add(new FHPMember(field.Name, value, field.FieldType));
                    }
                    foreach (var prop in currType.GetProperties(flags))
                    {
                        var debuggerBrowsableAtts = prop.GetCustomAttributes(typeof(DebuggerBrowsableAttribute), true);
                        if (debuggerBrowsableAtts.Count() == 1)
                        {
                            var att = debuggerBrowsableAtts[0] as DebuggerBrowsableAttribute;
                            if (att.State == DebuggerBrowsableState.Never)
                            {
                                continue;
                            }
                        }
                        Object value = null;
                        try
                        {
                            value = prop.GetValue(_target, null);
                        }
                        catch (Exception ex)
                        {
                            value = ex;
                        }
                        list.Add(new FHPMember(prop.Name, value, prop.PropertyType));
                    }
                    currType = currType.BaseType;
                }
            }
            return(list.OrderBy(m => m.Name).ToList());
        }