Ejemplo n.º 1
0
 public DotNetSpecification(Type type, DotNetReflector reflector) {
     introspector = new DotNetIntrospector(type, this, reflector);
     identifier = new IdentifierImpl(type.FullName);
 }
Ejemplo n.º 2
0
        public override void Introspect(FacetDecoratorSet decorator) {
            if (introspector == null) {
                throw new ReflectionException("Introspection already taken place, cannot introspect again");
            }

            introspector.IntrospectClass();

            Type = introspector.IntrospectedType;
            fullName = introspector.FullName;
            shortName = introspector.ShortName;
            var namedFacet = GetFacet<INamedFacet>();
            if (namedFacet == null) {
                namedFacet = new NamedFacetInferred(NameUtils.NaturalName(shortName), this);
                AddFacet(namedFacet);
            }

            var pluralFacet = GetFacet<IPluralFacet>();
            if (pluralFacet == null) {
                pluralFacet = new PluralFacetInferred(NameUtils.PluralName(namedFacet.Value), this);
                AddFacet(pluralFacet);
            }

            whetherAbstract = introspector.IsAbstract;
            whetherInterface = introspector.IsInterface;
            whetherSealed = introspector.IsSealed;
            whetherVoid = introspector.IsVoid;

            string superclassName = introspector.SuperclassName;
            string[] interfaceNames = introspector.InterfacesNames;

            INakedObjectReflector reflector = NakedObjectsContext.Reflector;
            if (superclassName != null && !TypeUtils.IsSystem(superclassName)) {
                superClassSpecification = reflector.LoadSpecification(superclassName);
                if (superClassSpecification != null) {
                    Log.DebugFormat("Superclass {0}", superclassName);
                    superClassSpecification.AddSubclass(this);
                }
            }
            else if (Type != typeof (object)) {
                // always root in object (unless this is object!) 
                superClassSpecification = reflector.LoadSpecification(typeof (object));
                if (superClassSpecification != null) {
                    Log.DebugFormat("Superclass {0}", typeof (object).Name);
                    superClassSpecification.AddSubclass(this);
                }
            }

            var interfaceList = new List<INakedObjectSpecification>();
            foreach (string interfaceName in interfaceNames) {
                INakedObjectSpecification interfaceSpec = reflector.LoadSpecification(interfaceName);
                interfaceSpec.AddSubclass(this);
                interfaceList.Add(interfaceSpec);
            }

            interfaces = interfaceList.ToArray();

            introspector.IntrospectPropertiesAndCollections();
            fields = OrderFields(introspector.Fields);

            validationMethods = introspector.IntrospectObjectValidationMethods();

            introspector.IntrospectActions();
            objectActions = OrderActions(introspector.ObjectActions);

            introspector = null;

            DecorateAllFacets(decorator);
            iconFacet = GetFacet<IIconFacet>();
        }