Пример #1
0
        private bool CheckIfStringEndsWithValue(string candidateAsString)
        {
            var theObjectAsString = TheObject as string;

            if (theObjectAsString != null)
            {
                return(candidateAsString.EndsWith(theObjectAsString,
                                                  _isCaseSensitive
                                                      ? StringComparison.Ordinal
                                                      : StringComparison.OrdinalIgnoreCase));
            }

            throw new OdbRuntimeException(
                      NDatabaseError.QueryEndsWithConstraintTypeNotSupported.AddParameter(TheObject.GetType().FullName));
        }
Пример #2
0
        protected override void LoadChildren()
        {
            bool            referenceLoop = false;
            ObjectViewModel parent        = ParentObject;

            while (parent != null)
            {
                if (parent.TheObject == TheObject)
                {
                    referenceLoop = true;
                    break;
                }
                parent = parent.ParentObject;
            }

            if (TheObject != null && referenceLoop)
            {
                var child = new InfoNode("Reference loop", Brushes.Gray, loopIcon);
                Children.Add(child);
            }
            else if (TheObject != null && canLoadChildren)
            {
                if (TheObject.GetType().IsArray)
                {
                    Array a = (Array)TheObject;
                    for (int i = 0; i < a.Length; i++)
                    {
                        object value = a.GetValue(i);
                        Children.Add(new ObjectViewModel($"[{i}]", value, TheObject.GetType().GetElementType(), fieldIcon, null, elementLevel));
                    }
                }
                else if (IsEnumerable(TheObject))
                {
                    int i = 0;
                    foreach (var value in TheObject as IEnumerable)
                    {
                        Children.Add(new ObjectViewModel($"[{i}]", value, value.GetType(), fieldIcon, null, elementLevel));
                        i++;
                    }
                }
                else
                {
                    foreach (var propInfo in TheObject.GetType()
                             .GetProperties(BindingFlags.Instance | BindingFlags.Public)
                             .Where(p => p.GetMethod != null)
                             .OrderBy(p => p.Name))
                    {
                        object value      = null;
                        Brush  valueColor = null;
                        try
                        {
                            value = propInfo.GetValue(TheObject);
                        }
                        catch (Exception ex)
                        {
                            value      = "[" + ex.Message + "]";
                            valueColor = Brushes.OrangeRed;
                        }
                        var child = new ObjectViewModel(propInfo.Name, value, propInfo.PropertyType, propertyIcon, valueColor, elementLevel);
                        Children.Add(child);
                        SetFontWeight(propInfo, child);
                        //if (TheObject.GetType() == typeof(Mono.Cecil.Cil.MethodBody) && propInfo.Name == "Instructions")
                        //{
                        //	child.IsExpanded = true;
                        //}
                    }

                    foreach (var fieldInfo in TheObject.GetType()
                             .GetFields(BindingFlags.Instance | BindingFlags.Public)
                             .OrderBy(f => f.Name))
                    {
                        object value      = null;
                        Brush  valueColor = null;
                        try
                        {
                            value = fieldInfo.GetValue(TheObject);
                        }
                        catch (Exception ex)
                        {
                            value      = "[" + ex.Message + "]";
                            valueColor = Brushes.OrangeRed;
                        }
                        Children.Add(new ObjectViewModel(fieldInfo.Name, value, fieldInfo.FieldType, fieldIcon, valueColor, elementLevel));
                    }

                    foreach (var methodInfo in TheObject.GetType()
                             .GetMethods(BindingFlags.Instance | BindingFlags.Public)
                             .Where(m => m.Name != "Clone")
                             .Where(m => m.Name != "GetHashCode")
                             .Where(m => m.Name != "GetType")
                             .Where(m => m.Name != "ToString")
                             .Where(m => !m.Name.StartsWith("get_"))
                             .Where(m => m.ReturnType != typeof(void))
                             .Where(m => m.GetParameters().Length == 0)
                             .OrderBy(m => m.Name))
                    {
                        object value      = null;
                        Brush  valueColor = null;
                        try
                        {
                            value = methodInfo.Invoke(TheObject, new object[0]);
                        }
                        catch (Exception ex)
                        {
                            value      = ex;
                            valueColor = Brushes.OrangeRed;
                        }
                        Children.Add(new ObjectViewModel(methodInfo.Name + "()", value, methodInfo.ReturnType, methodIcon, valueColor, elementLevel));
                    }
                }
            }
            IsChildrenLoaded = true;
            ForNode(this, o => o.HighlightObject());
        }
Пример #3
0
 private void SetFontWeight(PropertyInfo propInfo, ObjectViewModel item)
 {
     if (TheObject.GetType() == typeof(Mono.Cecil.AssemblyDefinition))
     {
         if (propInfo.Name == "EntryPoint" ||
             propInfo.Name == "MainModule")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.CustomAttribute))
     {
         if (propInfo.Name == "AttributeType" ||
             propInfo.Name == "ConstructorArguments")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.FieldDefinition))
     {
         if (propInfo.Name == "Constant" ||
             propInfo.Name == "CustomAttributes" ||
             propInfo.Name == "FieldType")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.GenericInstanceMethod))
     {
         if (propInfo.Name == "DeclaringType" ||
             propInfo.Name == "GenericArguments" ||
             propInfo.Name == "Parameters" ||
             propInfo.Name == "ReturnType")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.GenericInstanceType))
     {
         if (propInfo.Name == "GenericArguments")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.GenericParameter))
     {
         if (propInfo.Name == "Constraints")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.Cil.Instruction))
     {
         if (propInfo.Name == "OpCode" ||
             propInfo.Name == "Operand")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.Cil.MethodBody))
     {
         if (propInfo.Name == "Instructions" ||
             propInfo.Name == "Variables")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.MethodDefinition))
     {
         if (propInfo.Name == "Body" ||
             propInfo.Name == "CustomAttributes" ||
             propInfo.Name == "GenericParameters" ||
             propInfo.Name == "Parameters" ||
             propInfo.Name == "ReturnType")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.MethodReference))
     {
         if (propInfo.Name == "DeclaringType" ||
             propInfo.Name == "Parameters" ||
             propInfo.Name == "ReturnType")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.ModuleDefinition))
     {
         if (propInfo.Name == "Types")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.ParameterDefinition))
     {
         if (propInfo.Name == "ParameterType")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.PropertyDefinition))
     {
         if (propInfo.Name == "CustomAttributes" ||
             propInfo.Name == "GetMethod" ||
             propInfo.Name == "PropertyType" ||
             propInfo.Name == "SetMethod")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
     if (TheObject.GetType() == typeof(Mono.Cecil.TypeDefinition))
     {
         if (propInfo.Name == "BaseType" ||
             propInfo.Name == "CustomAttributes" ||
             propInfo.Name == "Events" ||
             propInfo.Name == "Fields" ||
             propInfo.Name == "Interfaces" ||
             propInfo.Name == "Methods" ||
             propInfo.Name == "NestedTypes" ||
             propInfo.Name == "Properties")
         {
             ((TextBlock)item.Text).FontWeight = FontWeights.Bold;
         }
     }
 }
Пример #4
0
 private void SetValue()
 {
     if (TheObject == null)
     {
         Value           = "null";
         ValueColor      = Brushes.Gray;
         canLoadChildren = false;
     }
     else if (TheObject is bool)
     {
         Value = ((bool)TheObject).ToString(CultureInfo.InvariantCulture).ToLowerInvariant();
     }
     else if (TheObject is byte)
     {
         Value = (byte)TheObject + " (0x" + GroupDigits(((byte)TheObject).ToString("x2")) + ")";
     }
     else if (TheObject is sbyte)
     {
         Value = (sbyte)TheObject + " (0x" + GroupDigits(((sbyte)TheObject).ToString("x2")) + ")";
     }
     else if (TheObject is ushort)
     {
         Value = (ushort)TheObject + " (0x" + GroupDigits(((ushort)TheObject).ToString("x4")) + ")";
     }
     else if (TheObject is short)
     {
         Value = (short)TheObject + " (0x" + GroupDigits(((short)TheObject).ToString("x4")) + ")";
     }
     else if (TheObject is uint)
     {
         Value = (uint)TheObject + " (0x" + GroupDigits(((uint)TheObject).ToString("x8")) + ")";
     }
     else if (TheObject is int)
     {
         Value = (int)TheObject + " (0x" + GroupDigits(((int)TheObject).ToString("x8")) + ")";
     }
     else if (TheObject is ulong)
     {
         Value = (ulong)TheObject + " (0x" + GroupDigits(((ulong)TheObject).ToString("x16")) + ")";
     }
     else if (TheObject is long)
     {
         Value = (long)TheObject + " (0x" + GroupDigits(((long)TheObject).ToString("x16")) + ")";
     }
     else if (TheObject is Exception)
     {
         Value           = ((Exception)TheObject).Message;
         canLoadChildren = true;
     }
     else if (canLoadChildren && IsEnumerable(TheObject))
     {
         int count = ((IEnumerable)TheObject).OfType <object>().Count();
         if (count == 0)
         {
             Value = "(empty)";
         }
         else if (count == 1)
         {
             Value = "(1 item)";
         }
         else
         {
             Value = "(" + count + " items)";
         }
         ValueColor = Brushes.Gray;
         if (count == 0)
         {
             canLoadChildren = false;
         }
     }
     else
     {
         Value = Convert.ToString(TheObject, CultureInfo.InvariantCulture);
         if (Value == TheObject.GetType().FullName)
         {
             if (TheObject.GetType() == typeof(Mono.Cecil.CustomAttribute))
             {
                 Value      = (TheObject.GetType().GetProperty("AttributeType")?.GetValue(TheObject) as Mono.Cecil.TypeReference).Name;
                 ValueColor = Brushes.MediumBlue;
             }
             else if (TheObject.GetType() == typeof(Mono.Cecil.CustomAttributeArgument))
             {
                 Value = "(" + (TheObject.GetType().GetProperty("Type")?.GetValue(TheObject) as Mono.Cecil.TypeReference).Name + ") " +
                         Convert.ToString(TheObject.GetType().GetProperty("Value")?.GetValue(TheObject), CultureInfo.InvariantCulture);
                 ValueColor = Brushes.MediumBlue;
             }
         }
     }
 }