Golem.Core.RecipeCataloger.GetRecipeAttributeOrNull C# (CSharp) Method

GetRecipeAttributeOrNull() public method

public GetRecipeAttributeOrNull ( Type type ) : RecipeAttribute
type System.Type
return RecipeAttribute
        public RecipeAttribute GetRecipeAttributeOrNull(Type type)
        {
            //get recipe attributes for type
            var atts = type.GetCustomAttributes(typeof(RecipeAttribute), true);

            //should only be one per type
            if (atts.Length > 1)
                throw new Exception("Expected only 1 recipe attribute, but got more");

            //return if none, we'll skip this class
            if (atts.Length == 0)
                return null;

            var recipeAtt = atts[0] as RecipeAttribute;

            //throw if bad case. Should cast fine (if not, then might indicate 2 of the same assembly is loaded)
            if (recipeAtt == null)
                throw new Exception("Casting error for RecipeAttribute. Same assembly loaded more than once?");

            return recipeAtt;
        }