コード例 #1
0
ファイル: Encoder.cs プロジェクト: jlucas9/WVU-Lunabotics
        /// <summary>
        /// Encodes a field and accompanying value into a short (16-bit) value
        /// </summary>
        /// <remarks>
        /// Bits 12-15 represent the field. Bits 0-11 represent the value (range between -2048 to 2047)
        /// </remarks>
        /// <param name="field"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        public static short Encode(CommandFields field, short value)
        {
            if (value < -2048 || value > 2047)
                throw new ArgumentException("Value is outside allowable range (-2048:2047)");

            if (value < 0) //sign bit is one (0x0800)
            {
                return (short)((short)field | 0x0800 | (0x07FF & value));
            }
            else //sign bit (bit 11) is zero
            {
                //should be able to simply OR together
                return (short)((short)field | value);
            }
        }
コード例 #2
0
            /// <summary>
            /// Called for every syntax node in the compilation, we can inspect the nodes and save any information useful for generation
            /// </summary>
            public void OnVisitSyntaxNode(GeneratorSyntaxContext context)
            {
                if (context.Node is ClassDeclarationSyntax classDeclaration)
                {
                    INamedTypeSymbol classTypeSymbol = context.SemanticModel.GetDeclaredSymbol(classDeclaration) as INamedTypeSymbol;

                    if (classTypeSymbol.GetAttributes().Any(ad => ad.AttributeClass.ToDisplayString() == "System.Mvvm.MVVMViewModelAttribute"))
                    {
                        ClassTypeSymbol = classTypeSymbol;

                        var props = classDeclaration.Members.OfType <PropertyDeclarationSyntax>();

                        ImmutableArray <ISymbol> members = ClassTypeSymbol.GetMembers();

                        foreach (ISymbol member in members)
                        {
                            if (member is IFieldSymbol fieldSymbol)
                            {
                                if (fieldSymbol.Type.ToDisplayString() == "System.Mvvm.DelegateCommand")
                                {
                                    CommandFields.Add(fieldSymbol);
                                }
                            }
                        }



                        //check to see if any properties are exposed
                        if (props.Any())
                        {
                            var commandFieldnames = new List <string>();

                            var fieldsToRemove = new List <IFieldSymbol>();

                            //work through each property
                            foreach (PropertyDeclarationSyntax propertySyntax in props)
                            {
                                IPropertySymbol propertySymbol = context.SemanticModel.GetDeclaredSymbol(propertySyntax);

                                if (propertySymbol.Type.ToDisplayString() == "System.Windows.Input.ICommand" || (propertySymbol.Type.ToDisplayString() == "System.Mvvm.DelegateCommand"))
                                {
                                    var propCode = propertySyntax.ToString();

                                    if (CommandFields.Any())
                                    {
                                        foreach (var command in CommandFields)
                                        {
                                            if (propCode.Contains(command.Name))
                                            {
                                                //don't notify the field as its cheaper to call the OnPropertyChanged notification
                                                fieldsToRemove.Add(command);
                                            }
                                        }
                                    }

                                    Properties.Add(propertySymbol);
                                }
                            }


                            //remove removed fields :-)
                            foreach (var field in fieldsToRemove)
                            {
                                CommandFields.Remove(field);
                            }
                        }
                    }
                }
            }
コード例 #3
0
ファイル: Encoder.cs プロジェクト: jlucas9/WVU-Lunabotics
 public FieldValuePair(CommandFields f, short val)
 {
     if (val < -2048 || val > 2047)
         throw new ArgumentException("Value is out of allowable range (-2048:2047)");
     this._field = f;
     this._value = val;
 }
コード例 #4
0
 public void SetUp()
 {
     DatabaseContext = SetupInMemoryDatabase();
     DatabaseContext.Database.EnsureCreated();
     _commands = new CommandFields(DatabaseContext, Mapper);
 }