Beispiel #1
0
        internal static SPModel TryCreate(ISPListItemAdapter adapter, SPModelCollection parentCollection)
        {
            CommonHelper.ConfirmNotNull(adapter, "adapter");
            CommonHelper.ConfirmNotNull(parentCollection, "parentCollection");

            SPModelDescriptor exactType;

            try {
                exactType = SPModelDescriptor.Resolve(adapter.ContentTypeId);
            } catch (ArgumentException) {
                return(null);
            }
            if (exactType.ModelType.IsGenericType)
            {
                throw new InvalidOperationException(String.Format("Cannot create object from generic type '{0}'. Consider adding SPModelManagerDefaultTypeAttribute to the model class.", exactType.ModelType.FullName));
            }
            try {
                calledByInternal = true;
                SPModel item = (SPModel)exactType.ModelInstanceType.CreateInstance();
                item.Adapter          = Intercept.ThroughProxy(adapter, new TransparentProxyInterceptor(), new[] { new SPListItemAdapterInterceptionBehavior(item, adapter, parentCollection) });
                item.ParentCollection = parentCollection;
                return(item);
            } finally {
                calledByInternal = false;
            }
        }
Beispiel #2
0
 public SPListItemAdapterInterceptionBehavior(SPModel item, ISPListItemAdapter adapter, SPModelCollection parentCollection)
 {
     CommonHelper.ConfirmNotNull(item, "item");
     CommonHelper.ConfirmNotNull(adapter, "adapter");
     CommonHelper.ConfirmNotNull(parentCollection, "parentCollection");
     this.parentCollection = parentCollection;
     this.adapter          = adapter;
     this.item             = item;
 }