Пример #1
0
        public DeputyBase GetOrCreateNativeReference(ByRefValue byRefValue)
        {
            if (!_references.ContainsKey(byRefValue.Value))
            {
                ConstructorInfo constructorInfo = GetByRefConstructor();
                _references[byRefValue.Value] = (DeputyBase)constructorInfo.Invoke(new object[] { byRefValue });
            }

            return(_references[byRefValue.Value]);

            ConstructorInfo GetByRefConstructor()
            {
                Type type = _types.GetClassType(byRefValue.FullyQualifiedName);

                if (type == null)
                {
                    type = _types.GetInterfaceProxyType(byRefValue.FullyQualifiedName);
                }
                if (type == null)
                {
                    throw new ArgumentException(
                              $"Could not find type with fully qualified name '{byRefValue.FullyQualifiedName}'",
                              nameof(byRefValue)
                              );
                }

                BindingFlags constructorFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

                return(type.GetConstructor(constructorFlags, null, new[] { typeof(ByRefValue) }, null));
            }
        }
Пример #2
0
        bool TryConvertCustomType(IReferenceMap referenceMap, object value, bool isOptional, string fullyQualifiedName, out object result)
        {
            if (IsReferenceType())
            {
                return(TryConvertClass(referenceMap, value, out result));
            }

            if (_types.GetEnumType(fullyQualifiedName) != null)
            {
                return(TryConvertEnum(value, isOptional, fullyQualifiedName, out result));
            }

            result = null;
            return(false);

            bool IsReferenceType()
            {
                return
                    (_types.GetClassType(fullyQualifiedName) != null ||
                     _types.GetInterfaceType(fullyQualifiedName) != null ||
                     _types.GetInterfaceProxyType(fullyQualifiedName) != null);
            }
        }