Example #1
0
 static string GetCaption(ITypeWrapper typeWrapper) {
     var modelApplicationBase = ((ModelApplicationBase)CaptionHelper.ApplicationModel);
     var currentAspect = modelApplicationBase.CurrentAspect;
     modelApplicationBase.SetCurrentAspect("");
     var caption = typeWrapper.Caption;
     modelApplicationBase.SetCurrentAspect(currentAspect);
     return caption;
 }
Example #2
0
        static string GetCaption(ITypeWrapper typeWrapper)
        {
            var modelApplicationBase = ((ModelApplicationBase)CaptionHelper.ApplicationModel);
            var currentAspect        = modelApplicationBase.CurrentAspect;

            modelApplicationBase.SetCurrentAspect("");
            var caption = typeWrapper.Caption;

            modelApplicationBase.SetCurrentAspect(currentAspect);
            return(caption);
        }
Example #3
0
        public EnumTypeData(ITypeWrapper typeToAnalyze)
        {
            AttributeData = new List<IAttributeData>();
            MethodData = new List<IMethodData>();
            FieldData = new List<IFieldData>();

            if (!typeToAnalyze.IsEnum)
            {
                throw new NtegrityException("Type: " + typeToAnalyze.AssemblyQualifiedName + " is not an Enum.");
            }

            Name = typeToAnalyze.FullName;

            Type = TypeEnum.Enum;

            var foundAccessLevel = false;
            if (typeToAnalyze.IsNestedPrivate)
            {
                AccessLevel = AccessLevelEnum.Private;
                foundAccessLevel = true;
            }
            if (!typeToAnalyze.IsVisible && typeToAnalyze.IsNotPublic
                || typeToAnalyze.IsNestedAssembly)
            {
                AccessLevel = AccessLevelEnum.Internal;
                foundAccessLevel = true;
            }
            if (typeToAnalyze.IsPublic || typeToAnalyze.IsNestedPublic)
            {
                AccessLevel = AccessLevelEnum.Public;
                foundAccessLevel = true;
            }
            if (typeToAnalyze.IsNestedFamily)
            {
                AccessLevel = AccessLevelEnum.Protected;
                foundAccessLevel = true;
            }
            if (!foundAccessLevel)
            {
                throw new NtegrityException("Unable to determine access level for type: " + typeToAnalyze.AssemblyQualifiedName);
            }

            CollectAttributeData(typeToAnalyze);
            AttributeData = AttributeData.OrderBy(x => x.Name).ToList();

            CollectMethodData(typeToAnalyze);
            MethodData = MethodData.OrderBy(x => x.MethodSignature).ToList();

            CollectFieldData(typeToAnalyze);
            FieldData = FieldData.OrderBy(x => x.FieldSignature).ToList();

            ImplementsInterfaces = typeToAnalyze.GetInterfaces().Select(x => x.FullName).ToList();
        }
Example #4
0
        public static DevExpress.DashboardCommon.Dashboard CreateDashBoard(this IDashboardDefinition template, IObjectSpace objectSpace, bool filter)
        {
            var dashboard = new DevExpress.DashboardCommon.Dashboard();

            try {
                LoadFromXml(template.Xml, dashboard);

                foreach (ITypeWrapper typeWrapper in template.DashboardTypes)
                {
                    ITypeWrapper wrapper = typeWrapper;
                    if (dashboard.DataSources.Contains(ds => ds.Name.Equals(wrapper.Caption)))
                    {
                        Type dashBoardObjectType = DashBoardObjectType(template, dashboard, typeWrapper);
                        if (dashBoardObjectType != null)
                        {
                            ITypeWrapper wrapper1   = typeWrapper;
                            var          dataSource = dashboard.DataSources.First(ds => ds.Name.Equals(wrapper1.Caption));
                            dataSource.Data = GetObjects(objectSpace, dashBoardObjectType);
                        }
                    }
                    else if (!dashboard.DataSources.Contains(ds => ds.Name.Equals(wrapper.Caption)))
                    {
                        dashboard.DataSources.Add(new DashboardObjectDataSource(typeWrapper.Caption, GetObjects(objectSpace, typeWrapper.Type)));
                    }
                }
                if (filter)
                {
                    Filter(template, dashboard);
                }
            }
            catch (Exception e) {
                dashboard.Dispose();
                Tracing.Tracer.LogError(e);
            }
            return(dashboard);
        }
        private TypeEnum GetTypeEnumValueForType(ITypeWrapper typeToAnalyze)
        {
            if (typeToAnalyze.IsClass)
            {
                return TypeEnum.Class;
            }
            if (typeToAnalyze.IsInterface)
            {
                return TypeEnum.Interface;
            }

            // Structs are value types, but not enums. Enums are both.
            if (typeToAnalyze.IsEnum && typeToAnalyze.IsValueType)
            {
                return TypeEnum.Enum;
            }
            if (typeToAnalyze.IsValueType)
            {
                return TypeEnum.Struct;
            }

            throw new NtegrityException("Unable to determine data type for type: " + typeToAnalyze.AssemblyQualifiedName);
        }
Example #6
0
        /// <summary>
        /// Reads the primitive value.
        /// </summary>
        /// <param name="instType">Type of the inst.</param>
        /// <param name="reader">The reader.</param>
        /// <param name="fallbackValue">The fallback value.</param>
        /// <param name="typeWrapper">The type wrapper.</param>
        /// <returns></returns>
        /// <exception cref="JsonException"></exception>
        private object ReadPrimitiveValue(Type instType, JsonReader reader, object fallbackValue, ITypeWrapper typeWrapper)
        {
            var jsonType = reader.Value.GetType();

            if (typeWrapper.IsAssignableFrom(jsonType))
            {
                return(reader.Value);
            }

            // If there's an importer that fits, use it
            object value;

            if (GetValueFromConverter(reader.Value, jsonType, instType, out value))
            {
                return(value);
            }

            // Maybe it's an enum
            if (instType.GetTypeWrapper().IsEnum)
            {
                return(Enum.ToObject(instType, reader.Value));
            }

            // Try using an implicit conversion operator
            var convOp = GetConvOp(instType, jsonType);

            if (convOp != null)
            {
                return(convOp.Invoke(null, new[] { reader.Value }));
            }

            if (fallbackValue != null)
            {
                return(fallbackValue);
            }

            // No luck
            Error("Can't assign value '{0}' (type {1}) to type {2}",
                  reader.Value, jsonType, instType);
            return(value);
        }
Example #7
0
        private void CollectPropertyData(ITypeWrapper typeToAnalyze)
        {
            var properties = typeToAnalyze.GetProperties(
                BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);

            foreach (var property in properties)
            {
                PropertyData.Add(new PropertyData(property));
            }
        }
Example #8
0
        public InterfaceTypeData(ITypeWrapper typeToAnalyze)
        {
            Name = typeToAnalyze.FullName;

            if (!typeToAnalyze.IsInterface)
            {
                throw new NtegrityException("non-interface type passed to InterfaceTypeData's constructor!");
            }
            Type = TypeEnum.Interface;

            var foundAccessLevel = false;
            if (typeToAnalyze.IsNestedPrivate)
            {
                AccessLevel = AccessLevelEnum.Private;
                foundAccessLevel = true;
            }
            if (!typeToAnalyze.IsVisible && typeToAnalyze.IsNotPublic
                || typeToAnalyze.IsNestedAssembly)
            {
                AccessLevel = AccessLevelEnum.Internal;
                foundAccessLevel = true;
            }
            if (typeToAnalyze.IsPublic || typeToAnalyze.IsNestedPublic)
            {
                AccessLevel = AccessLevelEnum.Public;
                foundAccessLevel = true;
            }
            if (typeToAnalyze.IsNestedFamily)
            {
                AccessLevel = AccessLevelEnum.Protected;
                foundAccessLevel = true;
            }
            if (!foundAccessLevel)
            {
                throw new NtegrityException("Unable to determine access level for type: " + typeToAnalyze.AssemblyQualifiedName);
            }

            IsSealed = typeToAnalyze.IsSealed;
            IsAbstract = typeToAnalyze.IsAbstract;
            // static types are both sealed and abstract. They can neither be inherited from nor instantiated.
            IsStatic = IsSealed && IsAbstract;

            CollectAttributeData(typeToAnalyze);
            AttributeData = AttributeData.OrderBy(x => x.Name).ToList();

            CollectConstructorData(typeToAnalyze);
            ConstructorData = ConstructorData.OrderBy(x => x.ConstructorSignature).ToList();

            CollectMethodData(typeToAnalyze);
            MethodData = MethodData.OrderBy(x => x.MethodSignature).ToList();

            CollectPropertyData(typeToAnalyze);
            PropertyData = PropertyData.OrderBy(x => x.PropertySignature).ToList();

            CollectFieldData(typeToAnalyze);
            FieldData = FieldData.OrderBy(x => x.FieldSignature).ToList();

            if (typeToAnalyze.BaseType != null
                && typeToAnalyze.BaseType.FullName != "System.Object"
                && typeToAnalyze.BaseType.FullName != "System.ValueType"
                && typeToAnalyze.BaseType.FullName != "System.Enum")
            {
                InheritsFrom = typeToAnalyze.BaseType.FullName;
            }

            ImplementsInterfaces = typeToAnalyze.GetInterfaces().Select(x => x.FullName).ToList();
        }
Example #9
0
        private void CollectMethodData(ITypeWrapper typeToAnalyze)
        {
            var methods = typeToAnalyze.GetMethods();

            foreach (var method in methods)
            {
                if (method.IsSpecialName ||
                    method.GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Any())
                {
                    continue;
                }
                MethodData.Add(new MethodData(method));
            }
        }
Example #10
0
        private void CollectFieldData(ITypeWrapper typeToAnalyze)
        {
            var fields = typeToAnalyze.GetFields();

            foreach (var field in fields)
            {
                if (field.IsSpecialName ||
                    field.GetCustomAttributes(typeof(CompilerGeneratedAttribute), true).Any())
                {
                    continue;
                }
                FieldData.Add(new FieldData(field));
            }
        }
Example #11
0
        private void CollectConstructorData(ITypeWrapper typeToAnalyze)
        {
            var constructors = typeToAnalyze.GetConstructors(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);

            foreach (var constructor in constructors)
            {
                ConstructorData.Add(new ConstructorData(constructor));
            }
        }
Example #12
0
        private void CollectAttributeData(ITypeWrapper typeToAnalyze)
        {
            var attributes = typeToAnalyze.GetCustomAttributes(true);

            foreach (var attribute in attributes)
            {
                var wrappedAttribute = new AttributeWrapper((Attribute) attribute);
                AttributeData.Add(new AttributeData(wrappedAttribute));
            }
        }
Example #13
0
 static Type DashBoardObjectType(IDashboardDefinition template, DevExpress.DashboardCommon.Dashboard dashboard, ITypeWrapper typeWrapper)
 {
     var wrapper = template.DashboardTypes.FirstOrDefault(type => type.Caption.Equals(dashboard.DataSources.First(ds => ds.Name.Equals(typeWrapper.Caption)).Name));
     return wrapper != null ? wrapper.Type : null;
 }
Example #14
0
        static Type DashBoardObjectType(IDashboardDefinition template, DevExpress.DashboardCommon.Dashboard dashboard, ITypeWrapper typeWrapper)
        {
            var wrapper = template.DashboardTypes.FirstOrDefault(type => type.Caption.Equals(dashboard.DataSources.First(ds => ds.Name.Equals(typeWrapper.Caption)).Name));

            return(wrapper != null ? wrapper.Type : null);
        }