Esempio n. 1
0
 static void CheckSetProperties(Dictionary <string, ClassInfo> classes, ClassInfo classInfo, FlowSourceObjectBase flowSource)
 {
     foreach (var name in classInfo.SetValues)
     {
         if (!flowSource.InPropertyNames.Contains(name))
         {
             classInfo.AddError(String.Format("{0} is not defined", name));
             errorFiles.Add(classInfo);
         }
     }
     foreach (var setterPropertyName in flowSource.InPropertyNames)
     {
         bool      usedFound        = false;
         var       type             = flowSource.GetType();
         ClassInfo currentClassInfo = classInfo;
         while (type != null)
         {
             if (currentClassInfo.ContainsSetValue(setterPropertyName))
             {
                 usedFound = true;
                 break;
             }
             type = type.BaseType;
             var className = type.FullName;
             if (type.IsGenericType)
             {
                 className = GetGenericClassName(className);
             }
             if (!classes.TryGetValue(className, out currentClassInfo))
             {
                 break;
             }
         }
         if (!usedFound)
         {
             classInfo.AddError(String.Format("{0} is defined, but not used in SetValue()", setterPropertyName));
             errorFiles.Add(classInfo);
         }
     }
 }
Esempio n. 2
0
        public static string GetFastCode(FlowSourceObjectBase flowSource)
        {
            var ret  = new StringBuilder();
            var type = flowSource.GetType();

            int level = 0;

            WriteData(ret, "//--------------------------------------------------------", level);
            WriteData(ret, "// This code is generated by AutoFastGenerator.", level);
            WriteData(ret, "// You should not modify the code.", level);
            WriteData(ret, "//--------------------------------------------------------", level);
            ret.AppendLine();

            WriteData(ret, String.Format("namespace {0}", type.Namespace), level);
            WriteData(ret, "{", level);
            level++;
            WriteData(ret, String.Format("public partial class {0}", type.Name), level);
            WriteData(ret, "{", level);
            level++;

            if (flowSource.OutProperties.Count > 0)
            {
                WriteData(ret, "public override object GetPropertyValue(string propertyName)", level);
                WriteData(ret, "{", level);
                level++;

                WriteData(ret, "switch (propertyName)", level);
                WriteData(ret, "{", level);
                level++;

                foreach (CustomMemberInfo <PropertyInfo> propertyInfo in flowSource.OutProperties)
                {
                    WriteData(ret, String.Format("case \"{0}\":", propertyInfo.MemberInfo.Name), level);
                    foreach (var replacedName in propertyInfo.ReplacedNames)
                    {
                        WriteData(ret, String.Format("case \"{0}\":", replacedName), level);
                    }
                    level++;
                    WriteData(ret, String.Format("return {0};", propertyInfo.MemberInfo.Name), level);
                    level--;
                }

                WriteData(ret, "default:", level);
                level++;
                WriteData(ret, "return null;", level);
                level--;

                level--;
                WriteData(ret, "}", level);

                level--;
                WriteData(ret, "}", level);
            }
            ret.AppendLine();
            if (flowSource.InProperties.Count > 0)
            {
                WriteData(ret, "protected override void SetPropertyValue(string propertyName, object value)", level);
                WriteData(ret, "{", level);
                level++;

                WriteData(ret, "switch (propertyName)", level);
                WriteData(ret, "{", level);
                level++;

                foreach (CustomMemberInfo <PropertyInfo> propertyInfo in flowSource.InProperties)
                {
                    WriteData(ret, String.Format("case \"{0}\":", propertyInfo.MemberInfo.Name), level);
                    foreach (var replacedName in propertyInfo.ReplacedNames)
                    {
                        WriteData(ret, String.Format("case \"{0}\":", replacedName), level);
                    }
                    level++;
                    WriteData(ret, String.Format("{0} = ({1})value;", propertyInfo.MemberInfo.Name, GetClassName(propertyInfo.MemberInfo.PropertyType)), level);
                    WriteData(ret, "break;", level);
                    level--;
                }

                level--;
                WriteData(ret, "}", level);

                level--;
                WriteData(ret, "}", level);
            }

            ret.AppendLine();
            if (flowSource.OutMethods.Count > 0)
            {
                WriteData(ret, "public override void ConnectEvent(string eventName, FlowScriptEngine.FlowEventHandler eventHandler)", level);
                WriteData(ret, "{", level);
                level++;

                WriteData(ret, "switch (eventName)", level);
                WriteData(ret, "{", level);
                level++;

                foreach (CustomMemberInfo <EventInfo> eventInfo in flowSource.OutMethods)
                {
                    WriteData(ret, String.Format("case \"{0}\":", eventInfo.MemberInfo.Name), level);
                    foreach (var replacedName in eventInfo.ReplacedNames)
                    {
                        WriteData(ret, String.Format("case \"{0}\":", replacedName), level);
                    }
                    level++;
                    WriteData(ret, String.Format("{0} += new FlowScriptEngine.FlowEventHandler(eventHandler);", eventInfo.MemberInfo.Name), level);
                    WriteData(ret, "break;", level);
                    level--;
                }

                level--;
                WriteData(ret, "}", level);

                level--;
                WriteData(ret, "}", level);
            }


            level--;
            WriteData(ret, "}", level);
            level--;
            WriteData(ret, "}", level);

            return(ret.ToString());
        }