示例#1
0
        internal CompilerClass(TsonStringNode assemblyNode, Assembly assembly, Type type, Type interfaceType)
        {
            this.Assembly  = assembly;
            this.Type      = type;
            this.Interface = interfaceType;
            this.Instance  = Activator.CreateInstance(this.Type);

            compilerParameters = new Dictionary <string, AttributedProperty>();
            targetParameters   = new Dictionary <string, AttributedProperty>();

            foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (propertyInfo.Name == "Target")
                {
                    this.TargetProperty = propertyInfo;
                }
                else if (propertyInfo.Name == "Context")
                {
                    this.ContextProperty = propertyInfo;
                }
                else if (propertyInfo.Name == "Extensions")
                {
                    this.ExtensionsProperty = propertyInfo;
                }
                else
                {
                    object[] attributes = propertyInfo.GetCustomAttributes(typeof(ContentCompilerParameterAttribute), true);
                    ContentCompilerParameterAttribute attribute;

                    if (attributes.Length == 1)
                    {
                        attribute = (ContentCompilerParameterAttribute)attributes[0];
                    }
                    else
                    {
                        continue;
                    }

                    if (!(propertyInfo.CanRead && propertyInfo.CanWrite))
                    {
                        throw new ContentFileException(
                                  assemblyNode, "Settings property '{0}' on '{1}' compiler must be read/write".CultureFormat(propertyInfo.Name, this.Name));
                    }

                    var property = new AttributedProperty(attribute, propertyInfo);

                    if (attribute.ForCompiler)
                    {
                        compilerParameters.Add(propertyInfo.Name, property);
                    }
                    else
                    {
                        targetParameters.Add(propertyInfo.Name, property);
                    }
                }
            }
        }
示例#2
0
        internal CompilerClass(TsonStringNode assemblyNode, Assembly assembly, Type type, Type interfaceType)
        {
            this.Assembly = assembly;
            this.Type = type;
            this.Interface = interfaceType;
            this.Instance = Activator.CreateInstance(this.Type);

            compilerParameters = new Dictionary<string, AttributedProperty>();
            targetParameters = new Dictionary<string, AttributedProperty>();

            foreach (PropertyInfo propertyInfo in type.GetProperties(BindingFlags.Instance | BindingFlags.Public))
            {
                if (propertyInfo.Name == "Target")
                {
                    this.TargetProperty = propertyInfo;
                }
                else if (propertyInfo.Name == "Context")
                {
                    this.ContextProperty = propertyInfo;
                }
                else if (propertyInfo.Name == "Extensions")
                {
                    this.ExtensionsProperty = propertyInfo;
                }
                else
                {
                    object[] attributes = propertyInfo.GetCustomAttributes(typeof(ContentCompilerParameterAttribute), true);
                    ContentCompilerParameterAttribute attribute;

                    if (attributes.Length == 1)
                        attribute = (ContentCompilerParameterAttribute)attributes[0];
                    else
                        continue;

                    if (!(propertyInfo.CanRead && propertyInfo.CanWrite))
                        throw new ContentFileException(
                            assemblyNode, "Settings property '{0}' on '{1}' compiler must be read/write".CultureFormat(propertyInfo.Name, this.Name));

                    var property = new AttributedProperty(attribute, propertyInfo);

                    if (attribute.ForCompiler)
                        compilerParameters.Add(propertyInfo.Name, property);
                    else
                        targetParameters.Add(propertyInfo.Name, property);
                }
            }
        }