Ejemplo n.º 1
0
        private void AddIncludeType(Type type)
        {
            var attr = type.GetCustomAttribute <SirenClassAttribute>();

            if (attr == null)
            {
                return;
            }

            if (!IncludeTypes.Contains(type))
            {
                IncludeTypes.Add(type);
            }
        }
Ejemplo n.º 2
0
        public IncludedTypesDiscovery GetIncludedTypesDiscovery()
        {
            if (string.IsNullOrEmpty(IncludeTypes))
            {
                return(IncludedTypesDiscovery.None);
            }

            switch (IncludeTypes.ToLowerInvariant())
            {
            case "none":
                return(IncludedTypesDiscovery.None);

            case "knowntypeattribute":
                return(IncludedTypesDiscovery.UseKnownTypeAttribute);

            default:
                throw new NotSupportedException($"Specified included types discovery option is not supported: {IncludeTypes}");
            }
        }
    static public IQueryable <StaffBroker.User> GetStaffIncl(int PortalId = 0, params string[] IncludeTypes)
    {
        StaffBrokerDataContext d = new StaffBrokerDataContext();
        var q = from c in d.Users where c.AP_StaffBroker_Staffs.Active && c.AP_StaffBroker_Staffs.PortalId == PortalId && (IncludeTypes.Contains(c.AP_StaffBroker_Staffs.AP_StaffBroker_StaffType.Name)) select c;

        q = q.Union(from c in d.Users join b in d.AP_StaffBroker_Staffs on c.UserID equals b.UserId2 where b.Active && b.PortalId == PortalId && (IncludeTypes.Contains(b.AP_StaffBroker_StaffType.Name)) select c);
        return(q.OrderBy(c => c.LastName).ThenBy(c => c.FirstName));
    }
Ejemplo n.º 4
0
        public bool Initialzie()
        {
            //get template
            Template = SirenFactory.Create(Attribute.Template) as ISirenTemplate;
            if (Template == null)
            {
                return(false);
            }

            if (Type.IsEnum)
            {
                return(true);
            }

            //get methods
            SerializeMethodInfo   = Type.GetMethod("Serialize", BindingFlags.Public | BindingFlags.Instance);
            DeserializeMethodInfo = Type.GetMethod("Deserialize", BindingFlags.Public | BindingFlags.Instance);
            RegisterMethodInfo    = Type.GetMethod("Register", BindingFlags.Public | BindingFlags.Instance | BindingFlags.Static);
            if (RegisterMethodInfo != null && !Type.ContainsGenericParameters)
            {
                RegisterMethodInfo.Invoke(null, null);
            }


            //get properties
            uint   index      = 0;
            ushort id         = GetBasePropertyCount();
            var    properties = Type.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.Instance);

            foreach (var propertyInfo in properties)
            {
                SirenPropertyAttribute propertyAttribute = propertyInfo.GetCustomAttribute <SirenPropertyAttribute>();
                if (propertyAttribute != null)
                {
                    SirenProperty property = new SirenProperty(this, propertyInfo, propertyAttribute, index++, id++);
                    Properties.Add(property);
                    PropertyIdDict.Add(property.Id, property);
                    PropertyNameDict.Add(property.Name, property);
                }
            }

            if (Properties.Count == 0)
            {
                if (Type.BaseType == typeof(object) || Type.BaseType.IsValueType)
                {
                    return(false);
                }
            }


            //get include types
            foreach (var property in Properties)
            {
                var type = property.Type;
                if (type.IsGenericType)
                {
                    if (type.Name.StartsWith("List"))
                    {
                        var valueType = type.GenericTypeArguments[0];
                        AddIncludeType(valueType);
                    }
                    else if (type.Name.StartsWith("Dictionary"))
                    {
                        var keyType   = type.GenericTypeArguments[0];
                        var valueType = type.GenericTypeArguments[1];
                        AddIncludeType(keyType);
                        AddIncludeType(valueType);
                    }
                    else
                    {
                        AddIncludeType(type);
                    }
                }
                else
                {
                    AddIncludeType(type);
                }
            }

            if (Type.BaseType != typeof(object) && !Type.BaseType.IsValueType)
            {
                //has base type
                if (!IncludeTypes.Contains(Type.BaseType))
                {
                    IncludeTypes.Add(Type.BaseType);
                }

                BaseSirenClass = SirenFactory.FindClass(Type.BaseType);
                if (BaseSirenClass != null)
                {
                    //add base properties
                    foreach (var sirenProperty in BaseSirenClass.PropertyIdDict)
                    {
                        PropertyIdDict.Add(sirenProperty.Key, sirenProperty.Value);
                    }

                    foreach (var sirenProperty in BaseSirenClass.PropertyNameDict)
                    {
                        PropertyNameDict.Add(sirenProperty.Key, sirenProperty.Value);
                    }
                }
            }


            return(true);
        }