Amazon.DynamoDBv2.DataModel.Utils.CanInstantiate C# (CSharp) Method

CanInstantiate() public static method

public static CanInstantiate ( Type objectType ) : bool
objectType System.Type
return bool
        public static bool CanInstantiate(Type objectType)
        {
            var objectTypeWrapper = TypeFactory.GetTypeInfo(objectType);
            return
                //objectType.IsPublic &&
                objectTypeWrapper.IsClass &&
                !objectTypeWrapper.IsInterface &&
                !objectTypeWrapper.IsAbstract &&
                !objectTypeWrapper.IsGenericTypeDefinition &&
                !objectTypeWrapper.ContainsGenericParameters &&
                objectTypeWrapper.GetConstructor(TypeFactory.EmptyTypes) != null; // parameterless constructor present?
        }
        public static Type GetType(MemberInfo member)

Usage Example

Example #1
0
        private bool TryFromMap(Type targetType, Document map, DynamoDBFlatConfig flatConfig, out object output)
        {
            output = null;

            if (!Utils.CanInstantiate(targetType))
            {
                return(false);
            }

            Type valueType;

            if (!IsSupportedDictionaryType(targetType, out valueType))
            {
                return(false);
            }

            var dictionary      = Utils.Instantiate(targetType);
            var idictionary     = dictionary as IDictionary;
            var propertyStorage = new SimplePropertyStorage(valueType);

            foreach (var kvp in map)
            {
                var key   = kvp.Key;
                var entry = kvp.Value;

                var item = FromDynamoDBEntry(propertyStorage, entry, flatConfig);
                idictionary.Add(key, item);
            }

            output = dictionary;
            return(true);
        }
All Usage Examples Of Amazon.DynamoDBv2.DataModel.Utils::CanInstantiate