Alexandria.Engines.Unreal.TypeProcessorAttribute.MustGetTypeProcessor C# (CSharp) Метод

MustGetTypeProcessor() публичный статический Метод

Get the DataProcessor for the given System.Type, returning the DataProcessor or throwing a NotSupportedException if there is none registered.
public static MustGetTypeProcessor ( Type type ) : DataProcessor
type System.Type The to search for a custom processor.
Результат DataProcessor
        public static DataProcessor MustGetTypeProcessor(Type type)
        {
            if(type == null) throw new ArgumentNullException("type");
            DataProcessor processor;
            if(!TypeProcessors.TryGetValue(type, out processor))
                throw new NotSupportedException("There is no type processor defined for " + type.FullName);
            return processor;
        }

Usage Example

Пример #1
0
        /// <summary>
        /// Get all the <see cref="PackageProperty"/> attributes that are defined within this <see cref="Type"/> (no inheritance).
        /// </summary>
        /// <param name="type">The <see cref="Type"/> to search for properties within.</param>
        /// <returns>The collection of <see cref="PackageProperty"/> objects.</returns>
        public static PackagePropertyCollection GetLocalNativeProperties(Type type)
        {
            PackagePropertyCollection collection;

            if (LocalNativePropertiesDictionary.TryGetValue(type, out collection))
            {
                return(collection);
            }

            ObservableCollection <PackageProperty> list = new ObservableCollection <PackageProperty>();

            collection = LocalNativePropertiesDictionary[type] = new PackagePropertyCollection(list);

            var properties = type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.DeclaredOnly);

            foreach (var property in properties)
            {
                var attributes = property.GetCustomAttributes(typeof(PackagePropertyAttribute), false);
                if (attributes == null || attributes.Length == 0)
                {
                    continue;
                }
                var attribute = (PackagePropertyAttribute)attributes[0];
                while (list.Count <= attribute.Index)
                {
                    list.Add(null);
                }
                if (list[attribute.Index] != null)
                {
                    throw new Exception(type.Name + " has invalid NativePropertyAttributes - multiple attributes (including " + list[attribute.Index].Property.Name + " and " + property.Name + ") have the same index.");
                }
                var nativeProperty = list[attribute.Index] = new PackageProperty(property, attribute);

                attribute.AttachedProperty = property;
                if (attribute.Processor == null)
                {
                    attribute.Processor = TypeProcessorAttribute.MustGetTypeProcessor(property.PropertyType);
                }
            }

            for (int index = 0; index < list.Count; index++)
            {
                if (list[index] == null)
                {
                    throw new Exception(type.Name + " has invalid NativePropertyAttributes - there is no usage of " + index + ", and maybe others.");
                }
            }

            return(collection);
        }