Exemplo n.º 1
0
        public object New(Type type)
        {
            try
            {
                var x = type.GetConstructor(System.Type.EmptyTypes);

                if (x == null)
                {
                    // Need to be using an log message type so that the exceptions can be filtered by a more advnced logging package.  This gets rid of the need to pass in a global context,
                    // as a more advanced logging system can filter the messages by type if it needed to adjust the verbosity.
                    XLogBase.LogError(null, new NoPublicConstructorsWithEmptyArguementsLogMessage()
                    {
                        Message = new Message()
                        {
                            Value = $"There are no public empty argument constructors for type '{type.AssemblyQualifiedName}'.  An instance could not be created."
                        }
                    });

                    //XLogBase.LogError(XContextualBase.GetGlobal(), $"There are no public empty argument constructors for type '{type.AssemblyQualifiedName}'.  An instance could not be created.");



                    return(null);
                }

                return(x.Invoke(null));
            }
            catch (System.Exception exception)
            {
                //XLogBase.LogException(XContextualBase.GetGlobal(), exception);

                XLogBase.LogException(null, exception);

                return(null);
            }
        }
Exemplo n.º 2
0
        public object New(Type type)
        {
            try
            {
                var x = type.GetConstructor(System.Type.EmptyTypes);

                if (x == null)
                {
                    // Need to be using an log message type so that the exceptions can be filtered by a more advnced logging package.  This gets rid of the need to pass in a global context,
                    // as a more advanced logging system can filter the messages by type if it needed to adjust the verbosity.
                    XLogBase.LogError(null, new NoPublicConstructorsWithEmptyArguementsLogMessage()
                    {
                        Message = new Message()
                        {
                            Value = $"There are no public empty argument constructors for type '{type.AssemblyQualifiedName}'.  An instance could not be created."
                        }
                    });

                    //XLogBase.LogError(XContextualBase.GetGlobal(), $"There are no public empty argument constructors for type '{type.AssemblyQualifiedName}'.  An instance could not be created.");



                    return(null);
                }

                var result = x.Invoke(null);

                var resultId = result as Ided_I;

                if (resultId != null)
                {
                    resultId.Id = XIdentification.IssueId();
                }

                var typed = result as Typed_I;

                if (typed != null)
                {
                    if (typed?.TypeId == null)
                    {
                        typed.TypeId = XTypeIdentification.GetTypeId(type);
                    }
                }

                var poco = result as Poco_I;

                if (poco != null)
                {
                    poco.VersionId = XVersionId.New();
                }

                return(result);
            }
            catch (System.Exception exception)
            {
                //XLogBase.LogException(XContextualBase.GetGlobal(), exception);

                XLogBase.LogException(null, exception);

                return(null);
            }
        }