コード例 #1
0
        public static ICEFInfraWrapper?CreateInfraWrapper(WrappingSupport need, WrappingAction action, bool isNew, object o, ObjectState?initState, IDictionary <string, object?>?props, IDictionary <string, Type>?types)
        {
            // Goal is to provision the lowest overhead object based on need!
            ICEFInfraWrapper?infrawrap = null;

            if (action != WrappingAction.NoneOrProvisionedAlready)
            {
                if ((o is INotifyPropertyChanged) || (need & WrappingSupport.Notifications) == 0)
                {
                    if ((need & WrappingSupport.DataErrors) != 0)
                    {
                        infrawrap = new DynamicWithValuesBagErrors(o, initState.GetValueOrDefault(isNew ? ObjectState.Added : ObjectState.Unchanged), props, types);
                    }
                    else
                    {
                        if ((need & WrappingSupport.OriginalValues) != 0)
                        {
                            infrawrap = new DynamicWithValuesAndBag(o, initState.GetValueOrDefault(isNew ? ObjectState.Added : ObjectState.Unchanged), props, types);
                        }
                        else
                        {
                            infrawrap = new DynamicWithBag(o, props, types);
                        }
                    }
                }
                else
                {
                    infrawrap = new DynamicWithAll(o, initState.GetValueOrDefault(isNew ? ObjectState.Added : ObjectState.Unchanged), props, types);
                }
            }

            return(infrawrap);
        }
コード例 #2
0
 public static ICEFWrapper CreateWrapper(WrappingSupport need, WrappingAction action, bool isNew, object o, ServiceScope ss, IDictionary <string, object> props = null, IDictionary <string, Type> types = null, IDictionary <object, object> visits = null)
 {
     return(InternalCreateWrapper(need, action, isNew, o, Globals.MissingWrapperAllowed, ss, new Dictionary <object, ICEFWrapper>(Globals.DefaultDictionaryCapacity), props, types, visits ?? new Dictionary <object, object>(Globals.DefaultDictionaryCapacity)));
 }
コード例 #3
0
        private static ICEFWrapper InternalCreateWrapper(WrappingSupport need, WrappingAction action, bool isNew, object o, bool missingAllowed, ServiceScope ss, IDictionary <object, ICEFWrapper> wrappers, IDictionary <string, object> props, IDictionary <string, Type> types, IDictionary <object, object> visits)
        {
            // Try to not duplicate wrappers: return one if previously generated in this parsing instance
            if (wrappers.ContainsKey(o))
            {
                return(wrappers[o]);
            }

            ICEFWrapper replwrap = null;

            if (Globals.DefaultWrappingAction == WrappingAction.PreCodeGen)
            {
                var fqn = GetFullyQualifiedWrapperName(o);

                if (string.IsNullOrEmpty(fqn))
                {
                    throw new CEFInvalidOperationException($"Failed to determine name of wrapper class for object of type {o.GetType().Name}.");
                }

                if (!_typeByName.TryGetValue(fqn, out Type t))
                {
                    t = Type.GetType(fqn, false, true);
                    _typeByName[fqn] = t;
                }

                if (t == null)
                {
                    if (missingAllowed)
                    {
                        return(null);
                    }
                    throw new CEFInvalidOperationException($"Failed to create wrapper object of type {fqn} for object of type {o.GetType().Name}.");
                }

                // Relies on parameterless constructor
                var wrapper = t.FastCreateNoParm();

                if (wrapper == null)
                {
                    if (missingAllowed)
                    {
                        return(null);
                    }
                    throw new CEFInvalidOperationException($"Failed to create wrapper object of type {fqn} for object of type {o.GetType().Name}.");
                }

                if (!(wrapper is ICEFWrapper))
                {
                    if (missingAllowed)
                    {
                        return(null);
                    }
                    throw new CEFInvalidOperationException($"Wrapper object of type {fqn} for object of type {o.GetType().Name} does not implement ICEFWrapper.");
                }

                visits[o] = wrapper;

                replwrap = (ICEFWrapper)wrapper;

                // Effectively presents all current values - we assume codegen has properly implemented use of storage
                replwrap.SetCopyTo(o);

                // Deep copy of properties on this object
                CopyPropertyValuesObject(o, replwrap, isNew, ss, null, visits);
            }

            return(replwrap);
        }