private SqlParameter GetParam(PropertyInfo property)
        {
            SqlParameter    param;
            string          tempName        = property.Name;
            SqlDbType       tempType        = SqlDbType.NVarChar;
            IgnoreAttribute ignoreattribute = property.GetCustomAttributes(typeof(IgnoreAttribute), false).FirstOrDefault() as IgnoreAttribute;

            if (ignoreattribute != null)
            {
                return(null);
            }
            ParamAttribute attribute = property.GetCustomAttributes(typeof(ParamAttribute), false).FirstOrDefault() as ParamAttribute;

            if (attribute != null)
            {
                tempName = attribute.Name;
                tempType = attribute.Type;
            }
            if (!tempName.StartsWith("@"))
            {
                tempName = $"@{tempName}";
            }
            param = new SqlParameter(tempName, tempType);

            var objVal = property.GetValue(this);

            param.Value = objVal;

            if (param.Value == null)
            {
                param.SqlValue = DBNull.Value;
            }
            return(param);
        }
Beispiel #2
0
        string GetParameterTooltip(int parameterNumber)
        {
            DndFunction dndFunction = TextCompletionEngine.GetActiveDndFunction(TextEditor.TextArea);

            if (dndFunction == null)
            {
                return(null);
            }

            IEnumerable <ParamAttribute> customAttributes = dndFunction.GetType().GetCustomAttributes(typeof(ParamAttribute)).Cast <ParamAttribute>().ToList();

            if (customAttributes == null)
            {
                return(null);
            }

            ParamAttribute paramAttribute = customAttributes.FirstOrDefault(x => x.Index == parameterNumber);

            if (paramAttribute == null)
            {
                return(null);
            }

            return(paramAttribute.Description);
        }
Beispiel #3
0
        public void applySettings(Data data)
        {
            Type type = this.GetType();

            // Iterate through all the methods of the class.
            foreach (FieldInfo field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
            {
                // Iterate through all the Attributes for each method.
                foreach (Attribute attr in Attribute.GetCustomAttributes(field))
                {
                    // Check for the AnimalType attribute.
                    if (attr.GetType() == typeof(ParamAttribute))
                    {
                        ParamAttribute pa = (ParamAttribute)attr;
                        if (pa.Type.Equals("float"))
                        {
                            data.SetNumber(pa.StringID, (float)field.GetValue(this));
                        }
                        else if (pa.Type.Equals("array"))
                        {
                            data.SetArray(pa.StringID, (float[])field.GetValue(this));
                        }
                        else if (pa.Type.Equals("string"))
                        {
                            data.SetString(pa.StringID, (string)field.GetValue(this));
                        }
                        else if (pa.Type.Equals("composite"))
                        {
                            ISettings fld = (ISettings)field.GetValue(this);
                            fld.applySettings(data);
                        }
                    }
                }
            }
        }
        private RuleParameter CreateConditionParameter(
            Type containerType, RuleParameterValueResolver containerResolver, string prefix, PropertyInfo property, ParamAttribute paramAttr)
        {
            var propertyType = property.PropertyType;
            var valueResolver = new ChainedRuleParameterValueResolver().Chain(containerResolver, new PropertyBackedRuleParameterValueResolver(property));
            var supportedOperators = GetDefaultOperators(propertyType);
            IRuleParameterValueSource valueSource = null;

            if (paramAttr.ValueSource != null)
            {
                valueSource = TypeActivator.CreateInstance(paramAttr.ValueSource) as IRuleParameterValueSource;
            }
            else if (property.PropertyType.IsEnum)
            {
                propertyType = typeof(String);
                valueSource = StaticRuleParameterValueSource.FromEnum(property.PropertyType);
            }
            else if (IsNullableEnum(property.PropertyType))
            {
                propertyType = typeof(String);
                valueSource = StaticRuleParameterValueSource.FromEnum(Nullable.GetUnderlyingType(property.PropertyType));
            }

            var paramName = prefix + (paramAttr.Name ?? property.Name);

            return new RuleParameter(paramName, propertyType, valueResolver, supportedOperators)
            {
                ValueSource = valueSource
            };
        }
 private static void initParameterDictionary(Type objClass, object source, Dictionary <object, object> retParametersDictionary, string paramType)
 {
     try
     {
         FieldInfo[] declaredField = objClass.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance);
         int         i             = 0;
         for (i = 0; i < declaredField.Length; i++)
         {
             FieldInfo    field      = declaredField[i];
             string       methodName = "get" + field.Name.Substring(0, 1).ToUpper() + field.Name.Substring(1);
             string       fieldName  = field.Name;
             MethodInfo[] methods    = objClass.GetMethods();
             int          k          = 0;
             for (k = 0; k < methods.Length; k++)
             {
                 MethodInfo m = methods[k];
                 if (m.Name.Equals(methodName, StringComparison.CurrentCultureIgnoreCase))
                 {
                     ParamAttribute attribute = (ParamAttribute)ParamAttribute.GetCustomAttribute(m, typeof(ParamAttribute));
                     if (attribute == null)
                     {
                         continue;
                     }
                     if (!"".Equals(attribute.paramName))
                     {
                         fieldName = attribute.paramName;
                     }
                     if (paramType.Equals(attribute.paramType))
                     {
                         setParameterToDictionary(m, source, retParametersDictionary, fieldName);
                     }
                     else if (paramType.Equals(attribute.paramType))
                     {
                         setParameterToDictionary(m, source, retParametersDictionary, fieldName);
                     }
                     else if (paramType.Equals(attribute.paramType))
                     {
                         setParameterToDictionary(m, source, retParametersDictionary, fieldName);
                     }
                     else if ("".Equals(paramType))
                     {
                         setParameterToDictionary(m, source, retParametersDictionary, fieldName);
                     }
                 }
             }
         }
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Beispiel #6
0
        EditorProviderDetails GetCompletionProviderDetails()
        {
            EditorProviderDetails result = new EditorProviderDetails();

            DndFunction dndFunction = GetActiveDndFunction(TbxCode.TextArea);

            if (dndFunction != null)
            {
                result.ActiveMethodCall = dndFunction.Name;
                IEnumerable <ParamAttribute> customAttributes = dndFunction.GetType().GetCustomAttributes(typeof(ParamAttribute)).Cast <ParamAttribute>().ToList();
                if (customAttributes != null)
                {
                    int            parameterNumber = TbxCode.Document.GetParameterNumberAtPosition(TbxCode.CaretOffset);
                    ParamAttribute paramAttribute  = customAttributes.FirstOrDefault(x => x.Index == parameterNumber);
                    if (paramAttribute != null)
                    {
                        result.Name = paramAttribute.Editor;
                        result.Type = paramAttribute.Type;
                    }
                }
            }
            return(result);
        }
        private static Boolean initParameter(object o, FieldInfo[] declaredField, Type objType, object targetObj)
        {
            Boolean hasParam = false;
            int     i        = 0;

            for (i = 0; i < declaredField.Length; i++)
            {
                FieldInfo    field         = declaredField[i];
                string       methodField   = field.Name.Substring(0, 1).ToUpper() + field.Name.Substring(1);
                string       getMethodName = field.GetType() == typeof(Boolean) ? "is" + methodField : "get" + methodField;
                string       setMethodName = "set" + methodField;
                MethodInfo[] methods       = objType.GetMethods();
                int          k             = 0;
                for (k = 0; k < methods.Length; k++)
                {
                    MethodInfo m = methods[k];
                    if (m.Name.Equals(getMethodName))
                    {
                        ParamAttribute attribute = (ParamAttribute)ParamAttribute.GetCustomAttribute(m, typeof(ParamAttribute));
                        if (attribute == null)
                        {
                            continue;
                        }
                        string dataKey = attribute.paramName.ToString().ToLower();
                        if (o.ToString().IndexOf(dataKey) != -1 && o.ToString().IndexOf(":") != -1)
                        {
                            hasParam = true;
                            object     data = toObject(o, dataKey);
                            MethodInfo setM = objType.GetMethod(setMethodName);
                            setParameterToMap(setM, targetObj, field, data);
                        }
                    }
                }
            }
            return(hasParam);
        }
        /// <summary> Write a Param XML Element from attributes in a member. </summary>
        public virtual void WriteParam(System.Xml.XmlWriter writer, System.Reflection.MemberInfo member, ParamAttribute attribute, BaseAttribute parentAttribute, System.Type mappedClass)
        {
            writer.WriteStartElement( "param" );
            // Attribute: <name>
            writer.WriteAttributeString("name", attribute.Name==null ? DefaultHelper.Get_Param_Name_DefaultValue(member) : GetAttributeValue(attribute.Name, mappedClass));

            WriteUserDefinedContent(writer, member, null, attribute);

            // Write the content of this element (mixed="true")
            writer.WriteString(attribute.Content);

            writer.WriteEndElement();
        }
 private object[] CreateArgs(MethodInfo methodInfo, int iteration, ParamAttribute testDefaultParamGen) {
     List<object> args = new List<object>();
     var parameters = methodInfo.GetParameters();
     foreach (var arg in parameters) {
         object v;
         var paramGen = (ParamAttribute)arg.GetCustomAttributes(typeof(ParamAttribute), false).FirstOrDefault() ?? testDefaultParamGen;
         var typeCode = Type.GetTypeCode(arg.ParameterType);
         switch (typeCode) {
         case TypeCode.Boolean:
             v = paramGen.GenBool(this.rnd, iteration);
             break;
         case TypeCode.SByte:
             v = paramGen.GenSByte(this.rnd, iteration);
             break;
         case TypeCode.Byte:
             v = paramGen.GenByte(this.rnd, iteration);
             break;
         case TypeCode.Int16:
             v = paramGen.GenInt16(this.rnd, iteration);
             break;
         case TypeCode.Int32:
             v = paramGen.GenInt32(this.rnd, iteration);
             break;
         case TypeCode.Int64:
             v = paramGen.GenInt64(this.rnd, iteration);
             break;
         case TypeCode.UInt16:
             v = paramGen.GenUInt16(this.rnd, iteration);
             break;
         case TypeCode.UInt32:
             v = paramGen.GenUInt32(this.rnd, iteration);
             break;
         case TypeCode.UInt64:
             v = paramGen.GenUInt64(this.rnd, iteration);
             break;
         case TypeCode.Single:
             v = paramGen.GenSingle(this.rnd, iteration);
             break;
         case TypeCode.Double:
             v = paramGen.GenDouble(this.rnd, iteration);
             break;
         case TypeCode.String:
             v = paramGen.GenString(this.rnd, iteration);
             break;
         case TypeCode.Char:
             v = paramGen.GenChar(this.rnd, iteration);
             break;
         default:
             throw new NotImplementedException("Cannot handle: " + typeCode);
         }
         args.Add(v);
     }
     return args.ToArray();
 }
Beispiel #10
0
        private object[] CreateArgs(MethodInfo methodInfo, int iteration, ParamAttribute testDefaultParamGen)
        {
            List <object> args       = new List <object>();
            var           parameters = methodInfo.GetParameters();

            foreach (var arg in parameters)
            {
                object v;
                var    paramGen = (ParamAttribute)arg.GetCustomAttributes(typeof(ParamAttribute), false).FirstOrDefault() ?? testDefaultParamGen;
                var    typeCode = Type.GetTypeCode(arg.ParameterType);
                switch (typeCode)
                {
                case TypeCode.Boolean:
                    v = paramGen.GenBool(this.rnd, iteration);
                    break;

                case TypeCode.SByte:
                    v = paramGen.GenSByte(this.rnd, iteration);
                    break;

                case TypeCode.Byte:
                    v = paramGen.GenByte(this.rnd, iteration);
                    break;

                case TypeCode.Int16:
                    v = paramGen.GenInt16(this.rnd, iteration);
                    break;

                case TypeCode.Int32:
                    v = paramGen.GenInt32(this.rnd, iteration);
                    break;

                case TypeCode.Int64:
                    v = paramGen.GenInt64(this.rnd, iteration);
                    break;

                case TypeCode.UInt16:
                    v = paramGen.GenUInt16(this.rnd, iteration);
                    break;

                case TypeCode.UInt32:
                    v = paramGen.GenUInt32(this.rnd, iteration);
                    break;

                case TypeCode.UInt64:
                    v = paramGen.GenUInt64(this.rnd, iteration);
                    break;

                case TypeCode.Single:
                    v = paramGen.GenSingle(this.rnd, iteration);
                    break;

                case TypeCode.Double:
                    v = paramGen.GenDouble(this.rnd, iteration);
                    break;

                case TypeCode.String:
                    v = paramGen.GenString(this.rnd, iteration);
                    break;

                case TypeCode.Char:
                    v = paramGen.GenChar(this.rnd, iteration);
                    break;

                default:
                    throw new NotImplementedException("Cannot handle: " + typeCode);
                }
                args.Add(v);
            }
            return(args.ToArray());
        }
        private RuleParameter CreateConditionParameter(
            Type containerType, RuleParameterValueResolver containerResolver, string prefix, PropertyInfo property, ParamAttribute paramAttr)
        {
            var propertyType       = property.PropertyType;
            var valueResolver      = new ChainedRuleParameterValueResolver().Chain(containerResolver, new PropertyBackedRuleParameterValueResolver(property));
            var supportedOperators = GetDefaultOperators(propertyType);
            IRuleParameterValueSource valueSource = null;

            if (paramAttr.ValueSource != null)
            {
                valueSource = TypeActivator.CreateInstance(paramAttr.ValueSource) as IRuleParameterValueSource;
            }
            else if (property.PropertyType.IsEnum)
            {
                propertyType = typeof(String);
                valueSource  = StaticRuleParameterValueSource.FromEnum(property.PropertyType);
            }
            else if (IsNullableEnum(property.PropertyType))
            {
                propertyType = typeof(String);
                valueSource  = StaticRuleParameterValueSource.FromEnum(Nullable.GetUnderlyingType(property.PropertyType));
            }

            var paramName = prefix + (paramAttr.Name ?? property.Name);

            return(new RuleParameter(paramName, propertyType, valueResolver, supportedOperators)
            {
                ValueSource = valueSource
            });
        }