Пример #1
0
        private static void ReportOwnerException(PropertyInfoEx propEx, IStateObject newValue, string old_Uid)
        {
            var stackTrace = new System.Diagnostics.StackTrace(4, true);

            var ownerInfo   = " Not owner info available";
            var ownerObject = StateManager.Current.GetParentEx(newValue);

            if (ownerObject != null)
            {
                var format =
                    " The owner of the object is an instance of class {0}, it is {1}. Look for property {2}. It could have been set during a Build call that is still of process or during an Initialize.Init which is the WebMap equivalent of a constructor. If it is used as parent reference reimplement the property as a non virtual, [StateManagement(None)] calculated property using ViewManager.GetParent(), you can also use [Reference] attribute or disable interception by removing virtual from the property";
                if (StateManager.AllBranchesAttached(ownerObject))
                {
                    ownerInfo = string.Format(format,
                                              TypeCacheUtils.GetOriginalTypeName(ownerObject.GetType()), " ATTACHED ",
                                              StateManager.GetLastPartOfUniqueID(newValue));
                }
                else
                {
                    ownerInfo = string.Format(format, "NOT ATTACHED",
                                              TypeCacheUtils.GetOriginalTypeName(ownerObject.GetType()),
                                              StateManager.GetLastPartOfUniqueID(newValue));
                }
            }
            throw new InvalidOperationException(
                      "LazyBehaviour::ProcessSetter object has already an Owner." + ownerInfo + "\r\n" +
                      "UniqueID: " + old_Uid + "\r\n" +
                      "Additional Info: \r\n" +
                      "ViewModel Type: " + newValue.GetType().FullName + "\r\n" +
                      "Property Type: " + propEx.prop.PropertyType.FullName + "\r\n" +
                      "Error Location: " + stackTrace.ToString());
        }
Пример #2
0
        /// <summary>
        /// Watchers can not be applied on IStateObjects. So we need to validate that
        /// </summary>
        /// <param name="type"></param>
        private static void ValidateWatcherType(MemberInfo memInfo)
        {
            Type   type        = null;
            string elementName = memInfo.Name;

            if (memInfo is FieldInfo)
            {
                var finfo = (FieldInfo)memInfo;
                type = finfo.FieldType;
#if DEBUG
                Debug.Assert(!typeof(IStateObject).IsAssignableFrom(type),
                             string.Format("DeltaTracker::ValidateWatcherType Error: The watcher attribute on {0}.{1} is wrong " +
                                           "because watcher attributes are meant to be used on fields that have a FieldType is not an IStateObject",
                                           TypeCacheUtils.GetOriginalTypeName(finfo.DeclaringType), elementName));
#endif
            }
            else if (memInfo is PropertyInfo)
            {
                var pinfo = (PropertyInfo)memInfo;
                type = pinfo.PropertyType;
                var isVirtual = pinfo.GetGetMethod().IsVirtual;
                Debug.Assert(!typeof(IStateObject).IsAssignableFrom(type) && !isVirtual,
                             string.Format("DeltaTracker::ValidateWatcherType Error: The watcher attribute on {0}.{1} is wrong because watcher attributes are meant to be used on non-virtual properties of types that are not an IStateObject",
                                           TypeCacheUtils.GetOriginalTypeName(pinfo.DeclaringType), elementName));
            }
        }
Пример #3
0
 private void ProcessIfOrphan()
 {
     if (!StateManager.AllBranchesAttached(_current.UniqueID))
     {
         //If we enter here we are Orphans :(
         //We asumme we got here because we are inside a surrogate and
         //that means that there is an StateObjectSurrogate associated with the parentObject
         if (parentCandidate == null)
         {
             var typeName = TypeCacheUtils.GetOriginalTypeName(_current.GetType());
             throw new NotSupportedException("The wrapped stated of type " + typeName + "object with ID" + _current.UniqueID + " does not have a valid parent reference");
         }
         var parentSurrogate = StateManager.Current.surrogateManager.GetSurrogateFor(parentCandidate, generateIfNotFound: false);
         if (parentSurrogate == null)
         {
             var typeName = TypeCacheUtils.GetOriginalTypeName(_current.GetType());
             throw new NotSupportedException("The wrapped stated of type " + typeName + "object with ID" + _current.UniqueID + " does not have a valid parent SURROGATE reference");
         }
         AdoptionInformation.StaticAdopt(parentSurrogate, _current);
     }
 }