private void Save_Click(object sender, RoutedEventArgs e) { if (Check(name) == false && Check(mark) == false && Check(Name_tf.Text) == false && Check(Mark_tf.Text) == false) { if (Mark_tf.IsEnabled) { icon.Source = Insects_png.Source; TypeClass type = new TypeClass(name, mark, description, icon, icon.Source.ToString()); Check check = new Check(type); if (!check.exists) { this.Close(); } } else { Update(); this.Close(); } } else { string message = "Type "; if (Check(name) || Check(Name_tf.Text)) { message += "name, "; } if (Check(mark) || Check(Mark_tf.Text)) { message += "mark"; } MessageBox.Show(message + " is empty or invalid!!!"); } }
/// <summary> /// Checks if the variable already exists. This does not allow for shadowing of variables, maybe as an /// enhancement, cause it wouldn't be that hard. /// /// Cflat also allows for declarations and assignments on the same line, so this will process the InitialValue sub tree /// as well. /// </summary> /// <param name="n"></param> public override void VisitDeclLocal(ASTDeclarationLocal n) { if (!_scopeMgr.HasSymbol(n.ID)) { CFlatType lhs = CheckSubTree(n.Type); //Check if the code is also assigning a value on the same line bool valid = true; if (n.InitialValue != null) { CFlatType rhs = CheckSubTree(n.InitialValue); if (rhs is TypeFunction && ((TypeFunction)rhs).IsConstructor) { rhs = new TypeClass(((TypeFunction)rhs).Name); } if (!IsValidAssignment(lhs, rhs)) { valid = false; ReportError(n.Location, "Invalid assignment, type mismatch. Expected: {0} Got: {1}", TypeToFriendlyName(lhs), TypeToFriendlyName(rhs)); } } if (valid) { _scopeMgr.AddLocal(n.ID, lhs, _currentMethod); } } else { ReportError(n.Location, "The identifier '{0}' already exists", n.ID); } }
public void TestPropertyComponentModelAttributes() { // check that ComponentModel attributes map to ParamSpec using (var baseObj = new TestObjectPropertiesBase()) using (var baseObjClass = (ObjectClass)TypeClass.Get(baseObj.GetGType())) using (var basePspec = baseObjClass.FindProperty("bool-value")) { Assert.That(basePspec.Name, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyName)); Assert.That(basePspec.Nick, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyNick)); Assert.That(basePspec.Blurb, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyBlurb)); Assert.That(basePspec.DefaultValue.Get(), Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyDefaultValue)); } // The subclass will inherit the values of the parent class. // If the subclass tries to declare an attribute again, it will // be ignored as is the case with DefaultValueAttribute here. using (var subObj = new TestObjectPropertiesSubclass()) using (var subObjClass = (ObjectClass)TypeClass.Get(subObj.GetGType())) using (var subPspec = subObjClass.FindProperty("bool-value")) { Assert.That(subPspec.Name, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyName)); Assert.That(subPspec.Nick, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyNick)); Assert.That(subPspec.Blurb, Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyBlurb)); Assert.That(subPspec.DefaultValue.Get(), Is.EqualTo(TestObjectPropertiesBase.BoolValuePropertyDefaultValue)); } Utility.AssertNoGLibLog(); }
public override void VisitSubClassDefinition(ASTSubClassDefinition n) { var parent = (ClassDescriptor)_scopeMgr.Find(n.Parent, p => p is ClassDescriptor); //need to restore the parent class's scope so that inheritance can pass semantic analysis _scopeMgr.RestoreScope(parent.Scope); _currentClass = new TypeClass(n.Name, parent); var classScope = _scopeMgr.PushScope(string.Format("subclass {0}", _currentClass.ClassName)); _currentClass.Descriptor = (ClassDescriptor)_scopeMgr.Find(n.Name, p => p is ClassDescriptor); var declarationType = CheckSubTree(n.Declarations); n.Type = _currentClass; CheckNecessaryFunctions(n); _currentClass.Descriptor.Scope = _currentClass.Scope = classScope; AddCtorIfNone(classScope, n.Name); //pop the sub class scope and the parent class _scopeMgr.PopScope(); _scopeMgr.PopScope(); }
public void TestRegister4() { // this should register successfully var testEnum4GType = typeof(TestEnum4).GetGType(); Assert.That(testEnum4GType, Is.Not.EqualTo(GType.Invalid), "Failed to register an enum"); // make sure the type is not re-registed. Assert.That(testEnum4GType, Is.EqualTo(typeof(TestEnum4).GetGType())); // a couple more GType checks Assert.That((Type)testEnum4GType, Is.EqualTo(typeof(TestEnum4))); Assert.That(testEnum4GType.IsA(GType.Enum), Is.True); // make sure that we set the typename, value name and value nick Assert.That(testEnum4GType.Name, Is.EqualTo("GISharp-Core-Test-GObject-EnumTests+TestEnum4")); using (var enum4TypeClass = (EnumClass)TypeClass.Get(testEnum4GType)) { var value = GISharp.GObject.Enum.GetValue(enum4TypeClass, 1); Assert.That(value.Value, Is.EqualTo((int)TestEnum4.One)); var valueName = GMarshal.Utf8PtrToString(value.ValueName); Assert.That(valueName, Is.EqualTo("One")); var valueNick = GMarshal.Utf8PtrToString(value.ValueNick); Assert.That(valueNick, Is.EqualTo("One")); } Utility.AssertNoGLibLog(); }
public static bool IsPublic(this TypeClass typeClass) { switch (typeClass) { case TypeClass.STREAM: return(true); case TypeClass.REVISION: return(true); case TypeClass.VARIANT: return(true); case TypeClass.APPLICATION: return(true); case TypeClass.NAMED_WINDOW: return(true); case TypeClass.ANONYMOUS: return(false); case TypeClass.TABLE: return(false); } throw new ArgumentException(); }
protected void saveButton_Click(object sender, EventArgs e) { TypeSetupManager aTypeManger = new TypeSetupManager(); TypeClass aTypeClass = new TypeClass(); aTypeClass.Name = typeNameTextBox.Text; if (typeNameTextBox.Text == string.Empty) { messageLabel.Text = "Insert Type Name !"; } else { if (aTypeManger.IsTypeNameExist(aTypeClass.Name) == true) { messageLabel.Text = "Type Name Already Exist !"; } else { if (aTypeManger.SaveTypeName(aTypeClass) > 0) { messageLabel.Text = "Type Name Inserted Successfully"; typeNameTextBox.Text = string.Empty; } else { messageLabel.Text = "Insert Failed !"; } List <TypeClass> aList = aTypeManger.GetAllTypeName(); showGridView.DataSource = aList; showGridView.DataBind(); } } }
public override void EnterTypeName(GoParser.TypeNameContext context) { string type = context.GetText(); string typeName = ConvertToCSTypeName(type); TypeClass typeClass = TypeClass.Simple; if (typeName.Equals("error") || (Metadata?.Interfaces.TryGetValue(typeName, out _) ?? false)) { typeClass = TypeClass.Interface; } else if (Metadata?.Structs.TryGetValue(typeName, out _) ?? false) { typeClass = TypeClass.Struct; } else if (Metadata?.Functions.TryGetValue($"{typeName}()", out _) ?? false) { typeClass = TypeClass.Function; } Types[context.Parent] = new TypeInfo { Name = type, TypeName = ConvertToCSTypeName(type), FullTypeName = typeName, TypeClass = typeClass }; }
public void Read(Stream data) { if (data == null) { throw new ArgumentNullException(nameof(data)); } var reader = new UnityReader(data); Header = new DatabaseHeader(reader); byte[] buffer = reader.ReadBytes(Header.CompressedSize); byte[] uncompressed = LZ4Codec.Decode(buffer, 0, buffer.Length, Header.UncompressedSize); using (var ms = new MemoryStream(uncompressed)) { UnityReader lz4Reader = new UnityReader(ms); int classCount = lz4Reader.ReadInt32(); Classes = new TypeClass[classCount]; for (int i = 0; i < classCount; i++) { Classes[i] = new TypeClass(lz4Reader, this); } lz4Reader.Position = Header.StringTablePosition; _stringTable = lz4Reader.ReadStringFixed(Header.StringTableLength, Encoding.ASCII); } }
/// <summary> /// Factory for a bean type. /// </summary> /// <param name="name">type name</param> /// <param name="clazz">java class</param> /// <param name="isConfigured">whether the class was made known or is discovered</param> /// <param name="typeClass">type of type</param> /// <param name="isPreConfigured">preconfigured</param> /// <param name="isPreConfiguredStatic">preconfigured via static config</param> /// <returns>instance</returns> public static EventTypeMetadata CreateBeanType( string name, Type clazz, bool isPreConfiguredStatic, bool isPreConfigured, bool isConfigured, TypeClass typeClass) { ISet<string> secondaryNames = null; if (name == null) { name = clazz.Name; } else { if (!name.Equals(clazz.Name)) { secondaryNames = new LinkedHashSet<string>(); secondaryNames.Add(clazz.Name); } } return new EventTypeMetadata( name, secondaryNames, typeClass, isPreConfiguredStatic, isPreConfigured, isConfigured, ApplicationType.CLASS, false); }
static void Main(string[] args) { int [] intArray = TypeClass.CreateArray <int>(5); string [] stringArray = TypeClass.CreateArray <string>(5); Point [] pointArray = TypeClass.CreateArray <Point>(5); MyCustomClass [] myCustomClassArray = TypeClass.CreateArray <MyCustomClass>(5); }
public override void VisitDeclarationClass(DeclarationClass n) { var cls = new TypeClass(n.Name); _currentClass = cls; n.Descriptor = _scopeMgr.AddClass(cls.ClassName, cls); n.Type = cls; }
public InputParameter(ParameterInfo info) { if (info == null) throw new ArgumentNullException("info"); this.info = info; paramClass = TypeHelper.GetTypeClass(info.ParameterType); }
/// <summary> /// Factory for a value-add type. /// </summary> /// <param name="name">type name</param> /// <param name="typeClass">type of type</param> /// <returns>instance</returns> public static EventTypeMetadata CreateValueAdd(string name, TypeClass typeClass) { if ((typeClass != TypeClass.VARIANT) && (typeClass != TypeClass.REVISION)) { throw new ArgumentException("Type class " + typeClass + " invalid"); } return new EventTypeMetadata(name, null, typeClass, true, true, true, null, false); }
/// <summary> /// Performs a comparison on the object with the field value <paramref name="Value"/>. /// </summary> /// <param name="Value">Field value for comparison.</param> /// <returns>Result of comparison.</returns> public override bool Compare(object Value) { Type T1 = Value.GetType(); Type T2 = this.value.GetType(); TypeCode Code1 = Convert.GetTypeCode(Value); TypeClass Class1 = GetTypeClass(Code1); if (T1 != T2 || Class1 == TypeClass.Numeric || Class1 == TypeClass.String) { TypeCode Code2 = Convert.GetTypeCode(this.value); TypeClass Class2 = GetTypeClass(Code2); if (Class1 != Class2) { return(false); } switch (Class1) { case TypeClass.Boolean: // Cannot be different types case TypeClass.DateTime: // Cannot be different types case TypeClass.Unknown: // Unknown type default: return(false); case TypeClass.Numeric: if (!(Value is double d1)) { d1 = Convert.ToDouble(Value); } if (!(this.value is double d2)) { d2 = Convert.ToDouble(this.value); } return(this.Compare(d1, d2)); case TypeClass.String: if (!(Value is string s1)) { s1 = Value.ToString(); } if (!(this.value is string s2)) { s2 = this.value.ToString(); } return(this.Compare(s1, s2)); } } else { return(this.Compare(Value, this.value)); } }
public IList <TypeClass> GetFullTreeFor(IDictionary <int, int> records = null) { IList <TypeClass> classificationList = new List <TypeClass>(); IList <Tree> types = DataSet.Where(m => m.taxonomy_id == 1 && m.BT_ID == null).ToList(); foreach (var item in types) { TypeClass tc = new TypeClass { TypeClassId = item.PN_ID, Classes = new List <ClassModel>(), TypeClassName = item.Name, TypeClassCount = (records != null && records.ContainsKey(item.PN_ID) ? records[item.PN_ID] : 0) }; IList <Tree> classes = DataSet.Where(n => n.BT_ID == item.PN_ID).ToList(); foreach (var itemC in classes) { ClassModel cm = new ClassModel { ClassModelId = itemC.PN_ID, Subclasses = new List <SubclassModel>(), ClassModelName = itemC.Name, ClassCount = (records != null && records.ContainsKey(itemC.PN_ID) ? records[itemC.PN_ID] : 0) }; IList <Tree> subclasses = DataSet.Where(m => m.BT_ID == itemC.PN_ID).ToList(); foreach (var itemS in subclasses) { SubclassModel sm = new SubclassModel { SubclassModelId = itemS.PN_ID, Groups = new List <GroupModel>(), SubclassName = itemS.Name, SubclassCount = (records != null && records.ContainsKey(itemS.PN_ID) ? records[itemS.PN_ID] : 0) }; IList <Tree> groups = DataSet.Where(l => l.BT_ID == itemS.PN_ID).ToList(); foreach (var itemG in groups) { sm.Groups.Add(new GroupModel { GroupModelId = itemG.PN_ID, GroupModelName = itemG.Name, GroupCount = (records != null && records.ContainsKey(itemG.PN_ID) ? records[itemG.PN_ID] : 0) }); } cm.Subclasses.Add(sm); } tc.Classes.Add(cm); } classificationList.Add(tc); } return(classificationList); }
/// <summary> /// Restore the scope of the class we're visiting, and then visit all of the child nodes. /// Pop the class scope when we're done. /// /// Both VisitClassDefinition and VisitSubClassDefinition do the same thing, so moved the code out into 1 method. /// </summary> private void VisitClassBody(TypeClass currentClass, ASTDeclarationList declarations) { _currentClass = currentClass; _scopeMgr.RestoreScope(currentClass.Scope); CheckSubTree(declarations); _scopeMgr.PopScope(); }
/// <summary> /// Visit a class node and add the descriptor to the current scope /// </summary> /// <param name="n"></param> public override void VisitClassDefinition(ASTClassDefinition n) { CheckForGlobalScope(n.Name, n.Location); TypeClass cls = new TypeClass(n.Name); _currentClass = cls; n.Descriptor = _scopeMgr.AddClass(cls.ClassName, cls, null); n.Type = cls; }
public InputParameter(ParameterInfo info) { if (info == null) { throw new ArgumentNullException("info"); } this.info = info; paramClass = TypeHelper.GetTypeClass(info.ParameterType); }
private void getTypes() { TypeClass typeClass = new TypeClass(); List <TypeClass> listType = typeClass.GetTypes(); foreach (var item in listType) { SpBtType.Items.Add(item.type_name); } }
public Method[] FindOverloads(ParameterData[] parameters) { lock (syncRoot) { // First get valid overloads List <Method> valid = new List <Method>(); foreach (Method method in overloads) { if (method.MinParameterCount <= parameters.Length && method.MaxParameterCount >= parameters.Length) { bool invalid = false; TypeClass paramClass = TypeClass.Object; for (int i = 0; i < parameters.Length; i++) { if (i < method.Parameters.Length) { if (method.Parameters[i].IsParamArray) { Debug.Assert(i == method.Parameters.Length - 1); paramClass = TypeHelper.GetTypeClass(method.Parameters[i].Type.GetElementType()); } else { paramClass = method.Parameters[i].Class; } } if (paramClass < parameters[i].Class) { invalid = true; break; } } if (!invalid) { valid.Add(method); } } } valid.Sort(new Comparison <Method>(MethodComparer)); if (valid.Count > 0) { return(valid.ToArray()); } else { throw new RuntimeException("No suitable method overload found."); } } }
public ParameterData(object value) { source = value; dataClass = TypeClass.Object; if (value != null) { valueString = value.ToString(); dataClass = TypeHelper.GetValueClass(value, out number); } }
public void TestRegister1() { // invalid because TestEnum1 does not have [GType] attribute so it // gets registered as a boxed type instead of as an enum type. var testEnum1GType = typeof(TestEnum1).GetGType(); Assert.That(() => (EnumClass)TypeClass.Get(testEnum1GType), Throws.ArgumentException); Utility.AssertNoGLibLog(); }
public UserTypeConfig() { if (TypeClass != UserTypeEnum.Customer) { Id = TypeClass.GetCustomAttr <FieldAttribute>().GuidId.ToGuid(); } else { Id = Guid.NewGuid(); } }
/// <summary> /// Initializes a new instance of the <see cref="TestData" /> class. /// </summary> protected TestData( ) { SourceApp = new AppClass( ); TargetApp = new AppClass( ); Map = new MapClass( ); Relationship = new RelationshipClass( ); TypeA = new TypeClass( ); TypeB = new TypeClass( ); TypeAInstance = new TypeClass( ); TypeBInstance = new TypeClass( ); }
private readonly bool _isPropertyAgnostic; // Type accepts any property name (i.e. no-schema XML type) /// <summary> /// Ctor. /// </summary> /// <param name="primaryName">the primary name by which the type became known.</param> /// <param name="secondaryNames">a list of additional names for the type, such as fully-qualified class name</param> /// <param name="typeClass">type of the type</param> /// <param name="isApplicationPreConfiguredStatic">if set to <c>true</c> [is application pre configured static].</param> /// <param name="applicationPreConfigured">if set to <c>true</c> [application pre configured].</param> /// <param name="applicationConfigured">true if configured by the application</param> /// <param name="applicationType">type of application class or null if not an application type</param> /// <param name="isPropertyAgnostic">true for types that accept any property name as a valid property (unchecked type)</param> protected EventTypeMetadata(String primaryName, ICollection <String> secondaryNames, TypeClass typeClass, bool isApplicationPreConfiguredStatic, bool applicationPreConfigured, bool applicationConfigured, ApplicationType?applicationType, bool isPropertyAgnostic) { _publicName = primaryName; _primaryName = primaryName; _optionalSecondaryNames = secondaryNames; _typeClass = typeClass; _isApplicationConfigured = applicationConfigured; _isApplicationPreConfigured = applicationPreConfigured; _isApplicationPreConfiguredStatic = isApplicationPreConfiguredStatic; _optionalApplicationType = applicationType; _isPropertyAgnostic = isPropertyAgnostic; }
public MemberDescriptor AddMember(string name, CFlatType type, TypeClass containingClass, List <string> modifiers = null) { var descriptor = new MemberDescriptor(type, name, containingClass.Descriptor); if (modifiers != null) { descriptor.Modifiers.AddRange(modifiers); } CurrentScope.Descriptors.Add(name, descriptor); containingClass.Descriptor.Fields.Add(descriptor); return(descriptor); }
public int SaveTypeName(TypeClass aTypeClass) { SqlConnection connection = new SqlConnection(connectionString); string query = "INSERT INTO t_Types (Name) VALUES ('" + aTypeClass.Name + "')"; SqlCommand command = new SqlCommand(query, connection); connection.Open(); int rowsAffected = command.ExecuteNonQuery(); connection.Close(); return(rowsAffected); }
public Player(int numb, string name, string desc, int lvl, int hp, int atk, int def, int spd, TypeClass clas) { this.PlayerNumber = numb; this.PlayerName = name; this.PlayerDescription = desc; this.Level = lvl; this.Health = hp; this.Attack = atk; this.Defence = def; this.Speed = spd; this.classType = clas; }
private void Choose_Click(object sender, RoutedEventArgs e) { if (dgrMain.SelectedItem != null) { selected_type = (TypeClass)dgrMain.SelectedItem; } else { selected_type = null; } this.Close(); }
private void Delete_Type(object sender, RoutedEventArgs e) { selected = (TypeClass)dgrMain.SelectedItem; Lists.Type_list.Remove(selected); if (selected != null) { MessageBox.Show("Type successfully deleted!"); } else { MessageBox.Show("First you have to choose type!"); } }
public object ConvertTo(Type targetType, TypeClass targetClass) { try { // Check null value if (this.IsNull) { if (!targetType.IsValueType) return null; else throw new ParameterException("Cannot convert null to ValueType."); } // Check if it isn't already in appropriate type if (targetType == this.Source.GetType()) { return this.Source; } // If string is requested return already known value if (targetType == typeof(String)) { return this.String; } // Convert numbers if (targetClass == TypeClass.Number) { if (this.String.Length > 0) { // Try to resolve alias ParameterData aliasData = null; if (targetType == typeof(uint) || targetType == typeof(int) || targetType == typeof(Serial)) { if (Aliases.ObjectExists(this.String)) { aliasData = new ParameterData(Aliases.GetObject(this.String)); } } if (aliasData != null) { return aliasData.ConvertTo(targetType, targetClass); } } // If requested type is one of built-in use implemented converter if (targetType.IsPrimitive) { return Convert.ChangeType(this.Number, targetType); } else if (targetType == typeof(Serial)) { return (Serial)(uint)this.Number; } else if (targetType == typeof(Graphic)) { return (Graphic)(ushort)this.Number; } else if (targetType == typeof(UOColor)) { return (UOColor)(ushort)this.Number; } else { throw new InternalErrorException("Unknown numeric type requested."); } } // Unimplemented type if (targetClass == TypeClass.Object) { // Try enum if (targetType.IsEnum) { try { return Enum.Parse(targetType, this.String, true); } catch { } } // Try IConvertible if (this.Source is IConvertible) { try { return ((IConvertible)this.Source).ToType(targetType, null); } catch { } } // Try to find operators List<MethodInfo> methods = new List<MethodInfo>(); methods.AddRange(targetType.GetMethods(BindingFlags.Public | BindingFlags.Static)); methods.AddRange(this.Source.GetType().GetMethods(BindingFlags.Public | BindingFlags.Static)); for (int i = 0; i < methods.Count; i++) { try { if (methods[i].Name == "op_Implicit" || methods[i].Name == "op_Explicit") { if (methods[i].ReturnType == targetType) { ParameterInfo[] parameters = methods[i].GetParameters(); if (parameters.Length == 1 && parameters[0].ParameterType == this.Source.GetType()) { return methods[i].Invoke(null, new object[] { this.Source }); } } } } catch { } } // Try to find Parse function MethodInfo parseMethod = targetType.GetMethod("Parse", new Type[] { typeof(String) }); if (parseMethod != null) { try { return parseMethod.Invoke(null, new object[] { this.String }); } catch { } } throw new ParameterException("No suitable convert method found."); } else { throw new InternalErrorException("Invalid targetClass specified."); } } catch (Exception e) { string valueString = this.Source != null ? this.String : "null"; if (valueString.Contains(" ")) valueString = "\"" + valueString + "\""; throw new ParameterException("Unable to convert " + valueString + " to " + targetType.ToString(), e); } }
/// <summary> /// Creates a new validator for the given column. /// </summary> /// <param name="column">Database column.</param> public FieldValidator(IDbColumn column) { this.type = column.DataType; this.minValue = column.MinValue; this.maxValue = column.MaxValue; this.allowNull = column.IsNullable || column.IsAutoGenerated; this.autoIncrement = column.AutoIncrement; this.typeClass = GetTypeClass(this.type); }