Exemple #1
0
        private NetPropertyInfo GetProperty(string propertyName)
        {
            for (var x = 0; x < _typeInfo.PropertyCount; x++)
            {
                var prop = _typeInfo.GetProperty(x);
                if (prop.Name == propertyName)
                {
                    return(prop);
                }

                prop.Dispose();
            }

            throw new Exception($"No prop {propertyName} found.");
        }
        public void OnNetTypeInfoCreated(NetTypeInfo netTypeInfo, Type forType)
        {
            if (!IsApplicableFor(forType))
            {
                return;
            }
            var mvvmTypeInfo = new MvvmTypeInfo();

            TypeInfos.Add(forType, mvvmTypeInfo);
            for (var i = 0; i < netTypeInfo.PropertyCount; i++)
            {
                int?existingSignalIndex = null;

                var property = netTypeInfo.GetProperty(i);
                if (property.NotifySignal != null)
                {
                    // In this case some other behavior or the user has already set up a notify signal for this property.
                    // We don't want to destroy that.
                    mvvmTypeInfo.AddPropertyInfo(property.Name, property.NotifySignal.Name);
                    continue;
                }
                var signalName = CalculateSignalNameFromPropertyName(property.Name);
                mvvmTypeInfo.AddPropertyInfo(property.Name, signalName);

                // Check if this signal already has been registered.
                for (var signalIndex = 0; signalIndex < netTypeInfo.SignalCount; signalIndex++)
                {
                    var signal = netTypeInfo.GetSignal(signalIndex);
                    if (string.Equals(signalName, signal.Name))
                    {
                        existingSignalIndex = signalIndex;
                        break;
                    }
                }
                if (existingSignalIndex.HasValue)
                {
                    // Signal for this property is already existent but not registered (we check that above).
                    property.NotifySignal = netTypeInfo.GetSignal(existingSignalIndex.Value);
                    continue;
                }

                // Create a new signal and link it to the property.
                var notifySignalInfo = new NetSignalInfo(netTypeInfo, signalName);
                netTypeInfo.AddSignal(notifySignalInfo);
                property.NotifySignal = notifySignalInfo;
            }
        }