public override void CheckSemantics(Scope scope, List <SemanticError> errors) { if (Names.GroupBy(n => n).Count() != Names.Length) { errors.Add(new SemanticError { Message = "At least two fields have the same name", Node = this }); } foreach (var type in TypesNames) { if (!scope.IsDefined <Semantics.TypeInfo>(type)) { errors.Add(new SemanticError { Message = $"Undefined field type '{type}'", Node = this }); } } if (errors.Any()) { return; } Types = TypesNames.Select(t => scope.GetItem <Semantics.TypeInfo>(t)).ToArray(); }
private bool LoadFigureFromAssembly(string path, int figureNum) { try { string asmName = GetAssemblyName(Path.GetFileName(path)); Assembly asm = Assembly.LoadFrom(path); Type[] types = asm.GetTypes(); Type figure = null; Type factory = null; foreach (Type t in types) { if (t.BaseType.Equals(typeof(CTwoDFigureFactory))) { factory = t; } if (t.BaseType.Equals(typeof(CTwoDFigure))) { figure = t; } } if ((factory == null) || (figure == null)) { return(false); } MethodInfo[] methods = factory.GetMethods(BindingFlags.Public | BindingFlags.Static); if (methods.Length == 0) { return(false); } List <MethodInfo> goodMethods = new List <MethodInfo>(); foreach (MethodInfo m in methods) { ParameterInfo[] parameters = m.GetParameters(); if (parameters.Length == 0) { if (m.ReturnType.BaseType.Equals(typeof(CTwoDFigureFactory))) { goodMethods.Add(m); } } } if (goodMethods.Count != 1) { return(false); } LoadedTypes.Add(figure); LoadedMethods.Add(goodMethods[0]); if (FiguresGroupType == null) { Type[] interfaces = figure.GetInterfaces(); foreach (Type t in interfaces) { if (t.Equals(typeof(IFiguresGroup))) { FiguresGroupType = figure; } } } bool isPictureLoaded; Image pic = null; try { pic = Image.FromFile(String.Format(PICTURE_FILE_TEMPLATE, asmName)); isPictureLoaded = true; } catch (Exception) { isPictureLoaded = false; } if (isPictureLoaded) { UI.CreateButton(String.Format(BUTTON_NAME_TEMPLATE, figureNum), pic); } else { UI.CreateButton(String.Format(BUTTON_NAME_TEMPLATE, figureNum), figure.Name); } string[] typeDeclar = figure.FullName.Split('.'); NamespacesNames.Add(typeDeclar[0]); TypesNames.Add(typeDeclar[1]); return(true); } catch (Exception) { return(false); } }