public Variable GetVariable(Compiler.Scope scope) { if (Initializers.TryGetValue(Type, out var compiler)) { return(compiler.Invoke(Access.Private, Usage.Default, Name, scope, scope.DeclaringMethod.ScriptTrace)); } else { throw new Compiler.SyntaxException($"Unknown type '{Type}'.", Compiler.CurrentScriptTrace); } }
public RosSerializableDefinition() { try { RosType = typeof(IMessage).IsAssignableFrom(typeof(T)) ? BuiltIns.GetMessageType(typeof(T)) : ""; } catch (RosInvalidMessageException) { throw new RosIncompleteWrapperException( $"Type '{typeof(T).Name}' must have a string constant named RosMessageType. " + "It should also be tagged with the attribute [MessageName]."); } var bi = new BuilderInfo(); foreach (var field in typeof(T).GetFields()) { if (field.IsStatic && field.IsLiteral && !field.IsInitOnly && RosWrapperBase.BuiltInNames.TryGetValue(field.FieldType, out string?fieldType) && field.GetCustomAttribute <MessageNameAttribute>() == null) { InitializeConstant(bi, field, fieldType); } } foreach (var property in typeof(T).GetProperties()) { if (property.GetSetMethod() == null && !(property.GetType().IsGenericType&& property.GetType().GetGenericTypeDefinition() != typeof(List <>))) { continue; } if (property.GetGetMethod() == null || property.GetCustomAttribute <IgnoreDataMemberAttribute>() != null) { continue; } Type propertyType = property.PropertyType; if (Initializers.TryGetValue(propertyType, out var initializer)) { initializer(property, bi); } else if (propertyType.IsArray) { var elementType = propertyType.GetElementType() !; if (elementType.IsEnum) { InitializeEnumArrayProperty(property, bi); } else if (typeof(IMessage).IsAssignableFrom(elementType)) { InitializeMessageArrayProperty(property, bi); } } else if (propertyType.IsEnum) { InitializeEnumProperty(property, bi); } else if (typeof(IMessage).IsAssignableFrom(propertyType)) { InitializeMessageProperty(property, bi); } } RosDefinition = bi.RosDefinition.ToString(); messageFields = bi.Fields.ToArray(); (RosInputForMd5, RosMessageMd5) = CreateMd5(bi); RosDependencies = CreateDependencies(RosDefinition); }