예제 #1
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>();
        }
예제 #2
0
        public override bool ProcessParams(MethodInfo method, int paramNum, IFacetHolder holder) {
            var facets = new List<IFacet>();

            if (holder is DotNetNakedObjectActionParamPeer) {
                var param = (DotNetNakedObjectActionParamPeer) holder;

                INamedFacet namedFacet;
                string name = method.GetParameters()[paramNum].Name;

                if (name == null) {
                    namedFacet = new NamedFacetNone(holder);
                }
                else {
                    namedFacet = new NamedFacetInferred(NameUtils.NaturalName(name), holder);
                }

                facets.Add(namedFacet);
                facets.Add(new DescribedAsFacetNone(holder));
                facets.Add(new MultiLineFacetNone(holder));
                facets.Add(new MaxLengthFacetZero(holder));
                facets.Add(new TypicalLengthFacetZero(holder));
                DefaultTypicalLength(facets, param.Specification, holder);
            }

            return FacetUtils.AddFacets(facets);
        }