コード例 #1
0
        /// <summary>
        /// this will add the definition to the schema's attribute definition collection and attach it to the 'general group' if it doesn't exist
        /// otherwise will return false.
        /// </summary>
        /// <param name="schema"></param>
        /// <param name="def"></param>
        /// <returns>Returns true if the property was added otherwise returns false</returns>
        public static bool TryAddAttributeDefinition(this EntitySchema schema, AttributeDefinition def)
        {
            if (def.AttributeGroup == null)
            {
                //check if we have a general group
                var generalGroup = schema.AttributeGroups.SingleOrDefault(x => x.Alias == FixedGroupDefinitions.GeneralGroupAlias);

                //if a general group already exists, use it. If it doesn't exist it will automatically get created
                if (generalGroup != null)
                {
                    def.AttributeGroup = generalGroup;
                }
            }

            return(schema.AttributeDefinitions.TryAdd(def));

            //if (schema.AttributeDefinitions.TryAdd(def))
            //{
            //    //check if we have a general group
            //    var generalGroup =
            //        schema.AttributeGroups.Where(x => x.Alias == FixedGroupDefinitions.GeneralGroupAlias)
            //            .SingleOrDefault();
            //    //if a general group already exists, use it. If it doesn't exist it will automatically get created
            //    if (generalGroup != null)
            //        def.AttributeGroup = generalGroup;
            //    //schema.AttributeDefinitions.Add(def);
            //}
            //return false;
        }
コード例 #2
0
        /// <summary>
        /// Creates an <see cref="AttributeDefinition"/> with a given <see cref="AttributeType"/> and references it to a given <see cref="AttributeGroup"/>.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="alias">The alias.</param>
        /// <param name="name">The name.</param>
        /// <param name="attributeDefinition">The attribute type definition.</param>
        /// <param name="serializationDefinition">The serialization definition.</param>
        /// <param name="attributeGroup">The attribute group definition.</param>
        /// <returns></returns>
        public static T CreateAttributeIn <T>(string alias, string name, AttributeDefinition attributeDefinition, IAttributeSerializationDefinition serializationDefinition,
                                              AttributeGroup attributeGroup)
            where T : AttributeDefinition, new()
        {
            var entity = Create <T>(alias, name);

            entity.AttributeType = attributeDefinition.AttributeType;
            entity.AttributeType.SerializationType = serializationDefinition;
            attributeDefinition.AttributeGroup     = attributeGroup;
            return(entity);
        }