示例#1
0
 protected override void Validate()
 {
     base.Validate();
     ChoGuard.ArgumentNotNullOrEmpty(CodeSnippet, "CodeSnippet");
 }
 protected override void Validate()
 {
     base.Validate();
     ChoGuard.ArgumentNotNullOrEmpty(TypeName, "TypeName");
     ChoGuard.ArgumentNotNullOrEmpty(MethodName, "MethodName");
 }
示例#3
0
        public bool ContainsProperty(string propertyName)
        {
            ChoGuard.ArgumentNotNull(_keyValuePropertyReplacer, "KeyValuePropertyReplacer");

            return(_keyValuePropertyReplacer.ContainsProperty(propertyName));
        }
示例#4
0
        public string ReplaceProperty(string propertyName, string format)
        {
            ChoGuard.ArgumentNotNull(_keyValuePropertyReplacer, "KeyValuePropertyReplacer");

            return(_keyValuePropertyReplacer.ReplaceProperty(propertyName, format));
        }
示例#5
0
        public static T GetMe <T>(object target) where T : Attribute
        {
            ChoGuard.ArgumentNotNull(target, "Target");

            return(GetMe <T>(target.GetType()));
        }
示例#6
0
 public static T GetMe <T>(Type type) where T : Attribute
 {
     ChoGuard.ArgumentNotNull(type, "Type");
     return(ChoType.GetAttribute <T>(type));
 }
示例#7
0
        public ChoRegistrySectionAttribute1(string registryKey)
        {
            ChoGuard.ArgumentNotNullOrEmpty(registryKey, "RegistryKey");

            _registryKey = registryKey;
        }
示例#8
0
 public ChoNameableObject(Type type)
 {
     ChoGuard.ArgumentNotNullOrEmpty(type, "Type");
     Name = type.FullName;
 }
示例#9
0
 public ChoNameableObject(string name)
 {
     ChoGuard.ArgumentNotNullOrEmpty(name, "Name");
     Name = name;
 }
示例#10
0
 public ChoAppDomainLoadMethodAttribute(string description)
 {
     ChoGuard.ArgumentNotNull(description, "Description");
     _description = description;
 }
示例#11
0
        public static string ToString(Exception exception, NameValueCollection additionalInfo)
        {
            ChoGuard.ArgumentNotNull(exception, "Exception");

            // Create StringBuilder to maintain publishing information.
            StringBuilder info = new StringBuilder();

            #region Record the contents of the AdditionalInfo collection
            // Record the contents of the AdditionalInfo collection.
            if (additionalInfo != null)
            {
                // Record General information.
                info.AppendFormat("{0}General Information {0}{1}{0}Additional Info:", Environment.NewLine, _textSeparator);

                foreach (string i in additionalInfo)
                {
                    info.AppendFormat("{0}{1}: {2}", Environment.NewLine, i, additionalInfo.Get(i));
                }
            }
            #endregion

            if (exception == null)
            {
                info.AppendFormat("{0}{0}No Exception object has been provided.{0}", Environment.NewLine);
            }
            else
            {
                #region Loop through each exception class in the chain of exception objects
                // Loop through each exception class in the chain of exception objects.
                Exception currentException  = exception; // Temp variable to hold InnerException object during the loop.
                int       intExceptionCount = 1;         // Count variable to track the number of exceptions in the chain.
                do
                {
                    // Write title information for the exception object.
                    info.AppendFormat("{0}{0}{1}) Exception Information{0}{2}", Environment.NewLine, intExceptionCount.ToString(), _textSeparator);
                    info.AppendFormat("{0}Exception Type: {1}", Environment.NewLine, currentException.GetType().FullName);

                    #region Loop through the public properties of the exception object and record their value
                    // Loop through the public properties of the exception object and record their value.
                    PropertyInfo[]      aryPublicProperties = currentException.GetType().GetProperties();
                    NameValueCollection currentAdditionalInfo;
                    foreach (PropertyInfo p in aryPublicProperties)
                    {
                        // Do not log information for the InnerException or StackTrace. This information is
                        // captured later in the process.
                        if (p.Name != "InnerException" && p.Name != "StackTrace")
                        {
                            if (p.GetValue(currentException, null) == null)
                            {
                                info.AppendFormat("{0}{1}: NULL", Environment.NewLine, p.Name);
                            }
                            else
                            {
                                // Loop through the collection of AdditionalInformation if the exception type is a ChoAApplicationException.
                                if (p.Name == "AdditionalInformation" && currentException is ChoApplicationException)
                                {
                                    // Verify the collection is not null.
                                    if (p.GetValue(currentException, null) != null)
                                    {
                                        // Cast the collection into a local variable.
                                        currentAdditionalInfo = (NameValueCollection)p.GetValue(currentException, null);

                                        // Check if the collection contains values.
                                        if (currentAdditionalInfo.Count > 0)
                                        {
                                            info.AppendFormat("{0}AdditionalInformation:", Environment.NewLine);

                                            // Loop through the collection adding the information to the string builder.
                                            for (int i = 0; i < currentAdditionalInfo.Count; i++)
                                            {
                                                info.AppendFormat("{0}{1}: {2}", Environment.NewLine, currentAdditionalInfo.GetKey(i), currentAdditionalInfo[i]);
                                            }
                                        }
                                    }
                                }
                                // Otherwise just write the ToString() value of the property.
                                else
                                {
                                    object value = p.GetValue(currentException, null);
                                    if (value is ICollection)
                                    {
                                        info.AppendFormat("{0}{1}: {0}", Environment.NewLine, p.Name);
                                        foreach (object item in (IEnumerable)value)
                                        {
                                            if (item is Exception)
                                            {
                                                info.AppendLine((item as Exception).ToString().Indent());
                                                //info.AppendLine(ChoApplicationException.ToString(item as Exception).Indent());
                                            }
                                            else
                                            {
                                                info.AppendLine(ChoObject.ToString(item).Indent());
                                            }
                                        }
                                    }
                                    else
                                    {
                                        info.AppendFormat("{0}{1}: {2}", Environment.NewLine, p.Name, p.GetValue(currentException, null));
                                    }
                                }
                            }
                        }
                    }
                    #endregion
                    #region Record the Exception StackTrace
                    // Record the StackTrace with separate label.
                    if (currentException.StackTrace != null)
                    {
                        info.AppendFormat("{0}{0}StackTrace Information{0}{1}", Environment.NewLine, _textSeparator);
                        info.AppendFormat("{0}{1}", Environment.NewLine, currentException.StackTrace);
                    }
                    #endregion

                    // Reset the temp exception object and iterate the counter.
                    currentException = currentException.InnerException;
                    intExceptionCount++;
                } while (currentException != null);
                #endregion
            }

            info.AppendFormat("{0}{1}", Environment.NewLine, ChoTrace.SEPARATOR);

            return(info.ToString());
        }