Ejemplo n.º 1
0
        public ReflectionObjectEditor(object target)
        {
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

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

            this.properties.AddRange(ReflectionEditorProvider.GetPropertiesForType(targetType));

            foreach (EventInfo ev in targetType.GetEvents())
            {
                this.events.Add(new ReflectionEventInfo(ev));
            }
        }
Ejemplo n.º 2
0
        internal static Task <AssignableTypesResult> GetAssignableTypes(ITypeInfo type, bool childTypes)
        {
            return(Task.Run(() => {
                var types = AppDomain.CurrentDomain.GetAssemblies().SelectMany(a => a.GetTypes()).AsParallel()
                            .Where(t => {
                    try {
                        return t.Namespace != null && !t.IsAbstract && !t.IsInterface && t.IsPublic && t.GetConstructor(Type.EmptyTypes) != null;
                    } catch (TypeLoadException) {
                        return false;
                    }
                });

                Type realType = ReflectionEditorProvider.GetRealType(type);
                if (childTypes)
                {
                    var generic = realType.GetInterface("ICollection`1");
                    if (generic != null)
                    {
                        realType = generic.GetGenericArguments()[0];
                    }
                    else
                    {
                        realType = typeof(object);
                    }
                }

                if (realType != typeof(Type))
                {
                    types = types.Where(t => realType.IsAssignableFrom(t));
                }

                return new AssignableTypesResult(types.Select(t => {
                    string asmName = t.Assembly.GetName().Name;
                    return new TypeInfo(new AssemblyInfo(asmName, isRelevant: asmName.StartsWith("Xamarin")), t.Namespace, t.Name);
                }).ToList());
            }));
        }