예제 #1
0
        public static void Assocication(this PropertyDefinition self, CollectionProperty p1)
        {
            var name = p1.DisplayName + "-" + p1.RelationProperty.DisplayName;

            if (p1.RelationProperty is Property)
            {
                var p = p1.RelationProperty as Property;
                if (p.Owner != null && p.Owner.IsRuntimeDefine)
                {
                    var pt = p.Owner;
                    if (pt != null)
                    {
                        var relationType = pt.GetTypeDefintion();
                        if (relationType == null)
                        {
                            throw new Exception("错误,没有找到类型定义!");
                        }
                        var relationPropertyDefine = relationType.Properties.Single(x => x.Name == p.称);
                        relationPropertyDefine.Assocication(name);
                    }
                    else
                    {
                        throw new Exception("关联属性只能建立在用户定义的类型上面.系统内置的类型是无法更改的!如果需要建立已有类型的关联,可以继承该类型,并增加属性建立关联!");
                    }
                }
                else
                {
                    throw new Exception("关联属性只能建立在用户定义的类型上面!");
                }
            }
            self.Assocication(name);
        }
예제 #2
0
        /// <summary>
        /// Saves the data and clears the dirty flag.
        /// </summary>
        /// <returns>Returns true if the data is saved, false if not.</returns>
        public bool Apply()
        {
            if (this.analyzer != null)
            {
                List <string> values = new List <string>(this.prefixList.Items.Count);

                foreach (ListViewItem prefix in this.prefixList.Items)
                {
                    // Only save local tags.
                    if ((bool)prefix.Tag)
                    {
                        values.Add(prefix.Text);
                    }
                }

                CollectionProperty list = new CollectionProperty(this.analyzer, NamingRules.AllowedPrefixesProperty, values);

                this.tabControl.LocalSettings.SetAddInSetting(this.analyzer, list);
            }

            this.dirty = false;
            this.tabControl.DirtyChanged();

            return(true);
        }
예제 #3
0
        /// <summary>
        /// Add prefixes from the parent settings.
        /// </summary>
        private void AddParentPrefixes()
        {
            CollectionProperty parentPrefixesProperty = null;

            if (this.tabControl.ParentSettings != null)
            {
                parentPrefixesProperty = this.tabControl.ParentSettings.GetAddInSetting(this.analyzer, NamingRules.AllowedPrefixesProperty) as CollectionProperty;

                if (parentPrefixesProperty != null)
                {
                    if (parentPrefixesProperty.Values.Count > 0)
                    {
                        foreach (string value in parentPrefixesProperty)
                        {
                            if (!string.IsNullOrEmpty(value))
                            {
                                ListViewItem item = this.prefixList.Items.Add(value);
                                if (item != null)
                                {
                                    item.Tag = false;
                                }
                            }
                        }
                    }
                }
            }
        }
        public void Read_collections()
        {
            var model = new CollectionProperty
            {
                Flats = new object[]
                {
                    new Flat2 {
                        First = 1, Second = "First"
                    },
                    new CamelCase {
                        ThisShouldBeCamelCase = ""
                    }
                }
            };
            var result = Read(model);

            result.Should().HaveCount(2);

            result[0].Attributes.Should().HaveCount(1);
            result[0].Attributes.ElementAt(0).Should().BeAssignableTo <RequiredAttribute>();
            result[0].Value.Should().Be(1);
            result[0].Path.Should().BeEquivalentTo(new object[] { "flats", 0, "first" });

            result[1].Attributes.Should().HaveCount(1);
            result[1].Attributes.ElementAt(0).Should().BeAssignableTo <RequiredAttribute>();
            result[1].Value.Should().Be("");
            result[1].Path.Should().BeEquivalentTo(new object[] { "flats", 1, "thisShouldBeCamelCase" });
        }
        private void ApplyProperties(CollectionProperty property, GridPanel panelToAdd)
        {
            panelToAdd.Clear();

            var itemsCount = property.Items.Count;

            var panelRowCount = itemsCount / ItemsInRow();

            var additionalItems = itemsCount - panelRowCount * ItemsInRow();

            if (additionalItems > 0)
            {
                panelRowCount++;
            }


            _fullRowCount += panelRowCount;

            panelToAdd.SetGrid(panelRowCount, ItemsInRow());

            for (var i = 0; i < property.Items.Count; i++)
            {
                var rowIndex = i / ItemsInRow();
                var colIndex = i % ItemsInRow();

                //простите, люди, очень хочется спать
                var control      = (PropertiesControl)panelToAdd.Panels[rowIndex].GetCell(colIndex);
                var stubCriteria = new CriteriaStubLayout();
                stubCriteria.Dock    = DockStyle.Fill;
                stubCriteria.Caption = property.Items[i].Text;
                control.Control.Controls[0].Controls.Add(stubCriteria);
            }
            panelToAdd.Height = panelRowCount * 50;
            panelToAdd.AlignControls();
        }
예제 #6
0
        private object createObjectFromCollectionProperty(CollectionProperty property)
        {
            Type   type       = property.Type;
            object collection = Tools.CreateInstance(type);

            if (property.Reference != null)
            {
                // property has Reference, only objects referenced multiple times
                // have properties with references. Object must be cached to
                // resolve its references in the future.
                _objectCache.Add(property.Reference.Id, collection);
            }

            // fill the properties
            fillProperties(collection, property.Properties);

            // Fill the items but only if the "Add" method was found, which has only 1 parameter
            MethodInfo methodInfo = collection.GetType().GetMethod("Add");

            if (methodInfo != null)
            {
                ParameterInfo[] parameters = methodInfo.GetParameters();
                if (parameters.Length == 1)
                {
                    foreach (Property item in property.Items)
                    {
                        object value = CreateObject(item);
                        methodInfo.Invoke(collection, new[] { value });
                    }
                }
            }
            return(collection);
        }
예제 #7
0
        private object CreateObjectFromCollectionProperty(CollectionProperty property)
        {
            var type       = property.Type;
            var collection = Tools.CreateInstance(type);

            if (property.Reference != null)
            {
                _objectCache.Add(property.Reference.Id, collection);
            }

            // fill the properties
            FillProperties(collection, property.Properties);

            // Fill the items but only if the "Add" method was found, which has only 1 parameter
            var methodInfo = collection.GetType().GetTypeInfo().GetMethod("Add");
            var parameters = methodInfo?.GetParameters();

            if (parameters?.Length == 1)
            {
                foreach (var item in property.Items)
                {
                    var value = CreateObject(item);
                    methodInfo.Invoke(collection, new[] { value });
                }
            }
            return(collection);
        }
        public void Read_null_collections()
        {
            var model = new CollectionProperty {
                Flats = null
            };
            var result = Read(model);

            result.Should().HaveCount(0);
        }
예제 #9
0
        protected void traverseCollection(CollectionProperty col, TestElementTraverser traverser)
        {
            PropertyIterator iter = col.iterator();

            while (iter.hasNext())
            {
                TraverseProperty(traverser, iter.next());
            }
        }
예제 #10
0
 public ObjectInfo(IntPtr raw)
     : base(raw)
 {
     Interfaces = new CollectionProperty<InterfaceInfo>(this, g_object_info_get_n_interfaces, g_object_info_get_interface);
     Fields = new CollectionProperty<FieldInfo>(this, g_object_info_get_n_fields, g_object_info_get_field);
     Properties = new CollectionProperty<PropertyInfo>(this, g_object_info_get_n_properties, g_object_info_get_property);
     Methods = new CollectionProperty<FunctionInfo>(this, g_object_info_get_n_methods, g_object_info_get_method);
     Signals = new CollectionProperty<SignalInfo>(this, g_object_info_get_n_signals, g_object_info_get_signal);
     VFuncs = new CollectionProperty<VFuncInfo>(this, g_object_info_get_n_vfuncs, g_object_info_get_vfunc);
 }
예제 #11
0
        /// <summary>
        /// Indicates whether to skip analysis on the given document.
        /// </summary>
        /// <param name="sourceCode">
        /// The document.
        /// </param>
        /// <returns>
        /// Returns true to skip analysis on the document.
        /// </returns>
        public override bool SkipAnalysisForDocument(SourceCode sourceCode)
        {
            Param.RequireNotNull(sourceCode, "sourceCode");

            if (sourceCode == null || sourceCode.Name == null ||
                !this.FileTypes.Contains(Path.GetExtension(sourceCode.Name).Trim('.').ToUpperInvariant()))
            {
                return(true);
            }

            // Get the property indicating whether to analyze designer files.
            BooleanProperty analyzeDesignerFilesProperty = this.GetSetting(sourceCode.Settings, AnalyzeDesignerFilesProperty) as BooleanProperty;

            // Default the setting to true if it does not exist.
            bool analyzeDesignerFiles = true;

            if (analyzeDesignerFilesProperty != null)
            {
                analyzeDesignerFiles = analyzeDesignerFilesProperty.Value;
            }

            if (analyzeDesignerFiles || !sourceCode.Name.EndsWith(".Designer.cs", StringComparison.OrdinalIgnoreCase))
            {
                // Get the property indicating whether to analyze generated files.
                BooleanProperty analyzerGeneratedFilesProperty = this.GetSetting(sourceCode.Settings, AnalyzeGeneratedFilesProperty) as BooleanProperty;

                // Default the setting to false if it does not exist.
                bool analyzeGeneratedFiles = false;
                if (analyzerGeneratedFilesProperty != null)
                {
                    analyzeGeneratedFiles = analyzerGeneratedFilesProperty.Value;
                }

                if (analyzeGeneratedFiles)
                {
                    // This document should be analyzed.
                    return(false);
                }

                // Initialize to the default set of generated file filters.
                IEnumerable <string> filters = DefaultGeneratedFileFilters;

                // Get the file filter list for generated files.
                CollectionProperty generatedFileFilterSettings = this.GetSetting(sourceCode.Settings, GeneratedFileFiltersProperty) as CollectionProperty;

                if (generatedFileFilterSettings != null)
                {
                    filters = generatedFileFilterSettings.Values;
                }

                return(Utils.InputMatchesRegExPattern(sourceCode.Path, filters));
            }

            return(true);
        }
예제 #12
0
        private void parseCollectionProperty(CollectionProperty property)
        {
            // Element type
            property.ElementType = this._reader.ReadType();

            // Properties
            this.readProperties(property.Properties, property.Type);

            // Items
            this.readItems(property.Items, property.ElementType);
        }
예제 #13
0
        private void ParseCollectionItems(CollectionProperty property, InternalTypeInfo info, object value)
        {
            property.ElementType = info.ElementType;

            var collection = (IEnumerable)value;

            foreach (var item in collection)
            {
                var itemProperty = CreateProperty(null, item);

                property.Items.Add(itemProperty);
            }
        }
예제 #14
0
 public InstanceEventConsumer(BroadcasterInstanceRule last, CollectionProperty vis, ProductInstanceExpression comp)
 {
     //Discarded unreachable code: IL_0002, IL_0006
     //IL_0003: Incompatible stack heights: 0 vs 1
     //IL_0007: Incompatible stack heights: 0 vs 1
     SingletonReader.PushGlobal();
     base._002Ector();
     ContextClientBridge.RunClient(last, "reader");
     ContextClientBridge.RunClient(vis, "contract");
     m_CustomerProperty  = last;
     interpreterProperty = vis;
     watcherProperty     = comp;
 }
예제 #15
0
        private void parseCollectionItems(CollectionProperty property, TypeInfo info, object value)
        {
            property.ElementType = info.ElementType;

            var collection = (IEnumerable)value;

            foreach (object item in collection)
            {
                Property itemProperty = this.CreateProperty(null, item);

                property.Items.Add(itemProperty);
            }
        }
        public void Rebind(THost host, ICollection <TProperty> nullCollection, ICollection <TProperty> collection)
        {
            var lazyCollection = collection as LazyEntityCollection <TProperty>;

            if (lazyCollection != null)
            {
                lazyCollection.ItemAdded   += x => CollectionProperty.Add(x, _inverse, host);
                lazyCollection.ItemRemoved += x => CollectionProperty.Remove(x, _inverse, host);
            }

            foreach (var x in collection)
            {
                CollectionProperty.Add(x, _inverse, host);
            }
        }
예제 #17
0
        private bool FillCollectionProperty(CollectionProperty property, InternalTypeInfo info, object value)
        {
            if (property == null)
            {
                return(false);
            }

            // Parsing properties
            ParseProperties(property, info, value);

            // Parse Items
            ParseCollectionItems(property, info, value);

            return(true);
        }
예제 #18
0
        internal static ExpandNode Create(ExpandProperty property, string select, string filter, string orderby, XElement schema, ParameterCollection parameterCollection)
        {
            if (property is EntityProperty)
            {
                EntityProperty entityProperty = property as EntityProperty;
                return(new EntityExpandNode(property.Relationship, property.Name, entityProperty.Entity,
                                            select, filter, orderby, schema, parameterCollection));
            }
            else if (property is CollectionProperty)
            {
                CollectionProperty collectionProperty = property as CollectionProperty;
                return(new CollectionExpandNode(property.Relationship, property.Name, collectionProperty.Collection,
                                                select, filter, orderby, schema, parameterCollection));
            }

            throw new NotSupportedException(property.GetType().ToString()); // never
        }
예제 #19
0
        /// <summary>
        /// Initializes the page.
        /// </summary>
        /// <param name="propertyControl">
        /// The tab control object.
        /// </param>
        public void Initialize(PropertyControl propertyControl)
        {
            Param.AssertNotNull(propertyControl, "propertyControl");

            this.tabControl = propertyControl;

            if (this.analyzer != null)
            {
                // Get the list of allowed prefixes from the parent settings.
                this.AddParentPrefixes();

                // Get the list of allowed prefixes from the local settings.
                CollectionProperty localPrefixesProperty =
                    this.tabControl.LocalSettings.GetAddInSetting(this.analyzer, NamingRules.AllowedPrefixesProperty) as CollectionProperty;

                if (localPrefixesProperty != null && localPrefixesProperty.Values.Count > 0)
                {
                    foreach (string value in localPrefixesProperty)
                    {
                        if (!string.IsNullOrEmpty(value))
                        {
                            ListViewItem item = this.prefixList.Items.Add(value);
                            if (item != null)
                            {
                                item.Tag = true;
                                this.SetBoldState(item);
                            }
                        }
                    }
                }
            }

            // Select the first item in the list.
            if (this.prefixList.Items.Count > 0)
            {
                this.prefixList.Items[0].Selected = true;
            }

            this.EnableDisableRemoveButton();

            this.dirty = false;
            this.tabControl.DirtyChanged();
        }
예제 #20
0
        private bool fillCollectionProperty(CollectionProperty property, TypeInfo info, object value)
        {
            if (property == null)
            {
                return(false);
            }

            // Parsing properties
            parseProperties(property, info, value);

            // Parse Items

            if (!_propertyProvider.IgnoreCollectionItems(info))
            {
                parseCollectionItems(property, info, value);
            }

            return(true);
        }
예제 #21
0
        private void parseCollectionProperty(CollectionProperty property)
        {
            // ElementType
            property.ElementType = property.Type != null?TypeInfo.GetTypeInfo(property.Type).ElementType : null;

            foreach (string subElement in _reader.ReadSubElements())
            {
                if (subElement == SubElements.Properties)
                {
                    // Properties
                    readProperties(property.Properties, property.Type);
                    continue;
                }

                if (subElement == SubElements.Items)
                {
                    // Items
                    readItems(property.Items, property.ElementType);
                }
            }
        }
        private void OrderClass(RecordClassDispatcher first, ISerializable visitor, CollectionProperty dic, ProductInstanceExpression selection2, InitializerTest cust3, ProductInstanceExpression asset4)
        {
            //Discarded unreachable code: IL_0002
            //IL_0003: Incompatible stack heights: 0 vs 1
            if (!ConfigProperty._0002())
            {
                string asset5 = "Type '{0}' implements ISerializable but cannot be serialized using the ISerializable interface because the current application is not fully trusted and ISerializable can expose secure data." + Environment.NewLine + "To fix this error either change the environment to be fully trusted, change the application to not deserialize the type, add JsonObjectAttribute to the type or change the JsonSerializer setting ContractResolver to use a new DefaultContractResolver with IgnoreSerializableInterface set to true." + Environment.NewLine;
                asset5 = asset5.ListReader(CultureInfo.InvariantCulture, visitor.GetType());
                throw StrategyError.ValidateComposer(null, first._0001(), asset5, null);
            }
            ManageBroadcaster(first, dic, visitor);
            wrapperProperty.Add(visitor);
            SortBroadcaster(first, visitor, dic, selection2, cust3, asset4);
            SerializationInfo serializationInfo = new SerializationInfo(((ProcTest)dic)._0002(), new FormatterConverter());

            visitor.GetObjectData(serializationInfo, baseProperty.roleError);
            SerializationInfoEnumerator enumerator = serializationInfo.GetEnumerator();

            while (enumerator.MoveNext())
            {
                SerializationEntry current  = enumerator.Current;
                ProcTest           procTest = DeleteBroadcaster(current.Value);
                if (CountBroadcaster(current.Value, null, procTest, dic, selection2))
                {
                    first._0002(current.Name);
                    QueryBroadcaster(first, current.Value);
                }
                else if (CustomizeBroadcaster(first, current.Value, null, procTest, dic, selection2))
                {
                    first._0002(current.Name);
                    InvokeBroadcaster(first, current.Value, procTest, null, dic, selection2);
                }
            }
            first._0011();
            wrapperProperty.RemoveAt(wrapperProperty.Count - 1);
            InitBroadcaster(first, dic, visitor);
        }
예제 #23
0
        /// <summary>
        /// Gets the list of valid prefixes for the given project.
        /// </summary>
        /// <param name="settings">The settings for the document being parsed.</param>
        /// <returns>Returns the list of prefixes.</returns>
        private Dictionary <string, string> GetPrefixes(Settings settings)
        {
            Param.Ignore(settings);

            Dictionary <string, string> validPrefixes = new Dictionary <string, string>();

            if (settings != null)
            {
                // Get the allowed hungarian prefixes from the local settings file.
                CollectionProperty list = this.GetSetting(settings, NamingRules.AllowedPrefixesProperty) as CollectionProperty;
                if (list != null && list.Count > 0)
                {
                    foreach (string value in list)
                    {
                        if (!string.IsNullOrEmpty(value) && !validPrefixes.ContainsKey(value))
                        {
                            validPrefixes.Add(value, value);
                        }
                    }
                }
            }

            return(validPrefixes);
        }
예제 #24
0
        /// <summary>
        /// Merges two collection properties together.
        /// </summary>
        /// <param name="mergedPropertyCollection">
        /// The merged property collection.
        /// </param>
        /// <param name="originalProperty">
        /// The original property to merge.
        /// </param>
        /// <param name="overridingProperty">
        /// The overriding property to merge.
        /// </param>
        private static void MergeCollectionProperties(PropertyCollection mergedPropertyCollection, PropertyValue originalProperty, PropertyValue overridingProperty)
        {
            Param.AssertNotNull(mergedPropertyCollection, "mergedPropertyCollection");
            Param.AssertNotNull(originalProperty, "originalProperty");
            Param.AssertNotNull(overridingProperty, "overridingProperty");

            CollectionProperty originalCollectionProperty = (CollectionProperty)originalProperty;
            CollectionProperty overridingCollectionProperty = (CollectionProperty)overridingProperty;

            // Create a new merged collection property.
            CollectionProperty mergedCollectionProperty = new CollectionProperty((CollectionPropertyDescriptor)originalCollectionProperty.PropertyDescriptor);
            mergedPropertyCollection.Add(mergedCollectionProperty);

            // Add each of the strings from the overriding collection.
            foreach (string value in overridingCollectionProperty.Values)
            {
                mergedCollectionProperty.Add(value);
            }

            // If necessary, also add the strings from the original collection.
            if (originalCollectionProperty.Aggregate)
            {
                foreach (string value in originalCollectionProperty.Values)
                {
                    if (!mergedCollectionProperty.Contains(value))
                    {
                        mergedCollectionProperty.Add(value);
                    }
                }
            }
        }
예제 #25
0
        private object createObjectFromCollectionProperty(CollectionProperty property)
        {
            Type type = property.Type;
            object collection = Tools.CreateInstance(type);

            if (property.Reference != null)
            {
                // property has Reference, only objects referenced multiple times
                // have properties with references. Object must be cached to
                // resolve its references in the future.
                _objectCache.Add(property.Reference.Id, collection);
            }

            // fill the properties
            fillProperties(collection, property.Properties);

            // Fill the items but only if the "Add" method was found, which has only 1 parameter
            MethodInfo methodInfo = collection.GetType().GetMethod("Add");
            if (methodInfo != null)
            {
                ParameterInfo[] parameters = methodInfo.GetParameters();
                if (parameters.Length == 1)
                {
                    foreach (Property item in property.Items)
                    {
                        object value = CreateObject(item);
                        methodInfo.Invoke(collection, new[] {value});
                    }
                }
            }
            return collection;
        }
예제 #26
0
 public CollectionPropertyBuilder(CollectionProperty property)
 {
     this.Property = property;
 }
예제 #27
0
 set => SetValue(CollectionProperty, value);
예제 #28
0
        private void ParseCollectionItems(CollectionProperty property, TypeInfo info, object value)
        {
            property.ElementType = info.ElementType;

            var collection = (IEnumerable)value;
            foreach (var item in collection) {
                var itemProperty = CreateProperty(null, item);

                property.Items.Add(itemProperty);
            }
        }
예제 #29
0
        private object createObjectFromCollectionProperty(CollectionProperty property)
        {
            var type = property.Type;
            var collection = Tools.CreateInstance(type);

            // fill the properties
            fillProperties(collection, property.Properties);

            // Fill the items but only if the "Add" method was found, which has only 1 parameter
            var methodInfo = collection.GetType().GetMethod("Add");
            if (methodInfo != null)
            {
                var parameters = methodInfo.GetParameters();
                if (parameters.Length == 1)
                {
                    foreach (var item in property.Items)
                    {
                        var value = CreateObject(item);
                        methodInfo.Invoke(collection, new[] { value });
                    }
                }
            }
            return collection;
        }
        /// <summary>
        /// Saves the data and clears the dirty flag.
        /// </summary>
        /// <returns>Returns true if the data is saved, false if not.</returns>
        public bool Apply()
        {
            if (this.analyzer != null)
            {
                List<string> values = new List<string>(this.prefixList.Items.Count);

                foreach (ListViewItem prefix in this.prefixList.Items)
                {
                    // Only save local tags.
                    if ((bool)prefix.Tag)
                    {
                        values.Add(prefix.Text);
                    }
                }

                CollectionProperty list = new CollectionProperty(this.analyzer, NamingRules.AllowedPrefixesProperty, values);

                this.tabControl.LocalSettings.SetAddInSetting(this.analyzer, list);
            }

            this.dirty = false;
            this.tabControl.DirtyChanged();

            return true;
        }
예제 #31
0
파일: TypeInfo.cs 프로젝트: sciyoshi/netgir
 public TypeInfo(IntPtr raw)
     : base(raw)
 {
     ErrorDomains = new CollectionProperty<ErrorDomainInfo>(this, g_type_info_get_n_error_domains, g_type_info_get_error_domain);
 }
예제 #32
0
        private void ParseCollectionProperty(CollectionProperty property)
        {
            // ElementType
            property.ElementType = property.Type != null ? TypeInfo.GetTypeInfo(property.Type).ElementType : null;

            foreach (var subElement in _reader.ReadSubElements()) {
                if (subElement == SubElements.Properties) {
                    // Properties
                    ReadProperties(property.Properties, property.Type);
                    continue;
                }

                if (subElement == SubElements.Items) {
                    // Items
                    ReadItems(property.Items, property.ElementType);
                }
            }
        }
예제 #33
0
 public void Rebind(THost host, TProperty previousValue, TProperty value)
 {
     CollectionProperty.Remove(previousValue, _inverse, host);
     CollectionProperty.Add(value, _inverse, host);
 }
예제 #34
0
 protected void traverseCollection(CollectionProperty col, TestElementTraverser traverser)
 {
     PropertyIterator iter = col.iterator();
     while (iter.hasNext()) {
         TraverseProperty(traverser, iter.next());
     }
 }
        private void parseCollectionProperty(CollectionProperty property)
        {
            // ElementType
            property.ElementType = property.Type != null ? Polenter.Serialization.Serializing.TypeInfo.GetTypeInfo(property.Type, _simpleTypes).ElementType : null;

            foreach (string subElement in _reader.ReadSubElements())
            {
                if (subElement == SubElements.Properties)
                {
                    // Properties
                    readProperties(property.Properties, property.Type);
                    continue;
                }

                if (subElement == SubElements.Items)
                {
                    // Items
                    readItems(property.Items, property.ElementType);
                }
            }
        }
        public PropertyDefinition BuildCollectionProperty(CollectionProperty property, TypeDefinition type)
        {
            //如果是一对多关系,即关联属性是单值属性时,直接在上面加上关联关系
            //如果是多对多,则不需要处理,因为所属类型会执行这个动作


            var mod          = type.Module;
            var elementType  = property.PropertyType.GetTypeReference();
            var ptype        = mod.ImportReference(typeof(XPCollection <>)).MakeGenericType(elementType);
            var propertyInfo = new PropertyDefinition(property.称, PropertyAttributes.None, ptype)
            {
                HasThis = true
            };

            type.Properties.Add(propertyInfo);

            propertyInfo.Assocication(property);
            if (property.Aggregated)
            {
                propertyInfo.Aggregate();
            }

            #region getter
            //.method public hidebysig specialname instance string get_创建者() cil managedMono.Cecil.MethodAttributes.Public | Mono.Cecil.MethodAttributes.HideBySig | Mono.Cecil.MethodAttributes.SpecialName
            var attr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.FamANDAssem | MethodAttributes.Family;

            var getMethod = new MethodDefinition("get_" + property.称, attr, ptype);

            var getMethodIl = getMethod.Body.GetILProcessor();
            getMethod.Body.Variables.Add(new VariableDefinition(ptype));

            getMethod.Body.MaxStackSize = 8;

            getMethod.Body.InitLocals = true;
            //.maxstack 2
            //.locals init ([0] class [DevExpress.Xpo.v15.2]DevExpress.Xpo.XPCollection`1<class IMatrix.ERP.Module.BusinessObjects.员工> xps)
            //L_0000: nop
            //L_0001: ldarg.0
            //L_0002: ldstr "\u8054\u7cfb\u4eba"
            //L_0007: call instance class [DevExpress.Xpo.v15.2]DevExpress.Xpo.XPCollection`1<!!0> [DevExpress.Xpo.v15.2]DevExpress.Xpo.XPBaseObject::GetCollection<class IMatrix.ERP.Module.BusinessObjects.员工>(string)
            //L_000c: stloc.0
            //L_000d: br.s L_000f
            //L_000f: ldloc.0
            //L_0010: ret
            getMethodIl.Emit(OpCodes.Nop);
            getMethodIl.Emit(OpCodes.Ldarg_0);
            getMethodIl.Emit(OpCodes.Ldstr, property.称);
            var clrGetCollection = typeof(SimpleObject).GetMethods(SR.BindingFlags.NonPublic | SR.BindingFlags.Instance).Single(x => x.Name == "GetCollection" && x.ReturnType.IsGenericType);
            var getCollection    = mod.ImportReference(clrGetCollection); //(tb as TypeDefinition).Methods.Single(x => x.Name == ".ctor" && x.Parameters.First().ParameterType.FullName == typeof(Session).FullName);
            getCollection = getCollection.MakeGenericMethod(elementType);

            getMethodIl.Emit(OpCodes.Call, getCollection);
            getMethodIl.Emit(OpCodes.Stloc_0);

            var ldloc0 = getMethodIl.Create(OpCodes.Ldloc_0);
            getMethodIl.Emit(OpCodes.Br_S, ldloc0);
            getMethodIl.Append(ldloc0);
            getMethodIl.Emit(OpCodes.Ret);
            type.Methods.Add(getMethod);
            propertyInfo.GetMethod = getMethod;

            #endregion

            return(propertyInfo);
        }
        public PropertyDefinition BuildCollectionProperty(CollectionProperty property,TypeDefinition type)
        {
            //如果是一对多关系,即关联属性是单值属性时,直接在上面加上关联关系
            //如果是多对多,则不需要处理,因为所属类型会执行这个动作

            var mod = type.Module;
            var elementType = property.PropertyType.GetTypeReference();
            var ptype = mod.ImportReference(typeof(XPCollection<>)).MakeGenericType(elementType);
            var propertyInfo = new PropertyDefinition(property.名称, PropertyAttributes.None, ptype) { HasThis = true };
            type.Properties.Add(propertyInfo);

            propertyInfo.Assocication(property);
            if (property.Aggregated)
            {
                propertyInfo.Aggregate();
            }

            #region getter
            //.method public hidebysig specialname instance string get_创建者() cil managedMono.Cecil.MethodAttributes.Public | Mono.Cecil.MethodAttributes.HideBySig | Mono.Cecil.MethodAttributes.SpecialName
            var attr = MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.FamANDAssem | MethodAttributes.Family;

            var getMethod = new MethodDefinition("get_" + property.名称, attr, ptype);

            var getMethodIl = getMethod.Body.GetILProcessor();
            getMethod.Body.Variables.Add(new VariableDefinition(ptype));

            getMethod.Body.MaxStackSize = 8;

            getMethod.Body.InitLocals = true;
            //.maxstack 2
            //.locals init ([0] class [DevExpress.Xpo.v15.2]DevExpress.Xpo.XPCollection`1<class IMatrix.ERP.Module.BusinessObjects.员工> xps)
            //L_0000: nop
            //L_0001: ldarg.0
            //L_0002: ldstr "\u8054\u7cfb\u4eba"
            //L_0007: call instance class [DevExpress.Xpo.v15.2]DevExpress.Xpo.XPCollection`1<!!0> [DevExpress.Xpo.v15.2]DevExpress.Xpo.XPBaseObject::GetCollection<class IMatrix.ERP.Module.BusinessObjects.员工>(string)
            //L_000c: stloc.0
            //L_000d: br.s L_000f
            //L_000f: ldloc.0
            //L_0010: ret
            getMethodIl.Emit(OpCodes.Nop);
            getMethodIl.Emit(OpCodes.Ldarg_0);
            getMethodIl.Emit(OpCodes.Ldstr, property.名称);
            var clrGetCollection = typeof(SimpleObject).GetMethods(SR.BindingFlags.NonPublic | SR.BindingFlags.Instance).Single(x => x.Name == "GetCollection" && x.ReturnType.IsGenericType);
            var getCollection = mod.ImportReference(clrGetCollection);    //(tb as TypeDefinition).Methods.Single(x => x.Name == ".ctor" && x.Parameters.First().ParameterType.FullName == typeof(Session).FullName);
            getCollection = getCollection.MakeGenericMethod(elementType);

            getMethodIl.Emit(OpCodes.Call, getCollection);
            getMethodIl.Emit(OpCodes.Stloc_0);

            var ldloc0 = getMethodIl.Create(OpCodes.Ldloc_0);
            getMethodIl.Emit(OpCodes.Br_S, ldloc0);
            getMethodIl.Append(ldloc0);
            getMethodIl.Emit(OpCodes.Ret);
            type.Methods.Add(getMethod);
            propertyInfo.GetMethod = getMethod;

            #endregion

            return propertyInfo;
        }
예제 #38
0
        /// <summary>
        /// Saves the given collection property into the given node.
        /// </summary>
        /// <param name="rootNode">The node under which to store the new property node.</param>
        /// <param name="property">The property to save.</param>
        /// <param name="propertyName">The name of the property.</param>
        /// <returns>Returns true if the property was written.</returns>
        private static bool SaveCollectionProperty(XmlNode rootNode, CollectionProperty property, string propertyName)
        {
            Param.AssertNotNull(rootNode, "rootNode");
            Param.AssertNotNull(property, "property");
            Param.AssertValidString(propertyName, "propertyName");

            if (property.Values.Count > 0)
            {
                // Create and append the root node for this property.
                XmlNode propertyNode = rootNode.OwnerDocument.CreateElement("CollectionProperty");
                rootNode.AppendChild(propertyNode);

                XmlAttribute propertyNameAttribute = rootNode.OwnerDocument.CreateAttribute("Name");
                propertyNameAttribute.Value = propertyName;
                propertyNode.Attributes.Append(propertyNameAttribute);

                // Add sub-nodes for each property value.
                foreach (string value in property.Values)
                {
                    XmlNode valueNode = rootNode.OwnerDocument.CreateElement("Value");
                    valueNode.InnerText = value;
                    propertyNode.AppendChild(valueNode);
                }

                return true;
            }

            return false;
        }
        private void parseCollectionProperty(CollectionProperty property)
        {
            // Element type
            property.ElementType = _reader.ReadType();

            // Properties
            readProperties(property.Properties, property.Type);

            // Items
            readItems(property.Items, property.ElementType);
        }
예제 #40
0
 private static void MergeCollectionProperties(PropertyCollection mergedPropertyCollection, PropertyValue originalProperty, PropertyValue overridingProperty)
 {
     CollectionProperty property = (CollectionProperty) originalProperty;
     CollectionProperty property2 = (CollectionProperty) overridingProperty;
     CollectionProperty property3 = new CollectionProperty((CollectionPropertyDescriptor) property.PropertyDescriptor);
     mergedPropertyCollection.Add(property3);
     foreach (string str in property2.Values)
     {
         property3.Add(str);
     }
     if (property.Aggregate)
     {
         foreach (string str2 in property.Values)
         {
             if (!property3.Contains(str2))
             {
                 property3.Add(str2);
             }
         }
     }
 }
예제 #41
0
        private void parseCollectionProperty(XmlReader reader, CollectionProperty property)
        {
            // ElementType
            property.ElementType = getElementTypeAttribute(reader);

            while (reader.Read())
            {
                // Properties
                if (arePropertiesFound(reader))
                {
                    using (var subReader = new SubtreeReader(reader))
                    {
                        readProperties(subReader.Reader, property.Properties, property.Type);
                    }
                }

                // Items
                if (areItemsFound(reader))
                {
                    using (var subReader = new SubtreeReader(reader))
                    {
                        readItems(subReader.Reader, property.Items, property.ElementType);
                    }
                }
            }
        }
예제 #42
0
        private bool FillCollectionProperty(CollectionProperty property, TypeInfo info, object value)
        {
            if (property == null) {
                return false;
            }

            // Parsing properties
            ParseProperties(property, info, value);

            // Parse Items
            ParseCollectionItems(property, info, value);

            return true;
        }
예제 #43
0
 private static void LoadCollectionProperty(string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
 {
     List<string> innerCollection = new List<string>();
     XmlNodeList list2 = propertyNode.SelectNodes("Value");
     if ((list2 != null) && (list2.Count > 0))
     {
         foreach (XmlNode node in list2)
         {
             if (!string.IsNullOrEmpty(node.InnerText))
             {
                 innerCollection.Add(node.InnerText);
             }
         }
     }
     if (innerCollection.Count > 0)
     {
         CollectionPropertyDescriptor propertyDescriptor = propertyDescriptors[propertyName] as CollectionPropertyDescriptor;
         CollectionProperty property = new CollectionProperty(propertyDescriptor, innerCollection);
         properties.Add(property);
     }
 }
        /// <summary>
        /// Loads and stores a collection property.
        /// </summary>
        /// <param name="propertyName">
        /// The name of the property to load.
        /// </param>
        /// <param name="propertyNode">
        /// The node containing the property.
        /// </param>
        /// <param name="properties">
        /// The collection in which to store the property.
        /// </param>
        /// <param name="propertyDescriptors">
        /// The collection of property descriptors.
        /// </param>
        private static void LoadCollectionProperty(
            string propertyName, XmlNode propertyNode, PropertyCollection properties, PropertyDescriptorCollection propertyDescriptors)
        {
            Param.AssertValidString(propertyName, "propertyName");
            Param.AssertNotNull(propertyNode, "propertyNode");
            Param.AssertNotNull(properties, "properties");
            Param.AssertNotNull(propertyDescriptors, "propertyDescriptors");

            // Create and load the inner property collection.
            List<string> innerCollection = new List<string>();

            // Load the value list.
            XmlNodeList valueNodes = propertyNode.SelectNodes("Value");
            if (valueNodes != null && valueNodes.Count > 0)
            {
                foreach (XmlNode valueNode in valueNodes)
                {
                    if (!string.IsNullOrEmpty(valueNode.InnerText))
                    {
                        innerCollection.Add(valueNode.InnerText);
                    }
                }
            }

            // If at least one value was loaded, save the proeprty.
            if (innerCollection.Count > 0)
            {
                // Get the property descriptor.
                CollectionPropertyDescriptor descriptor = propertyDescriptors[propertyName] as CollectionPropertyDescriptor;

                // Create the collection node and pass in the inner collection.
                CollectionProperty collectionProperty = new CollectionProperty(descriptor, innerCollection);

                // Add this property to the parent collection.
                properties.Add(collectionProperty);
            }
        }
예제 #45
0
 private static bool SaveCollectionProperty(XmlNode rootNode, CollectionProperty property, string propertyName)
 {
     if (property.Values.Count <= 0)
     {
         return false;
     }
     XmlNode newChild = rootNode.OwnerDocument.CreateElement("CollectionProperty");
     rootNode.AppendChild(newChild);
     XmlAttribute node = rootNode.OwnerDocument.CreateAttribute("Name");
     node.Value = propertyName;
     newChild.Attributes.Append(node);
     foreach (string str in property.Values)
     {
         XmlNode node2 = rootNode.OwnerDocument.CreateElement("Value");
         node2.InnerText = str;
         newChild.AppendChild(node2);
     }
     return true;
 }