public static ProductException Create(Application app, int code, bool error, Exception innerException, Mono.Cecil.TypeReference location, string message, params object [] args)
        {
            var e = new ProductException(code, error, innerException, message, args);

            if (location != null)
            {
                var td = location.Resolve();

                if (td.HasMethods)
                {
                    foreach (var method in td.Methods)
                    {
                        if (!method.IsConstructor)
                        {
                            continue;
                        }
                        SetLocation(app, e, method);
                        if (e.FileName != null)
                        {
                            break;
                        }
                    }
                }
            }
            return(e);
        }
        static internal TypeInformation ParseVariantTypeFields(Mono.Cecil.TypeDefinition variantType, Mono.Cecil.TypeReference typeReference)
        {
            var type = typeReference.Resolve();

            var root = new TypeInformation(type);

            if (!variantType.HasFields)
            {
                return(root);
            }

            foreach (var field in variantType.Fields)
            {
                if (!field.IsPublic || field.IsStatic)
                {
                    continue;
                }

                if (type.Fields.FirstOrDefault(f => f.Name == field.Name) == null)
                {
                    UnityEngine.Debug.LogError($"Variant {variantType.Name}. field {field.Name} not present in original type {type.Name}");
                    continue;
                }

                //Avoid use ghost fields modifiers for the variant type. passing null prevent that
                var ghostField = CecilExtensions.GetGhostFieldAttribute(null, field);
                if (ghostField != null && ghostField.SendData)
                {
                    root.Add(ParseTypeField(field, field.FieldType, ghostField, TypeAttribute.Empty(), root.AttributeMask));
                }
            }
            foreach (var prop in type.Properties)
            {
                if (prop.GetMethod == null || !prop.GetMethod.IsPublic || prop.GetMethod.IsStatic)
                {
                    continue;
                }
                if (prop.SetMethod == null || !prop.SetMethod.IsPublic || prop.SetMethod.IsStatic)
                {
                    continue;
                }

                if (type.Properties.FirstOrDefault(f => f.Name == prop.Name) == null)
                {
                    UnityEngine.Debug.LogError($"Variant {variantType.Name}. field {prop.Name} not present in original type {type.Name}");
                    continue;
                }

                var ghostField = CecilExtensions.GetGhostFieldAttribute(type, prop);
                if (ghostField != null && ghostField.SendData)
                {
                    root.Add(ParseTypeField(prop, prop.PropertyType, ghostField, TypeAttribute.Empty(), root.AttributeMask));
                }
            }
            return(root);
        }
Exemplo n.º 3
0
        public static bool IsICommandData(this Mono.Cecil.TypeReference typedReference)
        {
            var resolvedType = typedReference.Resolve();

            if (resolvedType == null)
            {
                return(false);
            }
            return(resolvedType.Interfaces.Any(i => i.InterfaceType.Name == typeof(ICommandData).Name &&
                                               i.InterfaceType.Namespace == typeof(ICommandData).Namespace));
        }
Exemplo n.º 4
0
        public static bool IsGhostComponent(this Mono.Cecil.TypeReference typeReference)
        {
            var resolvedType = typeReference.Resolve();

            if (resolvedType == null)
            {
                return(false);
            }

            return(resolvedType.CustomAttributes.Any(a =>
                                                     a.AttributeType.FullName == typeof(GhostComponentAttribute).FullName));
        }
Exemplo n.º 5
0
        public TypeDescription(Mono.Cecil.TypeReference typeReference, TypeAttribute attribute)
        {
            TypeFullName = typeReference.FullName.Replace("/", "+");

            if (!typeReference.IsPrimitive && typeReference.Resolve().IsEnum)
            {
                Key = typeof(Enum).FullName;
            }
            else
            {
                Key = TypeFullName;
            }
            Attribute = attribute;
        }
Exemplo n.º 6
0
        public static bool IsSimilarType(Type thisType, Mono.Cecil.TypeReference type)
        {
            Mono.Cecil.TypeDefinition td = type.Resolve();

            // Ignore any 'ref' types
            if (thisType.IsByRef)
            {
                thisType = thisType.GetElementType();
            }
            if (type.IsByReference)
            {
                type = type.GetElementType();
            }

            // Handle array types
            if (thisType.IsArray && type.IsArray)
            {
                Mono.Cecil.ArrayType at = type as Mono.Cecil.ArrayType;
                // Dimensions must be the same.
                if (thisType.GetArrayRank() != at.Rank)
                {
                    return(false);
                }
                // Base type of array must be the same.
                return(IsSimilarType(thisType.GetElementType(), type.GetElementType()));
            }
            if (thisType.IsArray && !type.IsArray)
            {
                return(false);
            }
            if (type.IsArray && !thisType.IsArray)
            {
                return(false);
            }

            // If the types are identical, or they're both generic parameters
            // or the special 'T' type, treat as a match
            // Match also if thisType is generic and type can be unified with thisType.
            if (thisType.Name == type.Name || // identical types.
                ((thisType.IsGenericParameter || thisType == typeof(T)) && (type.IsGenericParameter || type.Name.Equals("T"))) || // using "T" as matching generic type.
                IsUnifiableMono(thisType, type))
            {
                return(true);
            }

            return(false);
        }
        static private TypeInformation ParseTypeField(Mono.Cecil.IMemberDefinition fieldInfo, Mono.Cecil.TypeReference fieldType,
                                                      GhostFieldAttribute ghostField, TypeAttribute inheritedAttribute, TypeAttribute.AttributeFlags inheriteAttributedMask, string parent = "")
        {
            var information = new TypeInformation(fieldInfo, fieldType, ghostField, inheritedAttribute, inheriteAttributedMask, parent);

            //blittable also contains bool, but does not contains enums
            if (fieldType.IsBlittable())
            {
                return(information);
            }

            var fieldDef = fieldType.Resolve();

            if (fieldDef.IsEnum)
            {
                return(information);
            }

            if (!fieldDef.IsStruct())
            {
                return(default);
Exemplo n.º 8
0
 public static Type ConvertToSystemReflectionType(Mono.Cecil.TypeReference tr)
 {
     Mono.Cecil.TypeDefinition td = tr.Resolve();
     return(ConvertToSystemReflectionType(td));
 }