public static bool IsAlwaysImmutable(this ITypeSpec spec) { var immutableFacet = spec.GetFacet <IImmutableFacet>(); if (immutableFacet == null) { return(false); } return(immutableFacet.Value == WhenTo.Always); }
public static bool IsImmutableOncePersisted(this ITypeSpec spec) { var immutableFacet = spec.GetFacet <IImmutableFacet>(); if (immutableFacet == null) { return(false); } return(immutableFacet.Value == WhenTo.OncePersisted); }
public ITypeFacade GetElementType(IObjectFacade objectFacade) { if (IsCollection) { var introspectableSpecification = spec.GetFacet <ITypeOfFacet>().GetValueSpec(((ObjectFacade)objectFacade).WrappedNakedObject, framework.MetamodelManager.Metamodel); var elementSpec = framework.MetamodelManager.GetSpecification(introspectableSpecification); return(new TypeFacade(elementSpec, FrameworkFacade, framework)); } return(null); }
public ITestObject AssertIsImmutable() { ITypeSpec spec = NakedObject.Spec; var facet = spec.GetFacet <IImmutableFacet>(); bool immutable = facet.Value == WhenTo.Always || facet.Value == WhenTo.OncePersisted && NakedObject.ResolveState.IsPersistent(); Assert.IsTrue(immutable, "Not immutable"); return((ITestObject)this); }
public INakedObjectSpecificationSurface GetElementType(INakedObjectSurface nakedObject) { if (IsCollection) { var introspectableSpecification = spec.GetFacet <ITypeOfFacet>().GetValueSpec(((NakedObjectWrapper)nakedObject).WrappedNakedObject, framework.MetamodelManager.Metamodel); var elementSpec = framework.MetamodelManager.GetSpecification(introspectableSpecification); return(new NakedObjectSpecificationWrapper(elementSpec, Surface, framework)); } return(null); }
private INakedObject GetValue(string[] values, ISpecification featureSpec, ITypeSpec spec) { if (!values.Any()) { return(null); } if (spec.IsParseable) { return(spec.GetFacet <IParseableFacet>().ParseTextEntry(values.First(), NakedObjectsContext.NakedObjectManager)); } if (spec.IsCollection) { return(NakedObjectsContext.GetTypedCollection(featureSpec, values)); } return(NakedObjectsContext.GetNakedObjectFromId(values.First())); }
public static ITypeOfFacet GetTypeOfFacetFromSpec(this INakedObject objectRepresentingCollection) { ITypeSpec collectionSpec = objectRepresentingCollection.Spec; return(collectionSpec.GetFacet <ITypeOfFacet>()); }
public static INakedObjectAdapter GetTypedCollection(this INakedObjectsFramework framework, ITypeSpec collectionitemSpec, IEnumerable collectionValue) { string[] rawCollection = collectionValue.Cast <string>().ToArray(); object[] objCollection; Type instanceType = TypeUtils.GetType(collectionitemSpec.FullName); var typedCollection = (IList)Activator.CreateInstance(typeof(List <>).MakeGenericType(instanceType)); if (collectionitemSpec.IsParseable) { objCollection = rawCollection.Select(s => string.IsNullOrEmpty(s) ? null : collectionitemSpec.GetFacet <IParseableFacet>().ParseTextEntry(s, framework.NakedObjectManager).Object).ToArray(); } else { // need to check if collection is actually a collection memento if (rawCollection.Count() == 1) { INakedObjectAdapter firstObj = framework.GetNakedObjectFromId(rawCollection.First()); if (firstObj != null && firstObj.Oid is ICollectionMemento) { return(firstObj); } } objCollection = rawCollection.Select(s => framework.GetNakedObjectFromId(s).GetDomainObject()).ToArray(); } objCollection.Where(o => o != null).ForEach(o => typedCollection.Add(o)); return(framework.NakedObjectManager.CreateAdapter(typedCollection.AsQueryable(), null, null)); }
public static ICollectionFacet GetCollectionFacetFromSpec(this INakedObjectAdapter objectAdapterRepresentingCollection) { ITypeSpec collectionSpec = objectAdapterRepresentingCollection.Spec; return(collectionSpec.GetFacet <ICollectionFacet>()); }