Exemple #1
0
        /// <summary>
        /// Applies the <see cref="Constructor"/> and <see cref="MemberAssignment"/> information to bind
        /// a SPARQL results row to a new LINQ result object
        /// </summary>
        /// <param name="values">The SPARQL results row</param>
        /// <returns>The new LINQ result object</returns>
        public object MapRow(Dictionary <string, object> values)
        {
            object ret = null;

            if (Constructor != null)
            {
                if (Constructor.GetParameters().Count() == 0)
                {
                    ret = Constructor.Invoke(new object[0]);
                }
                else
                {
                    var ctorParams = ConstructorArgs.Select(ca => values[ca]).ToArray();
                    ret = Constructor.Invoke(ctorParams);
                }
            }
            if (ret != null)
            {
                foreach (var mapping in MemberAssignment)
                {
                    if (values.ContainsKey(mapping.Item2))
                    {
                        Constructor.DeclaringType.InvokeMember(mapping.Item1.Name, BindingFlags.Public, null, ret,
                                                               new object[] { values[mapping.Item2] });
                    }
                }
            }
            return(ret);
        }
Exemple #2
0
        protected override void ProcessNew(NewExpression expression)
        {
            base.ProcessNew(expression);

            if (expression.Constructor.DeclaringType != null)
            {
                Assembly assembly =
                    Assembly.ReflectionOnlyLoad(expression.Constructor.DeclaringType.Assembly.FullName);

                Constructor = assembly
                              .GetType(expression.Constructor.DeclaringType.FullName)
                              .GetConstructor(ConstructorArgs.Select((arg) => arg.GetType()).ToArray());
            }
        }
 public void ConstructorValidation(ConstructorArgs args)
 {
     if (args.IsValid)
     {
         Assert.IsNotNull(new LogConfiguration(args.Name, args.Type, args.Subs, args.Filters));
     }
     else
     {
         Assert.Throws <InvalidConfigurationException>(
             () =>
             new LogConfiguration(args.Name, args.Type, args.Subs,
                                  args.Filters));
     }
 }
Exemple #4
0
        public Message(@@ConstructorArgs@@byte[] aData)
        {
            Init();
            if (!Parse(aData))
            {
@@InitFieldsWithDefaults@@
                Command = KMsgError;
                Code = KErrBadParameters;
                _reader = null;
                _writer = null;
                _data = null;
            }
            else
            {
@@InitFieldsWithArgs@@
            }
        }
Exemple #5
0
        /// <summary>
        /// Constructs an instance of the attribute using the data contained
        /// in the blob. The result should be indistinguishable from the original
        /// attribute.
        /// </summary>
        /// <returns>New attribute</returns>
        public Attribute Build()
        {
            Attribute att = (Attribute)Constructor.Invoke(ConstructorArgs.ToArray());

            foreach (var namedArgument in NamedArguments)
            {
                switch (namedArgument.MemberInfo)
                {
                case FieldInfo fi: fi.SetValue(att, namedArgument.Value); break;

                case PropertyInfo pi: pi.SetValue(att, namedArgument.Value); break;

                default: throw new InvalidOperationException($"Unknown member type: {namedArgument.MemberInfo.GetType()}");
                }
            }

            return(att);
        }
        /// <summary>
        /// Applies the <see cref="Constructor"/> and <see cref="MemberAssignment"/> information to bind
        /// a SPARQL results row to a new LINQ result object
        /// </summary>
        /// <param name="values">The SPARQL results row</param>
        /// <returns>The new LINQ result object</returns>
        public object MapRow(Dictionary <string, object> values)
        {
            object ret = null;

            if (Constructor != null)
            {
                if (Constructor.GetParameters().Count() == 0)
                {
                    ret = Constructor.Invoke(new object[0]);
                }
                else
                {
                    var ctorParams = ConstructorArgs.Select(ca => values[ca]).ToArray();
                    ret = Constructor.Invoke(ctorParams);
                }
            }
            if (ret != null)
            {
                foreach (var mapping in MemberAssignment)
                {
                    if (values.ContainsKey(mapping.Item2))
                    {
#if PORTABLE
                        var memberInfo =
                            Constructor.DeclaringType.GetMember(mapping.Item1.Name, BindingFlags.Public).FirstOrDefault();
                        if (memberInfo != null)
                        {
                            var methodInfo = memberInfo as MethodInfo;
                            methodInfo.Invoke(ret, new [] { values[mapping.Item2] });
                        }
#else
                        Constructor.DeclaringType.InvokeMember(mapping.Item1.Name, BindingFlags.Public, null, ret,
                                                               new object[] { values[mapping.Item2] });
#endif
                    }
                }
            }
            return(ret);
        }
Exemple #7
0
 public static Message ErrorMessage(@@ConstructorArgs@@int errCode)
 {
     Message msg = new Message(@@ConstructorActualArgs@@KMsgError);
     msg.Code = errCode;
     return msg;
 }
Exemple #8
0
        public Message(@@ConstructorArgs@@int command)
        {
            Init();
@@InitFieldsWithArgs@@
            Command = command;
        }