Example #1
0
        public override PropertyDescriptorCollection GetProperties(ITypeDescriptorContext context, object value, Attribute[] attributes)
        {
            Defaultable defaultable = (Defaultable)value;

            var descriptor = TypeDescriptor.GetProperties(defaultable.GetType(), attributes);

            List <PropertyDescriptor> propertiesToRemove = new List <PropertyDescriptor>();

            foreach (PropertyDescriptor prop in descriptor)
            {
                if (prop.Name == "Value" && defaultable.IsDefault())
                {
                    propertiesToRemove.Add(prop);
                }
            }


            PropertyDescriptorCollection result = descriptor;

            if (propertiesToRemove.Count > 0)
            {
                PropertyDescriptor[] propertyDescriptors = descriptor.OfType <PropertyDescriptor>().ToArray();
                result = new PropertyDescriptorCollection(propertyDescriptors, false);

                foreach (PropertyDescriptor prop in descriptor)
                {
                    if (prop.Name == "Value" && defaultable.IsDefault())
                    {
                        try
                        {
                            result.Remove(prop);
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine(e);
                        }
                    }
                }
            }

            result.Sort(new[] { "ValueType", "Value" });

            return(result);
        }
Example #2
0
        private string GetPairFromToValue(bool from)
        {
            bool isSource     = IsSourceWithinAssociation();
            var  associations = this.PersistentTypeHasAssociations;

            if (associations == null)
            {
                return(string.Empty);
            }

            var endA = isSource ? associations.End2 : associations.End1;
            var endB = isSource ? associations.End1 : associations.End2;
            Defaultable <string> defPairTo = from ? endA.PairTo : endB.PairTo;

            return(defPairTo.IsDefault() ? string.Empty : defPairTo.Value);
        }
Example #3
0
    public string EscapeType(IPropertyBase property)
    {
        string result = null;

        if (property is IScalarProperty)
        {
            IScalarProperty scalarProperty = (IScalarProperty)property;
            Type            clrType        = scalarProperty.Type.TryGetClrType(null);
            string          typeName;

            if (clrType != null)
            {
                typeName = Escape(clrType);
                Defaultable <bool> nullable = scalarProperty.FieldAttribute.Nullable;
                bool isNullable             = !nullable.IsDefault() && nullable.Value;
                if (clrType.IsValueType && isNullable)
                {
                    typeName = String.Format(CultureInfo.InvariantCulture, SYSTEM_NULLABLE_FORMAT, typeName);
                }
            }
            else
            {
                typeName = scalarProperty.Type.FullName;
            }

            result = typeName;
        }
        else if (property is INavigationProperty)
        {
            INavigationProperty navigationProperty = (INavigationProperty)property;
            result = navigationProperty.GetPropertyType(_code, EscapeNameWithNamespace,
                                                        delegate(OrmType type, string s)
            {
                return(BuildXtensiveType(type, s));
            });
        }
        else if (property is IStructureProperty)
        {
            IStructureProperty structureProperty = (IStructureProperty)property;
            result = EscapeNameWithNamespace(structureProperty.TypeOf, property.Owner);
        }

        return(result);
    }
Example #4
0
        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            object propertyValue = context.PropertyDescriptor.GetValue(context.Instance);
            bool   isExclusive   = propertyValue == null;

            if (!isExclusive)
            {
                Defaultable defaultable = propertyValue as Defaultable;
                if (defaultable != null)
                {
                    object exValue = defaultable.InternalGetValue();
                    isExclusive = defaultable.IsDefault() || exValue == null;

                    Type typeOfValue = defaultable.GetTypeOfValue();
                    if (!isExclusive)
                    {
                        isExclusive = (typeOfValue == typeof(bool) || typeOfValue.IsEnum);
                    }
                }
            }

            return(isExclusive);
        }
Example #5
0
    private string[] CreateTypeAttributes(ITypeAttributesBuilder attributesBuilder, IEnumerable <IOrmAttribute> attributes,
                                          bool allowInPoco = false)
    {
        if (this.ActiveDTOStage && !allowInPoco)
        {
            return(new string[0]);
        }

        List <string> result = new List <string>();

        if (attributes != null)
        {
            foreach (var attribute in attributes)
            {
                foreach (var attributeGroup in attributesBuilder.GetAttributeGroups(attribute))
                {
                    var           attributeGroupItems = attributesBuilder.GetAttributeGroupItems(attribute, attributeGroup);
                    StringBuilder attr = new StringBuilder(attributeGroup.FormatFullName());
                    if (attributeGroupItems.Count > 0)
                    {
                        int beforeItemsLen = attr.Length;

                        bool handledByCustom = attributesBuilder.BuildCustomFormatComplete(attributeGroup,
                                                                                           attributeGroupItems, ref attr);

                        if (!handledByCustom)
                        {
                            foreach (KeyValuePair <string, Defaultable> attributeGroupItem in attributesBuilder.SortAttributeGroupItems(
                                         attributeGroup, attributeGroupItems))
                            {
                                string      attrItemName  = attributeGroupItem.Key;
                                Defaultable attrItemValue = attributeGroupItem.Value;
                                if (!attrItemValue.IsDefault())
                                {
                                    object value        = attrItemValue.GetValue();
                                    string valueLiteral = CreateLiteral(value);

                                    bool buildedCustomFormat = attributesBuilder.BuildCustomFormat(attributeGroup,
                                                                                                   attrItemName, valueLiteral, value, ref attr);

                                    if (!buildedCustomFormat)
                                    {
                                        attr.AppendFormat("{0}={1},", attrItemName, valueLiteral);
                                    }
                                }
                            }
                        }

                        if (attr[attr.Length - 1] == ',')
                        {
                            attr = attr.Remove(attr.Length - 1, 1);
                        }

                        if (attr.Length > beforeItemsLen)
                        {
                            attr.Insert(beforeItemsLen, "(");
                            attr.Append(")");
                        }
                    }

                    result.Add(attr.ToString());
                }
            }
        }

        return(result.ToArray());
    }