Esempio n. 1
0
 /// <summary>
 ///     Returns the title from the underlying business object. If the object has not yet been resolved the
 ///     specification will be asked for a unresolved title, which could of been persisted by the persistence
 ///     mechanism. If either of the above provides null as the title then this method will return a title
 ///     relating to the name of the object type, e.g. "A Customer", "A Product".
 /// </summary>
 public string TitleString()
 {
     try {
         if (Spec.IsCollection && !Spec.IsParseable)
         {
             return(CollectionTitleString(Spec.GetFacet <ICollectionFacet>()));
         }
         return(Spec.GetTitle(this) ?? DefaultTitle);
     }
     catch (Exception e) {
         throw new TitleException(Log.LogAndReturn("Exception on ToString POCO: " + (poco == null ? "unknown" : poco.GetType().FullName)), e);
     }
 }
Esempio n. 2
0
        private Tuple <INakedObjectAdapter, TypeOfDefaultValue> GetDefaultValueAndType(INakedObjectAdapter nakedObjectAdapter)
        {
            if (parentAction.IsContributedMethod && nakedObjectAdapter != null)
            {
                IActionParameterSpec[] matchingParms = parentAction.Parameters.Where(p => nakedObjectAdapter.Spec.IsOfType(p.Spec)).ToArray();

                if (matchingParms.Any() && matchingParms.First() == this)
                {
                    return(new Tuple <INakedObjectAdapter, TypeOfDefaultValue>(nakedObjectAdapter, TypeOfDefaultValue.Explicit));
                }
            }

            Tuple <object, TypeOfDefaultValue> defaultValue = null;

            // Check Facet on parm, then facet on type finally fall back on type;

            var defaultsFacet = GetFacet <IActionDefaultsFacet>();

            if (defaultsFacet != null && !defaultsFacet.IsNoOp)
            {
                defaultValue = defaultsFacet.GetDefault(parentAction.RealTarget(nakedObjectAdapter));
            }

            if (defaultValue == null)
            {
                var defaultFacet = Spec.GetFacet <IDefaultedFacet>();
                if (defaultFacet != null && !defaultFacet.IsNoOp)
                {
                    defaultValue = new Tuple <object, TypeOfDefaultValue>(defaultFacet.Default, TypeOfDefaultValue.Implicit);
                }
            }

            if (defaultValue == null)
            {
                object rawValue = nakedObjectAdapter == null ? null : nakedObjectAdapter.Object.GetType().IsValueType ? (object)0 : null;
                defaultValue = new Tuple <object, TypeOfDefaultValue>(rawValue, TypeOfDefaultValue.Implicit);
            }

            return(new Tuple <INakedObjectAdapter, TypeOfDefaultValue>(manager.CreateAdapter(defaultValue.Item1, null, null), defaultValue.Item2));
        }
 private object CallCallbackAndReturn <T>() where T : ICallbackFacet
 {
     return(Spec.GetFacet <T>()?.InvokeAndReturn(this, session, lifecycleManager, metamodel, persistor));
 }
 // todo - better to handle null facet or bind in noop facet ?
 private void CallCallback <T>() where T : ICallbackFacet => Spec.GetFacet <T>()?.Invoke(this, session, lifecycleManager, metamodel);