private static IFieldConverter InstantiateConverter(MetaProperty info, SPField field)
		{
			var converter = info.CustomConverterType != null ?
				FieldConverterResolver.Instance.Create(info.CustomConverterType) :
				FieldConverterResolver.Instance.Create(field.TypeAsString);

			converter.Initialize(field, info.MemberType);

			return converter;
		}
示例#2
0
     /// <summary>
 	/// Implements the constructor: MetaProperty()
 	/// Direct superclasses: global::MetaDslx.Core.MetaNamedElement, global::MetaDslx.Core.MetaTypedElement, global::MetaDslx.Core.MetaAnnotatedElement
 	/// All superclasses: global::MetaDslx.Core.MetaNamedElement, global::MetaDslx.Core.MetaDocumentedElement, global::MetaDslx.Core.MetaTypedElement, global::MetaDslx.Core.MetaAnnotatedElement
     /// </summary>
     public virtual void MetaProperty(MetaProperty @this)
     {
         this.MetaNamedElement(@this);
         this.MetaTypedElement(@this);
         this.MetaAnnotatedElement(@this);
     }
示例#3
0
 public void AddProperty(MetaProperty property)
 {
     properties.Add(property);
 }
		private void ImplementProperty(ClassEmitter emitter, MetaProperty property, ProxyGenerationOptions options)
		{
			property.BuildPropertyEmitter(emitter);
			if (property.CanRead)
			{
				ImplementMethod(property.Getter, emitter, options, property.Emitter.CreateGetMethod);
			}

			if (property.CanWrite)
			{
				ImplementMethod(property.Setter, emitter, options, property.Emitter.CreateSetMethod);
			}
		}
示例#5
0
        private void AddProperty(PropertyInfo property, IProxyGenerationHook hook)
        {
            MetaMethod getter = null;
            MetaMethod setter = null;

            if (property.CanRead)
            {
                var getMethod = property.GetGetMethod(true);
                getter = AddMethod(getMethod, hook, false);
            }

            if (property.CanWrite)
            {
                var setMethod = property.GetSetMethod(true);
                setter = AddMethod(setMethod, hook, false);
            }

            if (setter == null && getter == null)
            {
                return;
            }

            var nonInheritableAttributes = property.GetNonInheritableAttributes();
            var arguments = property.GetIndexParameters();

            properties[property] = new MetaProperty(property.Name,
                                                    property.PropertyType,
                                                    property.DeclaringType,
                                                    getter,
                                                    setter,
                                                    nonInheritableAttributes,
                                                    arguments.Select(a => a.ParameterType).ToArray());
        }
		private void AddProperty(PropertyInfo property, IProxyGenerationHook hook)
		{
			MetaMethod getter = null;
			MetaMethod setter = null;

			if (property.CanRead)
			{
				MethodInfo getMethod = property.GetGetMethod(true);
				getter = AddMethod(getMethod, hook, false);
			}

			if (property.CanWrite)
			{
				MethodInfo setMethod = property.GetSetMethod(true);
				setter = AddMethod(setMethod, hook, false);
			}

			if (setter==null && getter == null)
			{
				return;
			}

			var nonInheritableAttributes = AttributeUtil.GetNonInheritableAttributes(property);
			properties[property] = new MetaProperty(property.Name,
			                                              property.PropertyType,
														  property.DeclaringType, getter, setter, PropertyAttributes.None, nonInheritableAttributes);
		}
示例#7
0
 public override Builder set <T1>(MetaProperty <T1> property, object value)
 {
     base.set(property, value);
     return(this);
 }
        private void VisitReferenceTypeColumn(ColumnReferenceExpression node, TSqlFragment parent, string sourceProperty, Identifier identifier, MetaProperty property)
        {
            if (property.Fields.Count == 1) // Т.Ссылка (не составной тип)
            {
                string hexTypeCode = $"0x{property.PropertyTypes[0].ToString("X").PadLeft(8, '0')}";
                identifier.Value = property.Fields[0].Name;
                ParenthesisExpression expression = new ParenthesisExpression()
                {
                    Expression = new ScriptDom.BinaryExpression()
                    {
                        BinaryExpressionType = BinaryExpressionType.Add,
                        FirstExpression      = new BinaryLiteral()
                        {
                            Value = hexTypeCode
                        },
                        SecondExpression = node
                    }
                };
                PropertyInfo pi     = parent.GetType().GetProperty(sourceProperty);
                bool         isList = (pi.PropertyType.IsGenericType && pi.PropertyType.GetGenericTypeDefinition() == typeof(IList <>));
                if (isList)
                {
                    IList list  = (IList)pi.GetValue(parent);
                    int   index = list.IndexOf(node);
                    list[index] = expression;
                }
                else
                {
                    pi.SetValue(parent, expression);
                }
            }
            else // Т.Владелец (составной тип)
            {
                MetaField typeCode  = property.Fields.Where(f => f.Purpose == MetaFieldPurpose.TypeCode).FirstOrDefault();
                MetaField reference = property.Fields.Where(f => f.Purpose == MetaFieldPurpose.Object).FirstOrDefault();
                identifier.Value = reference.Name;

                MultiPartIdentifier mpi = new MultiPartIdentifier();
                foreach (var id in node.MultiPartIdentifier.Identifiers)
                {
                    mpi.Identifiers.Add(new Identifier()
                    {
                        Value = id.Value
                    });
                }
                mpi.Identifiers[mpi.Count - 1].Value = typeCode.Name;
                ParenthesisExpression expression = new ParenthesisExpression()
                {
                    Expression = new ScriptDom.BinaryExpression()
                    {
                        BinaryExpressionType = BinaryExpressionType.Add,
                        FirstExpression      = new ColumnReferenceExpression()
                        {
                            ColumnType          = ColumnType.Regular,
                            MultiPartIdentifier = mpi
                        },
                        SecondExpression = node
                    }
                };

                PropertyInfo pi     = parent.GetType().GetProperty(sourceProperty);
                bool         isList = (pi.PropertyType.IsGenericType && pi.PropertyType.GetGenericTypeDefinition() == typeof(IList <>));
                if (isList)
                {
                    IList list  = (IList)pi.GetValue(parent);
                    int   index = list.IndexOf(node);
                    list[index] = expression;
                }
                else
                {
                    pi.SetValue(parent, expression);
                }
            }
        }
        public ISyntaxNode Visit(TSqlFragment node, TSqlFragment parent, string sourceProperty, ISyntaxNode result)
        {
            ColumnReferenceExpression columnReference = node as ColumnReferenceExpression;

            if (columnReference == null)
            {
                return(result);
            }

            StatementNode statement = result as StatementNode;

            if (statement == null)
            {
                return(result);
            }
            if (columnReference.ColumnType != ColumnType.Regular)
            {
                return(result);
            }
            if (statement.Tables == null || statement.Tables.Count == 0)
            {
                return(result);
            }

            Identifier     identifier        = null;
            string         propertyFieldName = null;
            IList <string> identifiers       = new List <string>();

            for (int i = 0; i < columnReference.MultiPartIdentifier.Identifiers.Count; i++)
            {
                identifiers.Add(columnReference.MultiPartIdentifier.Identifiers[i].Value);
            }

            if (identifiers.Count == 1) // no table alias - just column name
            {
                identifier = columnReference.MultiPartIdentifier.Identifiers[0];
            }
            else if (columnReference.MultiPartIdentifier.Identifiers.Count == 2)
            {
                if (IsSpecialField(identifiers[1])) // no table alias - just column name
                {
                    propertyFieldName = identifiers[1];
                    identifier        = columnReference.MultiPartIdentifier.Identifiers[0];
                }
                else
                {
                    identifier = columnReference.MultiPartIdentifier.Identifiers[1];
                }
            }
            else // columnReference.MultiPartIdentifier.Identifiers.Count == 3
            {
                propertyFieldName = identifiers[2];
                identifier        = columnReference.MultiPartIdentifier.Identifiers[1];
            }

            MetaProperty property = GetProperty(identifiers, statement);

            if (property == null)
            {
                return(result);
            }
            if (property.Fields.Count == 0)
            {
                return(result);
            }

            if (property.IsReferenceType)
            {
                if (propertyFieldName == null) // Т.Ссылка | Т.Владелец
                {
                    VisitReferenceTypeColumn(columnReference, parent, sourceProperty, identifier, property);
                }
                else // uuid | type | TYPE
                {
                    VisitReferenceTypeColumn(columnReference, parent, sourceProperty, columnReference.MultiPartIdentifier.Identifiers, identifier, property, propertyFieldName);
                }
            }
            else // Т.Наименование
            {
                VisitValueTypeColumn(identifier, property);
            }

            return(result);
        }
        private void VisitReferenceTypeColumn(ColumnReferenceExpression node, TSqlFragment parent, string sourceProperty, IList <Identifier> identifiers, Identifier identifier, MetaProperty property, string fieldName)
        {
            MetaField     field         = null;
            BinaryLiteral binaryLiteral = null;

            if (fieldName == "uuid")
            {
                if (property.Fields.Count == 1)
                {
                    field = property.Fields[0];
                }
                else
                {
                    field = property.Fields.Where(f => f.Purpose == MetaFieldPurpose.Object).FirstOrDefault();
                }
            }
            else if (fieldName == "type")
            {
                if (property.Fields.Count == 1)
                {
                    string HexTypeCode = $"0x{property.PropertyTypes[0].ToString("X").PadLeft(8, '0')}";
                    binaryLiteral = new BinaryLiteral()
                    {
                        Value = HexTypeCode
                    };
                }
                else
                {
                    field = property.Fields.Where(f => f.Purpose == MetaFieldPurpose.TypeCode).FirstOrDefault();
                }
            }
            else if (fieldName == "TYPE")
            {
                if (property.Fields.Count == 1)
                {
                    binaryLiteral = new BinaryLiteral()
                    {
                        Value = "0x08"
                    };
                }
                else
                {
                    field = property.Fields.Where(f => f.Purpose == MetaFieldPurpose.Discriminator).FirstOrDefault();
                }
            }
            // TODO: throw new MissingMemberException !? if nonexistent field referenced

            if (binaryLiteral == null)
            {
                identifier.Value = field.Name;               // change object property identifier to SQL table column identifier
                identifiers.RemoveAt(identifiers.Count - 1); // uuid | type | TYPE
            }
            else
            {
                TransformToBinaryLiteral(node, parent, sourceProperty, binaryLiteral);
            }
        }
示例#11
0
 public void Add(MetaProperty property)
 {
     model.AddProperty(property);
     contributor.properties.Add(property);
 }
示例#12
0
 public virtual void VisitMetaProperty(MetaProperty metaProperty)
 {
 }